Skip to content

Commit

Permalink
Merge branch 'dev' into sara/fix-warning
Browse files Browse the repository at this point in the history
  • Loading branch information
phillsatellite authored Sep 19, 2024
2 parents b509c11 + de29bf8 commit d7470f3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/lib/wasm/ConstellationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,20 @@ class ConstellationStore {
return failure(WarpError.CONSTELLATION_NOT_FOUND)
}

async canGoBack(): Promise<Result<WarpError, boolean>> {
const constellation = get(this.constellationWritable)
if (constellation) {
try {
let currentPath = (await constellation.current_directory()).path()
let root = (await constellation.root_directory()).path()
return success(root !== currentPath)
} catch (error) {
return failure(handleErrors(error))
}
}
return failure(WarpError.CONSTELLATION_NOT_FOUND)
}

/**
* Goes back to the previous directory in the constellation.
* @returns A Result containing either success or failure with a WarpError.
Expand All @@ -247,6 +261,11 @@ class ConstellationStore {
if (constellation) {
try {
let currentPath = (await constellation.current_directory()).path()
let root = (await constellation.root_directory()).path()
if (root === currentPath) {
log.error("Already at root. Cannot go back more")
return failure(WarpError.GENERAL_ERROR)
}
if (this.isValidFormat(currentPath)) {
await constellation.set_path("")
} else {
Expand Down
21 changes: 18 additions & 3 deletions src/routes/files/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
$: files = Store.state.files
let currentFolderIdStore = writable<string>("")
let rename: string | undefined
let canGoBack = writable(false)
async function openFolder(folder: FileInfo) {
let res = await ConstellationStoreInstance.openDirectory(folder.name)
Expand All @@ -66,6 +67,10 @@
updateCurrentDirectory()
}
)
;(await ConstellationStoreInstance.canGoBack()).fold(
_ => {},
res => canGoBack.set(res)
)
}
async function goBack() {
Expand All @@ -77,6 +82,10 @@
updateCurrentDirectory()
}
)
;(await ConstellationStoreInstance.canGoBack()).fold(
_ => {},
res => canGoBack.set(res)
)
}
async function createNewDirectory(folder: FileInfo) {
Expand Down Expand Up @@ -195,6 +204,10 @@
Store.updateFileOrder(Array.from(filesSet))
$files = Array.from(filesSet)
})
;(await ConstellationStoreInstance.canGoBack()).fold(
_ => {},
res => canGoBack.set(res)
)
}
function updateFilesFromFolder(folder: FileInfo): void {
if (folder.items && folder.items.length > 0) {
Expand Down Expand Up @@ -590,9 +603,11 @@
<ProgressButton appearance={Appearance.Alt} icon={Shape.ArrowsUpDown} />
</svelte:fragment>
</Topbar>
<div class="folder-back">
<Button hook="button-folder-back" small appearance={Appearance.Alt} class="folder-back" on:click={goBack}>{$_("controls.go_back")}</Button>
</div>
{#if $canGoBack}
<div class="folder-back">
<Button hook="button-folder-back" small appearance={Appearance.Alt} class="folder-back" on:click={goBack}>{$_("controls.go_back")}</Button>
</div>
{/if}
<div class="files">
<!-- svelte-ignore a11y-no-static-element-interactions -->
{#each $files as item}
Expand Down

0 comments on commit d7470f3

Please sign in to comment.