49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
import { useRoute } from 'vue-router'
|
|
import { Board } from '@/services/Board'
|
|
import { User } from '@/services/User'
|
|
import { Spending } from '@/services/Spending'
|
|
|
|
export const useBoardStore = defineStore('boardStore', () => {
|
|
const route = useRoute()
|
|
const boards = new Map<string, Board>()
|
|
let testBoard: Board | undefined
|
|
|
|
function createBoard(name: string): Board {
|
|
const newBoard = new Board(name)
|
|
boards.set(newBoard.guid, newBoard)
|
|
return newBoard
|
|
}
|
|
|
|
function getBoard(guid: string): Board {
|
|
const board = boards.get(guid)
|
|
if (board != undefined) {
|
|
return board
|
|
} else {
|
|
if (testBoard === undefined) {
|
|
testBoard = new Board('Grill and Chill')
|
|
const elias = new User('Elias')
|
|
elias.addSpending(new Spending('Burger', 1230))
|
|
elias.addSpending(new Spending('Kaffee', 510))
|
|
testBoard.addUser(elias)
|
|
const max = new User('Max')
|
|
max.addSpending(new Spending('Omlett', 1822))
|
|
max.addSpending(new Spending('Kaffee', 3073))
|
|
testBoard.addUser(max)
|
|
return testBoard
|
|
}
|
|
return testBoard
|
|
}
|
|
}
|
|
|
|
function getCurrentBoard(): Board {
|
|
if (typeof route.params.boardId === 'string') {
|
|
return getBoard(route.params.boardId)
|
|
} else {
|
|
return getBoard('')
|
|
}
|
|
}
|
|
|
|
return { createBoard, getBoard, getCurrentBoard }
|
|
})
|