feat: load session and display start button if not exists

This commit is contained in:
wancat committed 2024-06-27 11:55:34 +08:00
1 parent c64043316e
commit 3398d18055
7 files changed
+51 -56

No files matched your search

+16 -8
View File
@@ -1,14 +1,14 @@
<script setup lang="ts">
import { ref, watch } from 'vue'
import { computed, ref, watch } from 'vue'
import useSession from '../../store/session'
import MarkdownText from '../MarkdownText.vue'
const sessionStore = useSession()
const current = ref(-1)
watch(
() => sessionStore.session.hints,
() => sessionStore.session?.hints,
(hints) => {
current.value = hints.length - 1
current.value = hints ? hints.length - 1 : -1
},
{ deep: true }
)
@@ -20,10 +20,18 @@ const left = () => {
}
const right = () => {
if (current.value < sessionStore.session.hints.length - 1) {
if (current.value < (sessionStore.session?.hints.length ?? 0) - 1) {
current.value += 1
}
}
const length = computed(() => {
return sessionStore.session?.hints.length ?? 0
})
const disabled = computed(() => {
return current.value === length.value - 1
})
</script>
<template>
@@ -50,13 +58,13 @@ const right = () => {
<p class="inline text-text font-xl w-1/14 p-2 m-1">{{ current + 1 }}</p>
<p class="inline text-text font-xl w-1/14 p-2 m-1">/</p>
<p class="inline text-text font-xl w-1/14 p-2 m-1">
{{ sessionStore.session.hints.length }}
{{ length }}
</p>
<button
class="p-2 m-1 w-1/8"
id="Rbutton"
@click="right"
:disabled="current === sessionStore.session.hints.length - 1"
:disabled="disabled"
>
<font-awesome-icon :icon="['fas', 'arrow-right']" class="text-text" />
</button>
@@ -65,7 +73,7 @@ const right = () => {
<div id="hint" class="bg-bg p-8 overflow-y-auto">
<ul>
<li
v-for="response in sessionStore.session.responses[current]"
v-for="response in sessionStore.session?.responses[current]"
:key="response.type"
class="text-text font-xl whitespace-pre-wrap"
>
@@ -74,7 +82,7 @@ const right = () => {
</div>
</li>
<li
v-for="hint in sessionStore.session.hints[current]"
v-for="hint in sessionStore.session?.hints[current]"
:key="hint"
class="text-text-primary font-xl whitespace-pre-wrap"
>