@@ -8,77 +8,11 @@ export function setStorage(workspaceState: vscode.Memento): void {
88 storage = workspaceState
99}
1010
11- // TUTORIAL
12- const STORE_TUTORIAL = 'coderoad:tutorial'
13-
14- export async function getTutorial ( ) : Promise < CR . Tutorial | undefined > {
15- return storage . get ( STORE_TUTORIAL )
16- }
17-
18- export async function setTutorial ( tutorial : CR . Tutorial ) : Promise < void > {
19- await storage . update ( STORE_TUTORIAL , tutorial )
11+ export function get < T > ( key : string ) : T | undefined {
12+ return storage . get ( key )
2013}
2114
22- // POSITION
23- const STORE_POSITION = 'coderoad:position'
24-
25- const defaultPosition = { levelId : '' , stageId : '' , stepId : '' }
26-
27- export async function getPosition ( ) : Promise < CR . Position > {
28- const position : CR . Position | undefined = storage . get ( STORE_POSITION )
29- return position || defaultPosition
15+ export function update < T > ( key : string , value : string | Object ) : Thenable < void > {
16+ return storage . update ( key , value )
3017}
3118
32- export async function setPosition ( position : CR . Position ) : Promise < void > {
33- await storage . update ( STORE_POSITION , position )
34- }
35-
36- // PROGRESS
37- const STORE_PROGRESS = 'coderoad:progress'
38-
39- const defaultProgress = { levels : { } , stages : { } , steps : { } , hints : { } , complete : false }
40-
41- export async function getProgress ( ) : Promise < CR . Progress > {
42- const progress : CR . Progress | undefined = await storage . get ( STORE_PROGRESS )
43- return progress || defaultProgress
44- }
45-
46- export async function resetProgress ( ) : Promise < void > {
47- await storage . update ( STORE_PROGRESS , defaultProgress )
48- }
49-
50- interface ProgressUpdate {
51- levels ?: {
52- [ levelId : string ] : boolean
53- }
54- stages ?: {
55- [ stageid : string ] : boolean
56- }
57- steps ?: {
58- [ stepId : string ] : boolean
59- }
60- }
61-
62- export async function updateProgress ( record : ProgressUpdate ) : Promise < void > {
63- const progress = await getProgress ( )
64- if ( record . levels ) {
65- progress . levels = {
66- ...progress . levels ,
67- ...record . levels ,
68- }
69- }
70- if ( record . stages ) {
71- progress . stages = {
72- ...progress . stages ,
73- ...record . stages ,
74- }
75- }
76- if ( record . steps ) {
77- progress . steps = {
78- ...progress . steps ,
79- ...record . steps ,
80- }
81- }
82-
83- await storage . update ( STORE_PROGRESS , progress )
84- }
0 commit comments