add tutorial progress backend

This commit is contained in:
Ruben Fiszel
2023-09-29 15:56:21 +02:00
parent 6f558f5898
commit 64caf938e3
3 changed files with 57 additions and 1 deletions
+1
View File
@@ -19,6 +19,7 @@ export interface UserExt {
const persistedWorkspace = BROWSER && localStorage.getItem('workspace')
export const tutorialsToDo = writable<number[]>([])
export const globalEmailInvite = writable<string>('')
export const awarenessStore = writable<Record<string, string>>(undefined)
export const enterpriseLicense = writable<string | undefined>(undefined)
+52
View File
@@ -0,0 +1,52 @@
import { get } from "svelte/store";
import { tutorialsToDo } from "./stores";
import { UserService } from "./gen";
const MAX_TUTORIAL_ID = 6
export async function updateProgress(id: number) {
const bef = get(tutorialsToDo)
const aft = bef.filter((x) => x != id)
tutorialsToDo.set(aft)
let bits = 0
for (let i = 0; i <= MAX_TUTORIAL_ID; i++) {
let mask = 1 << i;
if (!aft.includes(i)) {
bits = bits | mask
}
}
await UserService.updateTutorialProgress({requestBody: { progress: bits}})
}
export async function skipAllTodos() {
let bits = 0
for (let i = 0; i <= MAX_TUTORIAL_ID; i++) {
let mask = 1 << i;
bits = bits | mask
}
tutorialsToDo.set([])
await UserService.updateTutorialProgress({requestBody: { progress: bits}})
}
export async function resetAllTodos() {
let todos: number[] = []
for (let i = 0; i <= MAX_TUTORIAL_ID; i++) {
todos.push(i)
}
tutorialsToDo.set(todos)
await UserService.updateTutorialProgress({requestBody: { progress: 0 }})
}
export async function syncTutorialsTodos() {
const bits: number = (await UserService.getTutorialProgress()).progress!
const todos: number[] = []
for (let i = 0; i <= MAX_TUTORIAL_ID; i++) {
let mask = 1 << i;
if ((bits & mask) == 0) {
todos.push(i)
}
}
tutorialsToDo.set(todos)
}
@@ -12,7 +12,7 @@
ScriptService,
UserService
} from '$lib/gen'
import { classNames } from '$lib/utils'
import { classNames, sendUserToast } from '$lib/utils'
import WorkspaceMenu from '$lib/components/sidebar/WorkspaceMenu.svelte'
import SidebarContent from '$lib/components/sidebar/SidebarContent.svelte'
@@ -20,6 +20,7 @@
enterpriseLicense,
starStore,
superadmin,
tutorialsToDo,
usageStore,
userStore,
workspaceStore
@@ -34,6 +35,7 @@
import { SUPERADMIN_SETTINGS_HASH, USER_SETTINGS_HASH } from '$lib/components/sidebar/settings'
import { isCloudHosted } from '$lib/cloud'
import MultiplayerMenu from '$lib/components/sidebar/MultiplayerMenu.svelte'
import { syncTutorialsTodos, updateProgress } from '$lib/tutorialUtils'
OpenAPI.WITH_CREDENTIALS = true
let menuOpen = false
@@ -74,6 +76,7 @@
function onLoad() {
loadFavorites()
loadUsage()
syncTutorialsTodos()
}
async function loadUsage() {