Skip to content

Commit 4633df0

Browse files
commented ai chat box and added snippetcard to show snippets on /dashboard (#963)
* commented ai chat box and added snippetcard to show snippets * fixed text size * added skeleton while loading packages
1 parent b115e36 commit 4633df0

File tree

1 file changed

+54
-18
lines changed

1 file changed

+54
-18
lines changed

src/pages/dashboard.tsx

+54-18
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@ import { useGlobalStore } from "@/hooks/use-global-store"
1212
import { PrefetchPageLink } from "@/components/PrefetchPageLink"
1313
import { SnippetList } from "@/components/SnippetList"
1414
import { Helmet } from "react-helmet-async"
15+
import { SnippetCard } from "@/components/SnippetCard"
16+
import { useSnippetsBaseApiUrl } from "@/hooks/use-snippets-base-api-url"
17+
import { useConfirmDeletePackageDialog } from "@/components/dialogs/confirm-delete-package-dialog"
1518

1619
export const DashboardPage = () => {
1720
const axios = useAxios()
1821

1922
const currentUser = useGlobalStore((s) => s.session?.github_username)
2023
const [showAllTrending, setShowAllTrending] = useState(false)
2124
const [showAllLatest, setShowAllLatest] = useState(false)
25+
const [snippetToDelete, setSnippetToDelete] = useState<Snippet | null>(null)
26+
const { Dialog: DeleteDialog, openDialog: openDeleteDialog } =
27+
useConfirmDeletePackageDialog()
2228

2329
const {
2430
data: mySnippets,
@@ -49,6 +55,13 @@ export const DashboardPage = () => {
4955
},
5056
)
5157

58+
const baseUrl = useSnippetsBaseApiUrl()
59+
60+
const handleDeleteClick = (e: React.MouseEvent, snippet: Snippet) => {
61+
e.preventDefault() // Prevent navigation
62+
setSnippetToDelete(snippet)
63+
openDeleteDialog()
64+
}
5265
return (
5366
<div>
5467
<Helmet>
@@ -86,30 +99,47 @@ export const DashboardPage = () => {
8699
</div>
87100
</div>
88101
</div>
89-
<CreateNewSnippetWithAiHero />
102+
{/* <CreateNewSnippetWithAiHero /> */}
90103
<h2 className="text-sm font-bold mb-2 text-gray-700 border-b border-gray-200">
91104
Your Recent Snippets
92105
</h2>
93-
{isLoading && <div>Loading...</div>}
94-
{mySnippets && (
95-
<ul className="space-y-1">
106+
{isLoading && (
107+
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
108+
{[...Array(6)].map((_, i) => (
109+
<div key={i} className="border p-4 rounded-md animate-pulse">
110+
<div className="flex items-start gap-4">
111+
<div className="h-16 w-16 flex-shrink-0 rounded-md bg-slate-200"></div>
112+
<div className="flex-1">
113+
<div className="h-5 bg-slate-200 rounded w-3/4 mb-2"></div>
114+
<div className="h-4 bg-slate-200 rounded w-1/2 mb-2"></div>
115+
<div className="flex gap-2">
116+
<div className="h-3 bg-slate-200 rounded w-16"></div>
117+
<div className="h-3 bg-slate-200 rounded w-16"></div>
118+
</div>
119+
</div>
120+
</div>
121+
</div>
122+
))}
123+
</div>
124+
)}
125+
{mySnippets && mySnippets.length > 0 ? (
126+
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
96127
{mySnippets.slice(0, 10).map((snippet) => (
97-
<li
128+
<SnippetCard
98129
key={snippet.snippet_id}
99-
className="flex items-center justify-between"
100-
>
101-
<Link
102-
href={`/${snippet.owner_name}/${snippet.unscoped_name}`}
103-
className="text-blue-600 hover:underline text-sm"
104-
>
105-
{snippet.unscoped_name}
106-
</Link>
107-
<span className="text-xs text-gray-500">
108-
{new Date(snippet.created_at).toLocaleDateString()}
109-
</span>
110-
</li>
130+
snippet={snippet}
131+
baseUrl={baseUrl}
132+
isCurrentUserSnippet={snippet.owner_name === currentUser}
133+
onDeleteClick={handleDeleteClick}
134+
/>
111135
))}
112-
</ul>
136+
</div>
137+
) : (
138+
!isLoading && (
139+
<span className="font-medium text-sm text-gray-500">
140+
No snippets found
141+
</span>
142+
)
113143
)}
114144
{mySnippets && mySnippets.length > 10 && (
115145
<Link
@@ -136,6 +166,12 @@ export const DashboardPage = () => {
136166
/>
137167
</div>
138168
</div>
169+
{snippetToDelete && (
170+
<DeleteDialog
171+
packageId={snippetToDelete.snippet_id}
172+
packageName={snippetToDelete.unscoped_name}
173+
/>
174+
)}
139175
</div>
140176
</div>
141177
<Footer />

0 commit comments

Comments
 (0)