Files
archie/ui/src/settings/InstructionsPage.vue
T

60 lines
2.1 KiB
Vue

<script setup lang="ts">
import { Alert, AlertDescription } from "@/components/ui/alert";
import ApplyStatusRows from "./ApplyStatusRows.vue";
import { computed, onMounted } from "vue";
import { storeToRefs } from "pinia";
import PageHeader from "@/base/PageHeader.vue";
import { Textarea } from "@/components/ui/textarea";
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
import { Section } from "@/components/ui/section";
import DraftHint from "./DraftHint.vue";
import HistoryLink from "./HistoryLink.vue";
import { fieldInvalid } from "./settings-form";
const KIND = "soul";
const store = useSettingsStore();
const { catalog, catalogError } = storeToRefs(store);
onMounted(store.load);
const resources = computed(() => resourcesForPage(catalog.value, "soul"));
const form = computed(() => store.formFor(KIND));
const soul = computed(() => store.draftValue(KIND) as { text: string } | undefined);
const error = computed(() => store.pageErrorFor(KIND));
const chars = computed(() => soul.value?.text.length ?? 0);
</script>
<template>
<div>
<PageHeader title="Instructions">
<HistoryLink :kinds="resources.map((r) => r.kind)" />
</PageHeader>
<ApplyStatusRows v-for="resource in resources" :key="resource.kind" :kind="resource.kind" class="mb-4" />
<Alert v-if="catalogError || error" variant="destructive" class="mb-4"><AlertDescription>
{{ catalogError || error }}
</AlertDescription></Alert>
<Section v-if="form && soul">
<form.Field v-slot="{ field }" name="text">
<div class="flex justify-end">
<DraftHint :kind="KIND" path="text" />
</div>
<Textarea
id="soul-text"
:model-value="field.state.value"
:rows="18"
class="mt-1 font-mono text-label"
aria-label="Instructions"
:aria-invalid="fieldInvalid(field)"
@blur="field.handleBlur"
@update:model-value="field.handleChange"
/>
</form.Field>
<p class="mt-1.5 text-xs text-fg-subtle">
{{ chars.toLocaleString() }} chars · ~{{ Math.round(chars / 4).toLocaleString() }} tokens</p>
</Section>
</div>
</template>