feat: fetch quotes from server

This commit is contained in:
Settel 2022-08-09 13:36:05 +02:00
parent 5e58c9c994
commit f629d7cdb3
4 changed files with 25 additions and 22 deletions

View File

@ -5,28 +5,10 @@
</template>
<script setup lang="ts">
const quotes = [
{
id: 1,
quote: 'Somna imanus it vorgenstra exa al termanum.',
},
{
id: 2,
quote: 'Kerbositus con vai quel verendenguum. Abtanosi con vai stice vermadostuos, na tum gehomo asbabasictnem orb eterum (phlegtum aka iborn).',
},
{
id: 3,
quote: 'blah! #1',
},
{
id: 4,
quote: 'blah! #2',
},
{
id: 5,
quote: 'blah! #3',
},
]
import useEngine from '@/composables/useEngine'
const engine = useEngine()
const quotes = await engine.getQuotes()
console.log(quotes)
</script>
<style lang="scss">

6
client/src/composables/engine.d.ts vendored Normal file
View File

@ -0,0 +1,6 @@
export type Quote = {
id: string
quote: string
}
export type Quotes = Array<Quote>

View File

@ -0,0 +1,11 @@
import type { Quotes } from '@/composables/engine.d'
import { useUserinfoStore } from "@/stores/UserinfoStore"
export async function getQuotes(): Promise<Quotes> {
const userInfoStore = useUserinfoStore()
const response = await this.callApi('/api/getQuotes', {
g: userInfoStore.gameId,
})
return response.quotes
}

View File

@ -2,6 +2,8 @@ import { Ref, ref } from 'vue'
import { callApi, QueryParams } from '@/composables/engine/callApi'
import { start, stop } from '@/composables/engine/startStop'
import { fetchUpdate } from '@/composables/engine/fetchUpdate'
import { getQuotes } from '@/composables/engine/getQuotes'
import type { Quotes } from '@/composables/engine.d'
interface EngineContext {
isActive: boolean
@ -20,6 +22,7 @@ export interface useEngine {
start(): void
stop(): void
fetchUpdate(): void
getQuotes(): Promise<Quotes>
}
export default (): useEngine => {
@ -41,5 +44,6 @@ export default (): useEngine => {
start: () => start.apply(context),
stop: () => stop.apply(context),
fetchUpdate: () => fetchUpdate.apply(context),
getQuotes: () => getQuotes.apply(context),
}
}