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 { export function start(): void {
if (this.isActive.value && !this.shouldStop.value) { if (this.isActive.value && !this.shouldStop.value) {
console.warn('attempt to start already running engine!') console.warn('attempt to start already running engine!')
return return
} }
if (useUserinfoStore().isAdmin) {
console.debug('user is admin, engine not started')
return
}
this.isActive.value = true this.isActive.value = true
this.shouldStop.value = false this.shouldStop.value = false
this.fetchUpdate()
console.log('start engine') console.log('start engine')
} }

View File

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

View File

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

View File

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