Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 93 additions & 6 deletions packages/app/src/components/dialog-select-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Entry = {
updated?: number
}

type DialogSelectFileMode = "all" | "files"
type DialogSelectFileMode = "all" | "files" | "archived"

const ENTRY_LIMIT = 5
const COMMON_COMMAND_IDS = [
Expand Down Expand Up @@ -99,11 +99,13 @@ const createSessionEntry = (

function createCommandEntries(props: {
filesOnly: () => boolean
archivedOnly: () => boolean
command: ReturnType<typeof useCommand>
language: ReturnType<typeof useLanguage>
}) {
const allowed = createMemo(() => {
if (props.filesOnly()) return []
if (props.archivedOnly()) return []
return props.command.options.filter(
(option) => !option.disabled && !option.id.startsWith("suggested.") && option.id !== "file.open",
)
Expand Down Expand Up @@ -174,10 +176,14 @@ function createSessionEntries(props: {
token: number
inflight: Promise<Entry[]> | undefined
cached: Entry[] | undefined
archivedInflight: Promise<Entry[]> | undefined
archivedCached: Entry[] | undefined
} = {
token: 0,
inflight: undefined,
cached: undefined,
archivedInflight: undefined,
archivedCached: undefined,
}

const sessions = (text: string) => {
Expand Down Expand Up @@ -250,7 +256,73 @@ function createSessionEntries(props: {
return state.inflight
}

return { sessions }
const archived = () => {
if (state.archivedCached) return state.archivedCached
if (state.archivedInflight) return state.archivedInflight

const dirs = props.workspaces()
if (dirs.length === 0) return [] as Entry[]

state.archivedInflight = Promise.all(
dirs.map((directory) => {
const description = props.label(directory)
return props.globalSDK.client.experimental.session
.list({
directory,
roots: true,
archived: true,
limit: 200,
})
.then((x) =>
(x.data ?? [])
.filter((s) => !!s?.id)
.filter((s) => !!s.time?.archived)
.map((s) => ({
id: s.id,
title: s.title ?? props.language.t("command.session.new"),
description,
directory,
archived: s.time?.archived,
updated: s.time?.updated,
})),
)
.catch(
() =>
[] as {
id: string
title: string
description: string
directory: string
archived?: number
updated?: number
}[],
)
}),
)
.then((results) => {
const seen = new Set<string>()
const category = props.language.t("command.category.session")
const next = results
.flat()
.filter((item) => {
const key = `${item.directory}:${item.id}`
if (seen.has(key)) return false
seen.add(key)
return true
})
.map((item) => createSessionEntry(item, category))
state.archivedCached = next
return next
})
.catch(() => [] as Entry[])
.finally(() => {
state.archivedInflight = undefined
})

return state.archivedInflight
}

return { sessions, archived }
}

export function DialogSelectFile(props: { mode?: DialogSelectFileMode; onOpenFile?: (path: string) => void }) {
Expand All @@ -264,12 +336,13 @@ export function DialogSelectFile(props: { mode?: DialogSelectFileMode; onOpenFil
const globalSDK = useGlobalSDK()
const globalSync = useGlobalSync()
const filesOnly = () => props.mode === "files"
const archivedOnly = () => props.mode === "archived"
const sessionKey = createMemo(() => `${params.dir}${params.id ? "/" + params.id : ""}`)
const tabs = createMemo(() => layout.tabs(sessionKey))
const view = createMemo(() => layout.view(sessionKey))
const state = { cleanup: undefined as (() => void) | void, committed: false }
const [grouped, setGrouped] = createSignal(false)
const commandEntries = createCommandEntries({ filesOnly, command, language })
const commandEntries = createCommandEntries({ filesOnly, archivedOnly, command, language })
const fileEntries = createFileEntries({ file, tabs, language })

const projectDirectory = createMemo(() => decode64(params.dir) ?? "")
Expand Down Expand Up @@ -301,12 +374,16 @@ export function DialogSelectFile(props: { mode?: DialogSelectFileMode; onOpenFil
return `${kind} : ${name || path}`
}

const { sessions } = createSessionEntries({ workspaces, label, globalSDK, language })
const sessions = createSessionEntries({ workspaces, label, globalSDK, language })

const items = async (text: string) => {
const query = text.trim()
setGrouped(query.length > 0)

if (archivedOnly()) {
return Promise.resolve(sessions.archived())
}

if (!query && filesOnly()) {
const loaded = file.tree.state("")?.loaded
const pending = loaded ? Promise.resolve() : file.tree.list("")
Expand All @@ -329,7 +406,10 @@ export function DialogSelectFile(props: { mode?: DialogSelectFileMode; onOpenFil
return files.map((path) => createFileEntry(path, category))
}

const [files, nextSessions] = await Promise.all([file.searchFiles(query), Promise.resolve(sessions(query))])
const [files, nextSessions] = await Promise.all([
file.searchFiles(query),
Promise.resolve(sessions.sessions(query)),
])
const category = language.t("palette.group.files")
const entries = files.map((path) => createFileEntry(path, category))
return [...commandEntries.list(), ...nextSessions, ...entries]
Expand Down Expand Up @@ -384,7 +464,9 @@ export function DialogSelectFile(props: { mode?: DialogSelectFileMode; onOpenFil
search={{
placeholder: filesOnly()
? language.t("session.header.searchFiles")
: language.t("palette.search.placeholder"),
: archivedOnly()
? language.t("palette.search.archived.placeholder")
: language.t("palette.search.placeholder"),
autofocus: true,
hideIcon: true,
}}
Expand Down Expand Up @@ -437,6 +519,11 @@ export function DialogSelectFile(props: { mode?: DialogSelectFileMode; onOpenFil
>
{item.title}
</span>
<Show when={item.archived}>
<span class="text-11-regular text-text-subtle px-1.5 py-0.5 bg-surface-base rounded">
{language.t("common.archived")}
</span>
</Show>
<Show when={item.description}>
<span
class="text-14-regular text-text-weak truncate"
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/i18n/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const dict = {
"command.session.previous.unseen": "الجلسة غير المقروءة السابقة",
"command.session.next.unseen": "الجلسة غير المقروءة التالية",
"command.session.archive": "أرشفة الجلسة",
"command.session.browseArchived": "تصفح الجلسات المؤرشفة",
"command.palette": "لوحة الأوامر",
"command.theme.cycle": "تغيير السمة",
"command.theme.set": "استخدام السمة: {{theme}}",
Expand Down Expand Up @@ -82,6 +83,7 @@ export const dict = {
"command.session.unshare": "إلغاء مشاركة الجلسة",
"command.session.unshare.description": "إيقاف مشاركة هذه الجلسة",
"palette.search.placeholder": "البحث في الملفات والأوامر والجلسات",
"palette.search.archived.placeholder": "البحث في الجلسات المؤرشفة",
"palette.empty": "لا توجد نتائج",
"palette.group.commands": "الأوامر",
"palette.group.files": "الملفات",
Expand Down Expand Up @@ -502,6 +504,8 @@ export const dict = {
"common.rename": "إعادة تسمية",
"common.reset": "إعادة تعيين",
"common.archive": "أرشفة",
"common.unarchive": "إلغاء الأرشفة",
"common.archived": "مؤرشفة",
"common.delete": "حذف",
"common.close": "إغلاق",
"common.edit": "تحرير",
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/i18n/br.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const dict = {
"command.session.previous.unseen": "Sessão não lida anterior",
"command.session.next.unseen": "Próxima sessão não lida",
"command.session.archive": "Arquivar sessão",
"command.session.browseArchived": "Navegar em sessões arquivadas",
"command.palette": "Paleta de comandos",
"command.theme.cycle": "Alternar tema",
"command.theme.set": "Usar tema: {{theme}}",
Expand Down Expand Up @@ -82,6 +83,7 @@ export const dict = {
"command.session.unshare": "Parar de compartilhar sessão",
"command.session.unshare.description": "Parar de compartilhar esta sessão",
"palette.search.placeholder": "Buscar arquivos, comandos e sessões",
"palette.search.archived.placeholder": "Pesquisar sessões arquivadas",
"palette.empty": "Nenhum resultado encontrado",
"palette.group.commands": "Comandos",
"palette.group.files": "Arquivos",
Expand Down Expand Up @@ -508,6 +510,8 @@ export const dict = {
"common.rename": "Renomear",
"common.reset": "Redefinir",
"common.archive": "Arquivar",
"common.unarchive": "Desarquivar",
"common.archived": "Arquivado",
"common.delete": "Excluir",
"common.close": "Fechar",
"common.edit": "Editar",
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/i18n/bs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const dict = {
"command.session.previous.unseen": "Prethodna nepročitana sesija",
"command.session.next.unseen": "Sljedeća nepročitana sesija",
"command.session.archive": "Arhiviraj sesiju",
"command.session.browseArchived": "Pregledaj arhivirane sesije",

"command.palette": "Paleta komandi",

Expand Down Expand Up @@ -89,6 +90,7 @@ export const dict = {
"command.session.unshare.description": "Zaustavi dijeljenje ove sesije",

"palette.search.placeholder": "Pretraži datoteke, komande i sesije",
"palette.search.archived.placeholder": "Pretraži arhivirane sesije",
"palette.empty": "Nema rezultata",
"palette.group.commands": "Komande",
"palette.group.files": "Datoteke",
Expand Down Expand Up @@ -568,6 +570,8 @@ export const dict = {
"common.rename": "Preimenuj",
"common.reset": "Resetuj",
"common.archive": "Arhiviraj",
"common.unarchive": "Vrati iz arhive",
"common.archived": "Arhivirano",
"common.delete": "Izbriši",
"common.close": "Zatvori",
"common.edit": "Uredi",
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/i18n/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const dict = {
"command.session.previous.unseen": "Forrige ulæste session",
"command.session.next.unseen": "Næste ulæste session",
"command.session.archive": "Arkivér session",
"command.session.browseArchived": "Gennemse arkiverede sessioner",

"command.palette": "Kommandopalette",

Expand Down Expand Up @@ -89,6 +90,7 @@ export const dict = {
"command.session.unshare.description": "Stop med at dele denne session",

"palette.search.placeholder": "Søg i filer, kommandoer og sessioner",
"palette.search.archived.placeholder": "Søg i arkiverede sessioner",
"palette.empty": "Ingen resultater fundet",
"palette.group.commands": "Kommandoer",
"palette.group.files": "Filer",
Expand Down Expand Up @@ -564,6 +566,8 @@ export const dict = {
"common.rename": "Omdøb",
"common.reset": "Nulstil",
"common.archive": "Arkivér",
"common.unarchive": "Annuller arkivering",
"common.archived": "Arkiveret",
"common.delete": "Slet",
"common.close": "Luk",
"common.edit": "Rediger",
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/i18n/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const dict = {
"command.session.previous.unseen": "Vorherige ungelesene Sitzung",
"command.session.next.unseen": "Nächste ungelesene Sitzung",
"command.session.archive": "Sitzung archivieren",
"command.session.browseArchived": "Archivierte Sitzungen durchsuchen",
"command.palette": "Befehlspalette",
"command.theme.cycle": "Thema wechseln",
"command.theme.set": "Thema verwenden: {{theme}}",
Expand Down Expand Up @@ -86,6 +87,7 @@ export const dict = {
"command.session.unshare": "Teilen der Sitzung aufheben",
"command.session.unshare.description": "Teilen dieser Sitzung beenden",
"palette.search.placeholder": "Dateien, Befehle und Sitzungen durchsuchen",
"palette.search.archived.placeholder": "Archivierte Sitzungen suchen",
"palette.empty": "Keine Ergebnisse gefunden",
"palette.group.commands": "Befehle",
"palette.group.files": "Dateien",
Expand Down Expand Up @@ -516,6 +518,8 @@ export const dict = {
"common.rename": "Umbenennen",
"common.reset": "Zurücksetzen",
"common.archive": "Archivieren",
"common.unarchive": "Entarchivieren",
"common.archived": "Archiviert",
"common.delete": "Löschen",
"common.close": "Schließen",
"common.edit": "Bearbeiten",
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const dict = {
"command.session.previous.unseen": "Previous unread session",
"command.session.next.unseen": "Next unread session",
"command.session.archive": "Archive session",
"command.session.browseArchived": "Browse archived sessions",

"command.palette": "Command palette",

Expand Down Expand Up @@ -89,6 +90,7 @@ export const dict = {
"command.session.unshare.description": "Stop sharing this session",

"palette.search.placeholder": "Search files, commands, and sessions",
"palette.search.archived.placeholder": "Search archived sessions",
"palette.empty": "No results found",
"palette.group.commands": "Commands",
"palette.group.files": "Files",
Expand Down Expand Up @@ -585,6 +587,8 @@ export const dict = {
"common.rename": "Rename",
"common.reset": "Reset",
"common.archive": "Archive",
"common.unarchive": "Unarchive",
"common.archived": "Archived",
"common.delete": "Delete",
"common.close": "Close",
"common.edit": "Edit",
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/i18n/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const dict = {
"command.session.previous.unseen": "Sesión no leída anterior",
"command.session.next.unseen": "Siguiente sesión no leída",
"command.session.archive": "Archivar sesión",
"command.session.browseArchived": "Ver sesiones archivadas",

"command.palette": "Paleta de comandos",

Expand Down Expand Up @@ -89,6 +90,7 @@ export const dict = {
"command.session.unshare.description": "Dejar de compartir esta sesión",

"palette.search.placeholder": "Buscar archivos, comandos y sesiones",
"palette.search.archived.placeholder": "Buscar sesiones archivadas",
"palette.empty": "No se encontraron resultados",
"palette.group.commands": "Comandos",
"palette.group.files": "Archivos",
Expand Down Expand Up @@ -571,6 +573,8 @@ export const dict = {
"common.rename": "Renombrar",
"common.reset": "Restablecer",
"common.archive": "Archivar",
"common.unarchive": "Desarchivar",
"common.archived": "Archivado",
"common.delete": "Eliminar",
"common.close": "Cerrar",
"common.edit": "Editar",
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/i18n/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const dict = {
"command.session.previous.unseen": "Session non lue précédente",
"command.session.next.unseen": "Session non lue suivante",
"command.session.archive": "Archiver la session",
"command.session.browseArchived": "Parcourir les sessions archivées",
"command.palette": "Palette de commandes",
"command.theme.cycle": "Changer de thème",
"command.theme.set": "Utiliser le thème : {{theme}}",
Expand Down Expand Up @@ -82,6 +83,7 @@ export const dict = {
"command.session.unshare": "Ne plus partager la session",
"command.session.unshare.description": "Arrêter de partager cette session",
"palette.search.placeholder": "Rechercher des fichiers, des commandes et des sessions",
"palette.search.archived.placeholder": "Rechercher dans les sessions archivées",
"palette.empty": "Aucun résultat trouvé",
"palette.group.commands": "Commandes",
"palette.group.files": "Fichiers",
Expand Down Expand Up @@ -512,6 +514,8 @@ export const dict = {
"common.rename": "Renommer",
"common.reset": "Réinitialiser",
"common.archive": "Archiver",
"common.unarchive": "Désarchiver",
"common.archived": "Archivé",
"common.delete": "Supprimer",
"common.close": "Fermer",
"common.edit": "Modifier",
Expand Down
Loading
Loading