67 lines
2.6 KiB
Vue
67 lines
2.6 KiB
Vue
|
|
<script setup lang="ts">
|
||
|
|
const ed = useEditor()
|
||
|
|
const close = () => {
|
||
|
|
ed.dialog.value = 'projects'
|
||
|
|
ed.versionsFor.value = null
|
||
|
|
}
|
||
|
|
|
||
|
|
const id = computed(() => ed.versionsFor.value)
|
||
|
|
const name = computed(() => ed.projects.value.find(m => m.id === id.value)?.name ?? '')
|
||
|
|
const versions = ref<{ v: number; at: number; rev: number; name: string; size: number }[] | null>(null)
|
||
|
|
const error = ref('')
|
||
|
|
const busy = ref<number | null>(null)
|
||
|
|
|
||
|
|
const when = (t: number) => new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' }).format(t)
|
||
|
|
const kb = (n: number) => `${Math.max(1, Math.round(n / 1024))} KB`
|
||
|
|
|
||
|
|
onMounted(async () => {
|
||
|
|
if (!id.value) return
|
||
|
|
try {
|
||
|
|
versions.value = await ed.listVersions(id.value)
|
||
|
|
} catch (e) {
|
||
|
|
error.value = (e as Error).message
|
||
|
|
}
|
||
|
|
})
|
||
|
|
|
||
|
|
async function restore(v: number, asCopy: boolean) {
|
||
|
|
if (!id.value) return
|
||
|
|
busy.value = v
|
||
|
|
try {
|
||
|
|
await ed.restoreVersion(id.value, v, asCopy)
|
||
|
|
ed.dialog.value = null
|
||
|
|
} catch (e) {
|
||
|
|
error.value = (e as Error).message
|
||
|
|
} finally {
|
||
|
|
busy.value = null
|
||
|
|
}
|
||
|
|
}
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<template>
|
||
|
|
<div class="modal-backdrop" @click.self="close">
|
||
|
|
<div class="modal" role="dialog" aria-labelledby="versions-title">
|
||
|
|
<div class="flex items-start justify-between gap-4">
|
||
|
|
<h2 id="versions-title">Savegames of "{{ name }}"</h2>
|
||
|
|
<button class="tb-btn" title="Back" @click="close"><Icon name="lucide:x" class="size-4" /></button>
|
||
|
|
</div>
|
||
|
|
<p class="hint mt-1">
|
||
|
|
Kept automatically in your account while you work: a version at most every 15 minutes, the newest 30 plus one per day for 90 days.
|
||
|
|
Restoring keeps the current state as a savegame too, so nothing is lost.
|
||
|
|
</p>
|
||
|
|
<p v-if="error" class="result fail"><Icon name="lucide:circle-x" class="size-4 shrink-0" /> {{ error }}</p>
|
||
|
|
<p v-else-if="!versions" class="hint">Loading…</p>
|
||
|
|
<p v-else-if="!versions.length" class="hint">No savegames yet. The first one is kept the next time this project changes, 15 minutes after the last save.</p>
|
||
|
|
<ul v-else class="project-list">
|
||
|
|
<li v-for="v in versions" :key="v.v">
|
||
|
|
<div class="pick">
|
||
|
|
<span class="name">{{ when(v.at) }}</span>
|
||
|
|
<span class="meta">{{ v.name }} · revision {{ v.rev }} · {{ kb(v.size) }}</span>
|
||
|
|
</div>
|
||
|
|
<button class="btn-sm" :disabled="busy !== null" title="Replace the project with this version" @click="restore(v.v, false)">Restore</button>
|
||
|
|
<button class="btn-sm" :disabled="busy !== null" title="Open this version as a separate project" @click="restore(v.v, true)">As copy</button>
|
||
|
|
</li>
|
||
|
|
</ul>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</template>
|