This commit is contained in:
2026-03-04 23:09:02 +01:00
parent 94ec4e7135
commit 409f44476f
9 changed files with 259 additions and 42 deletions

View File

@@ -1,6 +1,6 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { Whiteboard } from '@/types'
import type {JoinResult, Whiteboard} from '@/types'
import { whiteboardService } from '@/services/whiteboardService'
export const useWhiteboardsStore = defineStore('whiteboards', () => {
@@ -8,6 +8,7 @@ export const useWhiteboardsStore = defineStore('whiteboards', () => {
const recentWhiteboards = ref<Whiteboard[]>([])
const currentWhiteboard = ref<Whiteboard | null>(null)
const isLoading = ref(false)
const isWaitingToJoin = ref(false)
const error = ref<string | null>(null)
async function getWhiteboardHistory() {
@@ -53,6 +54,27 @@ export const useWhiteboardsStore = defineStore('whiteboards', () => {
return newWhiteboard.id;
}
async function joinWhiteboardWithCode(code: string): Promise<JoinResult> {
isLoading.value = true;
try {
return await whiteboardService.joinWhiteboard(code);
} catch (err: any) {
error.value = err.message ?? 'Failed to join whiteboard';
throw err;
} finally {
isLoading.value = false;
}
}
function startWaitingToJoin() {
isWaitingToJoin.value = true;
}
function stopWaitingToJoin() {
isWaitingToJoin.value = false;
}
async function deleteWhiteboard(id: string): Promise<void> {
isLoading.value = true
error.value = null
@@ -92,10 +114,14 @@ export const useWhiteboardsStore = defineStore('whiteboards', () => {
ownedWhiteboards: ownedWhiteboards,
recentWhiteboards: recentWhiteboards,
isLoading,
isWaitingToJoin,
error,
getWhiteboardHistory: getWhiteboardHistory,
getRecentWhiteboards: getRecentWhiteboards,
createNewWhiteboard: createNewWhiteboard,
joinWhiteboardWithCode: joinWhiteboardWithCode,
startWaitingToJoin: startWaitingToJoin,
stopWaitingToJoin: stopWaitingToJoin,
deleteWhiteboard: deleteWhiteboard,
getCurrentWhiteboard: getCurrentWhiteboard,
selectWhiteboard: selectWhiteboard,