Skip to content

AI-native design editor. Open-source Figma alternative.

feat(app): unify recent and storage home

Victor Wads3b9375730f31
diff --git a/src/app/document/io/source.ts b/src/app/document/io/source.ts
index 058f3e198..18e0d4184 100644
--- a/src/app/document/io/source.ts
+++ b/src/app/document/io/source.ts
@@ -49,7 +49,7 @@ export function createDocumentSourceActions({
}: DocumentSourceOptions) {
function buildFigFile() {
const renderer = getRenderer()
- return exportFigFile(editor.graph, renderer?.ck, renderer ?? undefined)
+ return exportFigFile(editor.graph, renderer?.ck, renderer ?? undefined, state.currentPageId)
}
function buildRecoveryFigFile() {
diff --git a/src/app/shell/menu/navigation.ts b/src/app/shell/menu/navigation.ts
index 945ead55a..b57d471ec 100644
--- a/src/app/shell/menu/navigation.ts
+++ b/src/app/shell/menu/navigation.ts
@@ -1,5 +1,8 @@
import type { Router } from 'vue-router'
export function openStorageWorkspace(router: Router): void {
- void router.push('/storage')
+ void router
+ .push('/')
+ .then(() => import('@/app/tabs'))
+ .then(({ showRecentFiles }) => showRecentFiles())
}
diff --git a/src/app/tabs/index.ts b/src/app/tabs/index.ts
index 776ca3c23..76ff2f53a 100644
--- a/src/app/tabs/index.ts
+++ b/src/app/tabs/index.ts
@@ -154,16 +154,16 @@ function isDOMImportFile(file: File): boolean {
return /\.(html?|xhtml)$/i.test(file.name)
}
-function reusableTabStore(): EditorStore {
+function reusableTabStore(): { store: EditorStore; created: boolean } {
const current = activeTab.value
- if (current?.showHome) return createTab().store
+ if (current?.showHome) return { store: createTab().store, created: true }
const isUntouched =
current?.store.state.documentName === 'Untitled' && !current.store.undo.canUndo
if (isUntouched) {
leaveHome(current.id)
- return current.store
+ return { store: current.store, created: false }
}
- return createTab().store
+ return { store: createTab().store, created: true }
}
async function readFigForTab(file: File, store: EditorStore): Promise<SceneGraph> {
@@ -249,7 +249,7 @@ export async function openStorageDocumentInNewTab(document: StorageDocument): Pr
return
}
- const store = reusableTabStore()
+ const { store, created } = reusableTabStore()
store.state.documentName = document.name
store.state.loading = true
try {
@@ -282,6 +282,12 @@ export async function openStorageDocumentInNewTab(document: StorageDocument): Pr
await showImportedGraph(store, imported, () =>
store.setStorageDocumentSource({ providerId, documentId: document.id }, document.name)
)
+ } catch (error) {
+ if (created) {
+ const tab = getTabForStore(store)
+ if (tab) await closeTab(tab.id)
+ }
+ throw error
} finally {
store.state.loading = false
}
@@ -316,7 +322,7 @@ export async function openFileInNewTab(
return { kind: 'existing' as const }
}
- const store = reusableTabStore()
+ const { store, created } = reusableTabStore()
store.state.documentName = file.name.replace(/\.[^.]+$/i, '')
store.state.loading = true
@@ -324,7 +330,7 @@ export async function openFileInNewTab(
void completion.promise.catch(() => undefined)
const pendingOpen = { completion: completion.promise, identity, store }
fileOpenCoordinator.add(pendingOpen)
- return { kind: 'owner' as const, completion, pendingOpen, store }
+ return { kind: 'owner' as const, completion, pendingOpen, store, created }
})
if (decision.kind === 'existing') return
@@ -333,7 +339,7 @@ export async function openFileInNewTab(
return
}
- const { completion, pendingOpen, store } = decision
+ const { completion, pendingOpen, store, created } = decision
try {
if (isDOMImportFile(file)) {
await store.openDOMFile(file, { handle, path })
@@ -368,6 +374,10 @@ export async function openFileInNewTab(
completion.resolve(undefined)
} catch (error) {
completion.reject(error)
+ if (created) {
+ const tab = getTabForStore(store)
+ if (tab) await closeTab(tab.id)
+ }
throw error
} finally {
store.state.loading = false
@@ -387,7 +397,7 @@ export async function restoreRecoverySnapshot(id: string): Promise<void> {
const snapshot = await getRecoveryStore().read(id)
if (!snapshot) throw new Error('Recovery snapshot is no longer available')
- const store = reusableTabStore()
+ const { store } = reusableTabStore()
store.state.loading = true
try {
const fileBytes = new Uint8Array(snapshot.figBytes)
diff --git a/src/components/recent-files/RecentFilesHome.vue b/src/components/recent-files/RecentFilesHome.vue
index 1d3126946..0fd07b0f4 100644
--- a/src/components/recent-files/RecentFilesHome.vue
+++ b/src/components/recent-files/RecentFilesHome.vue
@@ -12,11 +12,16 @@ import {
type RecentFile
} from '@/app/shell/menu/recent-files'
import { openFileDialog, openFileFromPath } from '@/app/shell/menu/use'
+import { activeStorageProviderID, type StorageDocument } from '@/app/integrations/storage'
+import { openSettingsDialog } from '@/app/settings/dialog'
+import { createStorageWorkspaceSource } from '@/app/storage/workspace/source'
+import { openStorageDocumentInNewTab } from '@/app/tabs'
const emit = defineEmits<{ 'new-document': [] }>()
const { dialogs, menu, panels, locale } = useI18n()
-const view = useLocalStorage<'grid' | 'list'>('open-pencil:recent-files-view', 'grid')
+const view = useLocalStorage<'grid' | 'list'>('open-pencil:home-files-view', 'grid')
const openError = ref<string | null>(null)
+const storageConfigured = ref(false)
const workspace = useDocumentWorkspace<RecentFile>({
source: {
@@ -35,8 +40,23 @@ const previewURL = workspace.previewURL
const vWorkspacePreview = workspace.previewDirective
const hasRecentFiles = computed(() => documents.value.length > 0)
+const storageWorkspace = useDocumentWorkspace<StorageDocument>({
+ source: createStorageWorkspaceSource((snapshot) => {
+ storageConfigured.value = snapshot.configured
+ }),
+ refreshInterval: 60_000,
+ previewConcurrency: 6
+})
+const storageDocuments = storageWorkspace.documents
+const storagePreviewURL = storageWorkspace.previewURL
+const vStoragePreview = storageWorkspace.previewDirective
+
watch(recentFiles, () => void workspace.invalidate())
+async function refreshHome(): Promise<void> {
+ await Promise.all([workspace.refresh(), storageWorkspace.refresh()])
+}
+
async function openRecent(document: RecentFile): Promise<void> {
openError.value = null
try {
@@ -47,6 +67,10 @@ async function openRecent(document: RecentFile): Promise<void> {
}
}
+async function openStorageDocument(document: StorageDocument): Promise<void> {
+ await openStorageDocumentInNewTab(document)
+}
+
function formattedDate(updatedAt: string): string {
const date = new Date(updatedAt)
if (date.getTime() === 0) return ''
@@ -62,6 +86,22 @@ function formattedDate(updatedAt: string): string {
<span class="text-sm font-semibold">OpenPencil</span>
</div>
<div class="ml-auto flex items-center gap-2">
+ <button
+ type="button"
+ class="flex size-7 items-center justify-center rounded text-muted hover:bg-hover hover:text-surface"
+ :aria-label="dialogs.refresh"
+ @click="refreshHome"
+ >
+ <icon-lucide-refresh-cw class="size-3.5" />
+ </button>
+ <button
+ type="button"
+ class="rounded px-3 py-1.5 text-xs text-muted hover:bg-hover hover:text-surface"
+ @click="openSettingsDialog('storage')"
+ >
+ <icon-lucide-settings-2 class="mr-1.5 inline size-3.5" />
+ {{ dialogs.settings }}
+ </button>
<button
type="button"
class="rounded px-3 py-1.5 text-xs text-muted hover:bg-hover hover:text-surface"
@@ -89,8 +129,9 @@ function formattedDate(updatedAt: string): string {
<h1 class="text-xl font-semibold">{{ dialogs.recentFiles }}</h1>
<p class="mt-1 text-xs text-muted">{{ dialogs.recentFilesDescription }}</p>
</div>
- <div v-if="hasRecentFiles" class="ml-auto flex rounded border border-border p-0.5">
+ <div class="ml-auto flex rounded border border-border p-0.5">
<button
+ v-if="hasRecentFiles"
type="button"
class="flex size-7 items-center justify-center rounded-sm text-muted hover:text-surface"
:aria-label="dialogs.clear"
@@ -170,7 +211,10 @@ function formattedDate(updatedAt: string): string {
</button>
</div>
- <div v-else class="flex flex-1 flex-col items-center justify-center pb-20 text-center">
+ <div
+ v-else-if="!storageConfigured"
+ class="flex flex-1 flex-col items-center justify-center pb-20 text-center"
+ >
<div class="mb-4 flex size-12 items-center justify-center rounded-xl bg-panel-field">
<icon-lucide-files class="size-5 text-muted" />
</div>
@@ -184,6 +228,73 @@ function formattedDate(updatedAt: string): string {
{{ menu.open }}
</button>
</div>
+
+ <section v-if="storageConfigured" class="mt-10">
+ <div class="mb-6 flex items-center">
+ <div>
+ <h2 class="text-xl font-semibold">{{ dialogs.storageWorkspace }}</h2>
+ <p class="mt-1 text-xs text-muted">{{ activeStorageProviderID }}</p>
+ </div>
+ </div>
+
+ <div
+ v-if="storageDocuments.length && view === 'grid'"
+ class="grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-5"
+ >
+ <button
+ v-for="document in storageDocuments"
+ :key="document.id"
+ type="button"
+ class="group overflow-hidden rounded-lg border border-border bg-panel text-left transition-colors hover:border-panel-focus hover:bg-hover"
+ @click="openStorageDocument(document)"
+ >
+ <div
+ v-storage-preview="document.id"
+ class="flex aspect-video items-center justify-center overflow-hidden bg-panel-field"
+ >
+ <img
+ v-if="storagePreviewURL(document.id)"
+ :src="storagePreviewURL(document.id) ?? undefined"
+ alt=""
+ class="size-full object-cover transition-transform duration-200 group-hover:scale-[1.015]"
+ />
+ <icon-lucide-file-image v-else class="size-8 text-muted/40" />
+ </div>
+ <div class="border-t border-border p-3">
+ <p class="truncate text-xs font-medium">{{ document.name }}</p>
+ <p class="mt-1 truncate text-[10px] text-muted">
+ {{ formattedDate(document.updatedAt) }}
+ </p>
+ </div>
+ </button>
+ </div>
+
+ <div
+ v-else-if="storageDocuments.length"
+ class="overflow-hidden rounded-lg border border-border"
+ >
+ <button
+ v-for="document in storageDocuments"
+ :key="document.id"
+ type="button"
+ class="flex w-full items-center gap-3 border-b border-border px-4 py-3 text-left last:border-b-0 hover:bg-hover"
+ @click="openStorageDocument(document)"
+ >
+ <icon-lucide-file-image class="size-4 shrink-0 text-accent" />
+ <span class="min-w-0 flex-1 truncate text-xs font-medium">{{ document.name }}</span>
+ <span class="shrink-0 text-[10px] text-muted">{{
+ formattedDate(document.updatedAt)
+ }}</span>
+ </button>
+ </div>
+
+ <div
+ v-else
+ class="rounded-lg border border-border border-dashed px-4 py-8 text-center text-xs text-muted"
+ >
+ {{ dialogs.emptyStorageWorkspace }}
+ </div>
+ </section>
</section>
</main>
</template>
diff --git a/src/views/EditorView.vue b/src/views/EditorView.vue
index 2db3413a8..beaa4647c 100644
--- a/src/views/EditorView.vue
+++ b/src/views/EditorView.vue
@@ -41,8 +41,7 @@ const params = useUrlSearchParams('history')
const showChrome = !('no-chrome' in params)
const createdInitialTab = tabCount() === 0
-const showInitialHome =
- route.path === '/' && !('test' in params) && (isTauri() || 'recent-files' in params)
+const showInitialHome = route.path === '/' && !('test' in params) && !route.meta.demo
const firstTab = createdInitialTab
? createTab(undefined, undefined, showInitialHome)
: (activeTab.value ?? createTab())