feat: add stub for engine's fetchUpdate()

This commit is contained in:
Settel 2022-08-02 22:34:46 +02:00
parent db79d45217
commit c05c3cd2d6
5 changed files with 21 additions and 6 deletions

View File

@ -0,0 +1,3 @@
export function fetchUpdate() {
console.log('fetchUpdate() called')
}

View File

@ -1,10 +1,19 @@
import { useUserinfoStore } from "@/stores/UserinfoStore"
export function start(): void {
if (this.isActive.value && !this.shouldStop.value) {
console.warn('attempt to start already running engine!')
return
}
if (useUserinfoStore().isAdmin) {
console.debug('user is admin, engine not started')
return
}
this.isActive.value = true
this.shouldStop.value = false
this.fetchUpdate()
console.log('start engine')
}

View File

@ -1,25 +1,30 @@
import { useState } from '#app'
import { Ref } from 'vue'
import { start, stop } from '@/composables/engine/startStop'
import { fetchUpdate } from '@/composables/engine/fetchUpdate'
interface EngineContext {
isActive: Ref<boolean>
shouldStop: Ref<boolean>
fetchUpdate: () => void
}
export interface useEngine {
start(): void
stop(): void
fetchUpdate(): void
}
export default (): useEngine => {
const context: EngineContext = {
isActive: useState('engine__is-active', () => false),
shouldStop: useState('engine__should-stop', () => false),
fetchUpdate,
}
return {
start: () => start.apply(context),
stop: () => stop.apply(context),
fetchUpdate: () => fetchUpdate.apply(context),
}
}

View File

@ -19,15 +19,14 @@
</template>
<script setup lang="ts">
import { useRuntimeConfig, useRouter } from '#app'
import { useRuntimeConfig, navigateTo } from '#app'
import useAuth from '@/composables/useAuth'
const config = useRuntimeConfig()
try {
await useAuth().authenticateAndLoadUserInfo()
useRouter().push('/play')
navigateTo('/play', { replace: true })
} catch (e) {
// nop
}

View File

@ -6,17 +6,16 @@
</template>
<script setup lang="ts">
import { useRouter } from '#app'
import { navigateTo } from '#app'
import useAuth from '@/composables/useAuth';
import useEngine from '@/composables/useEngine';
import { onMounted, onBeforeUnmount } from 'vue';
const { authenticateAndLoadUserInfo } = useAuth()
const router = useRouter()
try {
await authenticateAndLoadUserInfo()
} catch(e) {
router.push('/')
navigateTo('/', { replace: true })
}
const { start: startEngine, stop: stopEngine } = useEngine()