Skip to content

Commit

Permalink
Merge pull request #22 from LyonSyonII/dev
Browse files Browse the repository at this point in the history
Fix checkpoints old format error
  • Loading branch information
LyonSyonII authored Dec 19, 2023
2 parents e698074 + e20b079 commit a862b07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions frontend/src/components/Checkpoint/checkpoint.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
type Checkpoints = Map<string, Set<string>>;

class Persistent {
persistent: Checkpoints = new Map<string, Set<string>>();
persistent: Checkpoints = new Map();
subscribers: Array<(checkpoints: Checkpoints) => void> = [];

constructor() {
this.persistent = this.deserialize();
}

private serialize() {
const serialized: Array<[string, string[]]> = [
...this.persistent.entries(),
].map(([k, v]) => [k, Array.from(v)]);
localStorage.setItem("checkpoints", JSON.stringify(serialized));
}


/* Old format
{"data":[["#$@__reference__1","1",{"data":["1-1"],"#$@__constructor__":"Set","#$@__reference__":2}],["#$@__reference__3","2",{"data":["2-1","2-2","2-3","2-4","2-5","2-6","2-7","2-8","2-confetti"],"#$@__constructor__":"Set","#$@__reference__":4}],["#$@__reference__5","3",{"data":["3-1"],"#$@__constructor__":"Set","#$@__reference__":6}],["#$@__reference__7","4",{"data":["4-1"],"#$@__constructor__":"Set","#$@__reference__":8}]],"#$@__constructor__":"Map","#$@__reference__":0}
*/
private deserialize(): Checkpoints {
const item = localStorage.getItem("checkpoints") as string;
const parsed: Array<[string, string[]]> = (item && JSON.parse(item)) || [];
if (!Array.isArray(parsed)) {
window.alert("Failed to load checkpoints, resetting progress.")
return new Map();
}
return new Map(parsed.map(([k, v]) => [k, new Set(v)]));
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/content/docs/en/first-steps/4-enrolling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Please fill in the remaining information in the blanks provided:
</Guild>

:::caution[Data collection?]
**DATA WILL NOT BE COLLECTED** in any way, it's just an exercise.
**DATA WILL NOT BE COLLECTED** in any way, it's just for the exercise.
If you're worried about it, use dummy values that don't match your real data.
:::

Expand Down

0 comments on commit a862b07

Please sign in to comment.