diff --git a/bun.lockb b/bun.lockb index de15b1a..ccdaab9 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/src/app/discover/page.tsx b/src/app/discover/page.tsx index 3625098..cc9efa1 100644 --- a/src/app/discover/page.tsx +++ b/src/app/discover/page.tsx @@ -5,7 +5,6 @@ import { getPublicThemes } from '@/lib/db/themes' export default async function DiscoverPage() { const themes = await getPublicThemes() - return (
diff --git a/src/components/Discover.tsx b/src/components/Discover.tsx index b343899..08ba1d6 100644 --- a/src/components/Discover.tsx +++ b/src/components/Discover.tsx @@ -10,17 +10,19 @@ export default function Discover({ themes }: { themes: SavedTheme[] }) { const [selectedTheme, setSelectedTheme] = useState(themes[0]) return (
-
+
-
+

Discover new themes

made by the community

+
+
-
+
{themes.map((theme) => ( { + setThemes((themes) => themes.filter((theme) => theme.id !== themeId)) + } + return (
{themes.map((theme) => ( - + ))}
diff --git a/src/components/ThemeCard.tsx b/src/components/ThemeCard.tsx index 2055790..e2d0a62 100644 --- a/src/components/ThemeCard.tsx +++ b/src/components/ThemeCard.tsx @@ -1,44 +1,53 @@ // src/components/ThemeCard.tsx 'use client' -import React, { useState } from 'react' +import React, { useState, useTransition } from 'react' import { SavedTheme } from '@/lib/types/colors' import { Button } from '@/components/ui/button' import { Switch } from '@/components/ui/switch' import { Edit, Download, Eye, Share2, Trash2, Loader2 } from 'lucide-react' import { - updateThemePublicity, + updateThemeType, deleteTheme, downloadThemeVSIX, } from '@/lib/db/themes' -import { useTransition } from 'react' +import { useTheme } from '@/contexts/ThemeContext' interface ThemeCardProps { theme: SavedTheme onPreview: (theme: SavedTheme) => void + onDelete: (themeId: number) => void } -const ThemeCard: React.FC = ({ theme, onPreview }) => { +const ThemeCard: React.FC = ({ + theme, + onPreview, + onDelete, +}) => { + const { updateSelectedThemeType, deleteSavedTheme } = useTheme() const [isPublic, setIsPublic] = useState(theme.public) - const [isPending, startTransition] = useTransition() + const [isDelPending, startDelTransition] = useTransition() + const [isDownPending, startDownTransition] = useTransition() + const [isPublPending, startPublTransition] = useTransition() const handleDelete = () => { if (window.confirm('Are you sure you want to delete this theme?')) { - startTransition(async () => { - await deleteTheme(theme.id) + startDelTransition(async () => { + await deleteSavedTheme(theme.id) + onDelete(theme.id) }) } } const handlePublicityToggle = (checked: boolean) => { - startTransition(async () => { - await updateThemePublicity(theme.id, checked) + startPublTransition(async () => { + await updateSelectedThemeType(theme.id, checked) setIsPublic(checked) }) } const handleDownload = () => { - startTransition(async () => { + startDownTransition(async () => { const vsixBuffer = await downloadThemeVSIX(theme.id) if (vsixBuffer) { const blob = new Blob([vsixBuffer], { @@ -60,13 +69,38 @@ const ThemeCard: React.FC = ({ theme, onPreview }) => {
onPreview(theme)} - aria-disabled={isPending} + aria-disabled={isDelPending || isDownPending || isPublPending} > +
+
+
+
+
+
+
+

= ({ theme, onPreview }) => { handlePublicityToggle(checked)} - disabled={isPending} + disabled={isPublPending} /> - {theme.public ? 'Public' : 'Private'} + {isPublic ? 'Public' : 'Private'}

-
- - - - - +
+
+ + + +
+
+ + +
diff --git a/src/components/ThemeCardPublic.tsx b/src/components/ThemeCardPublic.tsx index a0069bd..a6f7e33 100644 --- a/src/components/ThemeCardPublic.tsx +++ b/src/components/ThemeCardPublic.tsx @@ -6,6 +6,7 @@ import { SavedTheme } from '@/lib/types/colors' import { Download, Eye, Share2, Loader2 } from 'lucide-react' import { downloadThemeVSIX } from '@/lib/db/themes' import { useTransition } from 'react' +import { useUser } from '@clerk/nextjs' type ThemeCardPublicProps = { theme: SavedTheme @@ -16,6 +17,7 @@ const ThemeCardPublic: React.FC = ({ theme, onClick, }) => { + const { user } = useUser() const [isPending, startTransition] = useTransition() const handleDownload = () => { @@ -41,7 +43,6 @@ const ThemeCardPublic: React.FC = ({
onClick(theme)} >
= ({ > {theme.name} +

+ {theme.userName} +

-