feat: Archive UI Component

This commit is contained in:
Harsh Mahajan committed 2025-08-22 10:48:01 +05:30
1 parent 02127e9aec
commit fa1780e40c
4 files changed
+168 -7

No files matched your search

+157
View File
@@ -0,0 +1,157 @@
<script lang="ts">
import { Button } from '$lib/elements/forms';
import { CardContainer, DropList, GridItem1 } from '$lib/components';
import {
Badge,
Icon,
Typography,
Tag,
Accordion,
ActionMenu,
Popover
} from '@appwrite.io/pink-svelte';
import {
IconAndroid,
IconApple,
IconCode,
IconFlutter,
IconReact,
IconUnity,
IconInfo,
IconDotsHorizontal,
IconInboxIn,
IconSwitchHorizontal
} from '@appwrite.io/pink-icons-svelte';
import { getPlatformInfo } from '$lib/helpers/platform';
import type { Models } from '@appwrite.io/console';
import type { ComponentType } from 'svelte';
// prrops
interface Props {
projectsToArchive: Models.Project[];
}
let { projectsToArchive }: Props = $props();
// Track Read-only info droplist per archived project
let readOnlyInfoOpen = $state<Record<string, boolean>>({});
function filterPlatforms(platforms: { name: string; icon: string }[]) {
return platforms.filter(
(value, index, self) => index === self.findIndex((t) => t.name === value.name)
);
}
function getIconForPlatform(platform: string): ComponentType {
switch (platform) {
case 'code':
return IconCode;
case 'flutter':
return IconFlutter;
case 'apple':
return IconApple;
case 'android':
return IconAndroid;
case 'react-native':
return IconReact;
case 'unity':
return IconUnity;
default:
return IconCode;
}
}
</script>
{#if projectsToArchive.length > 0}
<div style="margin-top: 36px;">
<Accordion title="Archived projects" badge={`${projectsToArchive.length}`}>
<Typography.Text tag="p" size="s">
These projects have been archived and are read-only. You can view and migrate their
data.
</Typography.Text>
<div style="margin-top: 16px; margin-bottom: 36px;">
<CardContainer>
{#each projectsToArchive as project}
{@const platforms = filterPlatforms(
project.platforms.map((platform) => getPlatformInfo(platform.type))
)}
<GridItem1>
<svelte:fragment slot="eyebrow">
{project?.platforms?.length ? project?.platforms?.length : 'No'} apps
</svelte:fragment>
<svelte:fragment slot="title">{project.name}</svelte:fragment>
<svelte:fragment slot="status">
<span style="display: flex; align-items: center; gap: 8px;">
<DropList
bind:show={readOnlyInfoOpen[project.$id]}
placement="bottom-start"
noArrow>
<Tag
size="s"
style="white-space: nowrap; max-width: none;"
on:click={(e) => {
e.preventDefault();
e.stopPropagation();
readOnlyInfoOpen = {
...readOnlyInfoOpen,
[project.$id]: !readOnlyInfoOpen[project.$id]
};
}}>
<Icon icon={IconInfo} size="s" />
<span>Read only</span>
</Tag>
<svelte:fragment slot="list">
<li
class="drop-list-item u-width-250"
style="padding: var(--space-5, 12px) var(--space-6, 16px)">
<span class="u-block u-mb-8">
Archived projects are read-only. You can view
and migrate their data, but they no longer
accept edits or requests.
</span>
</li>
</svelte:fragment>
</DropList>
<Popover let:toggle padding="none" placement="bottom-end">
<Button
text
icon
size="s"
ariaLabel="more options"
on:click={(e) => {
e.preventDefault();
e.stopPropagation();
toggle(e);
}}>
<Icon icon={IconDotsHorizontal} size="s" />
</Button>
<ActionMenu.Root slot="tooltip">
<ActionMenu.Item.Button leadingIcon={IconInboxIn}
>Unarchive project</ActionMenu.Item.Button>
<ActionMenu.Item.Button
leadingIcon={IconSwitchHorizontal}
>Migrate project</ActionMenu.Item.Button>
</ActionMenu.Root>
</Popover>
</span>
</svelte:fragment>
{#each platforms.slice(0, 2) as platform}
{@const icon = getIconForPlatform(platform.icon)}
<Badge
variant="secondary"
content={platform.name}
style="width: max-content;">
<Icon {icon} size="s" slot="start" />
</Badge>
{/each}
</GridItem1>
{/each}
<svelte:fragment slot="empty">
<p>No archived projects</p>
</svelte:fragment>
</CardContainer>
</div>
</Accordion>
</div>
{/if}
+1 -1
View File
@@ -1,6 +1,6 @@
<script lang="ts">
import { Card, Layout, Typography } from '@appwrite.io/pink-svelte';
export let href: string;
export let href: string = null;
</script>
<Card.Link class="card" {href}>
+1
View File
@@ -1,3 +1,4 @@
export { default as ArchiveProject } from './archiveProject.svelte';
export { default as Arrow } from './arrow.svelte';
export { default as Modal } from './modal.svelte';
export { default as Pagination } from './pagination.svelte';
@@ -8,6 +8,7 @@
import { page } from '$app/state';
import { registerCommands } from '$lib/commandCenter';
import {
// ArchiveProject,
CardContainer,
DropList,
DropListItem,
@@ -270,6 +271,14 @@
<p>Create a new project</p>
</svelte:fragment>
</CardContainer>
<PaginationWithLimit
name="Projects"
limit={data.limit}
offset={data.offset}
total={data.projects.total} />
<!-- TODO: uncomment this when we have a way to archive projects -->
<!-- <ArchiveProject {projectsToArchive} /> -->
{:else}
<Empty
single
@@ -278,12 +287,6 @@
target="project"
href="https://appwrite.io/docs/quick-starts"></Empty>
{/if}
<PaginationWithLimit
name="Projects"
limit={data.limit}
offset={data.offset}
total={data.projects.total} />
</Container>
<CreateOrganization bind:show={addOrganization} />