45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { Ref, ref } from 'vue'
|
|
import type { Quotes } from '@/composables/engine.d'
|
|
import { useUserinfoStore } from "@/stores/UserinfoStore"
|
|
import { EngineContext } from '@/composables/useEngine'
|
|
|
|
type QuotesResponse = {
|
|
quotes: Quotes
|
|
}
|
|
|
|
const quotes = ref([]) as Ref<Quotes>
|
|
|
|
export async function loadQuotes(this: EngineContext): Promise<void> {
|
|
const userInfoStore = useUserinfoStore()
|
|
const response = await this.callApi('/api/getQuotes', {
|
|
g: userInfoStore.gameId,
|
|
}) as QuotesResponse
|
|
|
|
quotes.value.splice(0, quotes.value.length, ...response.quotes)
|
|
}
|
|
|
|
export function getQuotesRef(): Ref<Quotes> {
|
|
return quotes
|
|
}
|
|
|
|
export async function deleteQuote(this: EngineContext, id: string): Promise<void> {
|
|
const userInfoStore = useUserinfoStore()
|
|
await this.callApi('/api/removeQuote', {
|
|
g: userInfoStore.gameId,
|
|
id,
|
|
})
|
|
|
|
await this.loadQuotes()
|
|
}
|
|
|
|
export async function saveQuote(this: EngineContext, id: string, quote: string): Promise<void> {
|
|
const userInfoStore = useUserinfoStore()
|
|
await this.callApi('/api/saveQuote', {
|
|
g: userInfoStore.gameId,
|
|
id,
|
|
quote,
|
|
})
|
|
|
|
await this.loadQuotes()
|
|
}
|