Skip to content

Commit a8d473d

Browse files
fehmerMiodec
andauthored
refactor: prevent miniSnapshot to be set to db (@fehmer) (#8215)
Co-authored-by: Jack <jack@monkeytype.com>
1 parent 7c2a6a4 commit a8d473d

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

frontend/src/ts/components/pages/account/MyProfile.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { UserProfile as UserProfileType } from "@monkeytype/schemas/users";
21
import { JSXElement, Show } from "solid-js";
32

43
import { getActivePage } from "../../../states/core";
@@ -9,7 +8,7 @@ export function MyProfile(): JSXElement {
98
const profile = () =>
109
getActivePage() === "account" ? getSnapshot() : undefined;
1110
return (
12-
<Show when={profile() as UserProfileType} fallback="no user found">
11+
<Show when={profile()} fallback="no user found">
1312
{(p) => <UserProfile profile={p()} isAccountPage />}
1413
</Show>
1514
);

frontend/src/ts/constants/default-snapshot.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export type Snapshot = Omit<
7171
xp: number;
7272
testActivity?: ModifiableTestActivityCalendar;
7373
testActivityByYear?: { [key: string]: TestActivityCalendar };
74+
isMiniSnapshot?: never;
7475
};
7576

7677
const defaultSnap = {

frontend/src/ts/states/snapshot.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,30 @@ import { Mode } from "@monkeytype/schemas/shared";
55

66
export type MiniSnapshot = Omit<
77
Snapshot,
8-
"results" | "presets" | "filterPresets"
9-
>;
8+
"testActivity" | "testActivityByYear" | "isMiniSnapshot"
9+
> & { isMiniSnapshot: boolean };
1010
const [snapshot, updateSnapshot] = createStore<{
1111
value: MiniSnapshot | undefined;
1212
}>({ value: undefined });
1313

1414
/**
1515
* This does not update the DB.snapshot. Use DB.setSnapshot for now.
1616
*/
17-
export function _setSnapshot(newValue: MiniSnapshot | undefined): void {
17+
export function _setSnapshot(newValue: Snapshot | undefined): void {
1818
if (newValue === undefined) {
1919
updateSnapshot("value", undefined);
2020
} else {
21-
updateSnapshot(
22-
"value",
23-
reconcile(structuredClone(unwrap(newValue)), { merge: true }),
24-
);
21+
const snapshot = structuredClone(unwrap(newValue));
22+
23+
delete snapshot.testActivity;
24+
delete snapshot.testActivityByYear;
25+
26+
const miniSnapshot = {
27+
...snapshot,
28+
isMiniSnapshot: true,
29+
};
30+
31+
updateSnapshot("value", reconcile(miniSnapshot, { merge: true }));
2532
}
2633
}
2734

0 commit comments

Comments
 (0)