Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat #1127 added selection to files #1555

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
DropListLink,
Empty,
EmptySearch,
FloatingActionBar,
PaginationWithLimit,
SearchQuery
} from '$lib/components';
Expand All @@ -30,7 +31,9 @@
TableCellText,
TableHeader,
TableRow,
TableRowLink
TableRowLink,
TableCellHeadCheck,
TableCellCheck
} from '$lib/elements/table';
import { toLocaleDate } from '$lib/helpers/date';
import {
Expand All @@ -56,6 +59,7 @@
let showDelete = false;
let showDropdown = [];
let selectedFile: Models.File = null;
let selected: string[] = [];

const projectId = $page.params.project;
const bucketId = $page.params.bucket;
Expand Down Expand Up @@ -143,6 +147,9 @@
{#if data.files.total}
<Table>
<TableHeader>
<TableCellHeadCheck
bind:selected
pageItemsIds={data.files.files.map((f) => f.$id)} />
<TableCellHead>Filename</TableCellHead>
<TableCellHead onlyDesktop width={140}>Type</TableCellHead>
<TableCellHead onlyDesktop width={100}>Size</TableCellHead>
Expand Down Expand Up @@ -186,6 +193,7 @@
{:else}
<TableRowLink
href={`${base}/project-${projectId}/storage/bucket-${bucketId}/file-${file.$id}`}>
<TableCellCheck bind:selectedIds={selected} id={file.$id} />
<TableCell title="Name">
<div class="u-flex u-gap-12 u-cross-center">
<Avatar size={32} src={getPreview(file.$id)} name={file.name} />
Expand Down Expand Up @@ -267,8 +275,50 @@
target="file"
on:click={() => wizard.start(Create)} />
{/if}

<FloatingActionBar show={selected.length > 0}>
<div class="u-flex u-cross-center u-main-space-between actions">
<div class="u-flex u-cross-center u-gap-8">
<span class="indicator body-text-2 u-bold">{selected.length}</span>
<p>
<span class="is-only-desktop">
file{selected.length > 1 ? 's' : ''}
</span>
selected
</p>
</div>

<div class="u-flex u-cross-center u-gap-8">
<Button text on:click={() => (selected = [])}>Cancel</Button>
<Button
secondary
on:click={() => {
showDelete = true;
selectedFile = null;
}}>
<p>Delete</p>
</Button>
</div>
</div>
</FloatingActionBar>
</Container>

{#if selectedFile}
<DeleteFile file={selectedFile} bind:showDelete on:deleted={fileDeleted} />
{/if}
<DeleteFile
singleFile={selectedFile}
bind:multipleFiles={selected}
{bucketId}
bind:showDelete
on:deleted={fileDeleted} />

<style lang="scss">
.actions {
.indicator {
border-radius: 0.25rem;
background: hsl(var(--color-information-100));
color: hsl(var(--color-neutral-0));

padding: 0rem 0.375rem;
display: inline-block;
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@
import type { Models } from '@appwrite.io/console';
import { createEventDispatcher } from 'svelte';

export let file: Models.File;
export let singleFile: Models.File;
export let multipleFiles: string[];
export let showDelete = false;
export let bucketId: string;

const dispatch = createEventDispatcher();

const deleteFile = async () => {
const promises = !singleFile
? multipleFiles.map((fileId) => sdk.forProject.storage.deleteFile(bucketId, fileId))
: [await sdk.forProject.storage.deleteFile(bucketId, singleFile.$id)];
showDelete = false;
try {
await sdk.forProject.storage.deleteFile(file.bucketId, file.$id);
showDelete = false;
dispatch('deleted', file);
await Promise.all(promises);
dispatch('deleted');
addNotification({
type: 'success',
message: `${file.name} has been deleted`
message: `${!singleFile ? multipleFiles.length : singleFile.name} has been deleted`
});
multipleFiles = [];
trackEvent(Submit.FileDelete);
} catch (error) {
addNotification({
Expand All @@ -39,7 +45,11 @@
icon="exclamation"
state="warning"
headerDivider={false}>
<p data-private>Are you sure you want to delete <b>{file.name}</b>?</p>
<p data-private>
Are you sure you want to delete <b
>{!singleFile ? `${multipleFiles.length} file${multipleFiles.length > 1 ? 's' : ''}` : singleFile.name}</b
>?
</p>
<svelte:fragment slot="footer">
<Button text on:click={() => (showDelete = false)}>Cancel</Button>
<Button secondary submit>Delete</Button>
Expand Down