Skip to content

Commit

Permalink
wip: use a sidebar_item_action
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Nov 27, 2024
1 parent 35478e5 commit 5f3c50f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/src/lib/components/SidebarItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
import { page } from '$app/stores';
import { Button } from './ui/button';
import { cn } from '@/utils/ui.utils';
import SidebarItemActions from './SidebarItemActions.svelte';
export let item: SidebarItemModel;
const [send, receive] = crossfade({
duration: 250,
easing: cubicInOut
});
const [send, receive] = crossfade({ duration: 250, easing: cubicInOut });
$: href = item.completed
? `/audiocast/${item.sessionId}`
Expand Down Expand Up @@ -52,7 +50,9 @@
{item.title}
</div>

<div class="text-[10px] px-2 hidden group-hover:block absolute bottom-0 right-0 text-sky-200">
<div class="text-[10px] px-2 hidden group-hover:block absolute bottom-0 left-0 text-sky-200">
{item.category}
</div>

<SidebarItemActions sessionId={item.sessionId} />
</Button>
51 changes: 51 additions & 0 deletions app/src/lib/components/SidebarItemActions.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script lang="ts">
import * as AlertDialog from './ui/alert-dialog';
import { Trash } from 'lucide-svelte';
import { goto } from '$app/navigation';
import { SESSION_KEY } from '@/stores/sessionContext.svelte';
import { env } from '@env';
export let sessionId: string;
let openDialog = false;
async function deleteSession() {
localStorage.removeItem(`${SESSION_KEY}_${sessionId}`);
void fetch(`${env.API_BASE_URL}/delete-session/${sessionId}`, {
method: 'DELETE'
}).catch(() => {});
openDialog = false;
return goto('/', { invalidateAll: true, replaceState: true });
}
</script>

<div
class="absolute rounded-r-md hidden group/action bg-gray-800/80 hover:bg-gray-800 h-full group-hover:flex items-center right-0 p-2"
>
<button
class="text-gray-400 group-hover/action:text-gray-100"
on:click={() => (openDialog = true)}
>
<Trash class="w-4 h-4 inline" />
</button>
</div>

<AlertDialog.Root bind:open={openDialog}>
<AlertDialog.Trigger>Open</AlertDialog.Trigger>
<AlertDialog.Content class="border-neutral-800">
<AlertDialog.Header>
<AlertDialog.Title>Delete audiocast?</AlertDialog.Title>
<AlertDialog.Description>
This action cannot be undone. This will permanently delete your audiocast data.
</AlertDialog.Description>
</AlertDialog.Header>
<AlertDialog.Footer>
<AlertDialog.Cancel on:click={() => (openDialog = false)}>Cancel</AlertDialog.Cancel>
<AlertDialog.Action class="bg-red-500 text-red-100 hover:bg-red-600" on:click={deleteSession}
>Continue</AlertDialog.Action
>
</AlertDialog.Footer>
</AlertDialog.Content>
</AlertDialog.Root>

0 comments on commit 5f3c50f

Please sign in to comment.