feat: add stub for engine's fetchUpdate()
This commit is contained in:
parent
db79d45217
commit
c05c3cd2d6
3
client/src/composables/engine/fetchUpdate.ts
Normal file
3
client/src/composables/engine/fetchUpdate.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export function fetchUpdate() {
|
||||
console.log('fetchUpdate() called')
|
||||
}
|
@ -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')
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user