diff --git a/fake-snippets-api/routes/api/snippets/create.ts b/fake-snippets-api/routes/api/snippets/create.ts index 8ffa2f0..b95b1eb 100644 --- a/fake-snippets-api/routes/api/snippets/create.ts +++ b/fake-snippets-api/routes/api/snippets/create.ts @@ -1,6 +1,6 @@ import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec" import { z } from "zod" -import { snippetSchema } from "fake-snippets-api/lib/db/schema" +import { Snippet, snippetSchema } from "fake-snippets-api/lib/db/schema" export default withRouteSpec({ methods: ["POST"], @@ -25,7 +25,7 @@ export default withRouteSpec({ if (!unscoped_name) { unscoped_name = `untitled-${snippet_type}-${ctx.db.idCounter + 1}` } - const newSnippet = { + const newSnippet: Snippet = { snippet_id: `snippet_${ctx.db.idCounter + 1}`, name: `${ctx.auth.github_username}/${unscoped_name}`, unscoped_name, diff --git a/fake-snippets-api/routes/api/snippets/list.ts b/fake-snippets-api/routes/api/snippets/list.ts index 40f5cef..66707d7 100644 --- a/fake-snippets-api/routes/api/snippets/list.ts +++ b/fake-snippets-api/routes/api/snippets/list.ts @@ -17,6 +17,7 @@ export default withRouteSpec({ })(async (req, ctx) => { const { owner_name, unscoped_name } = req.commonParams + console.log(ctx.db.snippets) const snippets = ctx.db .getSnippetsByAuthor(owner_name) .filter((s) => !unscoped_name || s.unscoped_name === unscoped_name) diff --git a/src/App.tsx b/src/App.tsx index a5c2773..afc1486 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -10,13 +10,13 @@ import { ViewSnippetPage } from "./pages/view-snippet" import { LandingPage } from "./pages/landing" import { Route, Switch } from "wouter" import { AiPage } from "./pages/ai" -import { ProfilePage } from "./pages/profile" import { NewestPage } from "./pages/newest" import { SettingsPage } from "./pages/settings" import { SearchPage } from "./pages/search" import { QuickstartPage } from "./pages/quickstart" import { Toaster } from "@/components/ui/toaster" import AuthenticatePage from "./pages/authorize" +import { UserProfilePage } from "./pages/user-profile" function App() { return ( @@ -27,11 +27,11 @@ function App() { - + diff --git a/src/components/HeaderLogin.tsx b/src/components/HeaderLogin.tsx index 2cc6d62..f441ead 100644 --- a/src/components/HeaderLogin.tsx +++ b/src/components/HeaderLogin.tsx @@ -14,7 +14,9 @@ import { useGlobalStore } from "@/hooks/use-global-store" import { useAccountBalance } from "@/hooks/use-account-balance" import { useIsUsingFakeApi } from "@/hooks/use-is-using-fake-api" -export const HeaderLogin: React.FC = () => { +interface HeaderLoginProps {} + +export const HeaderLogin: React.FC = () => { const [, setLocation] = useLocation() const session = useGlobalStore((s) => s.session) const isLoggedIn = Boolean(session) @@ -32,10 +34,10 @@ export const HeaderLogin: React.FC = () => { window.location.href = `${snippetsBaseApiUrl}/internal/oauth/github/authorize?next=${window.location.origin}/authorize` } else { setSession({ - account_id: "account_1234", - github_username: "shadcn", + account_id: "account-1234", + github_username: "testuser", token: "1234", - session_id: "session_1234", + session_id: "session-1234", }) } }} @@ -51,10 +53,10 @@ export const HeaderLogin: React.FC = () => { window.location.href = `${snippetsBaseApiUrl}/internal/oauth/github/authorize?next=${window.location.origin}/authorize` } else { setSession({ - account_id: "account_1234", - github_username: "shadcn", + account_id: "account-1234", + github_username: "testuser", token: "1234", - session_id: "session_1234", + session_id: "session-1234", }) } }} @@ -84,6 +86,11 @@ export const HeaderLogin: React.FC = () => { {accountBalance?.monthly_ai_budget_used_usd.toFixed(2) ?? "0.00"} / $5.00 + setLocation(`/${session?.github_username}`)} + > + My Profile + setLocation("/dashboard")}> Dashboard diff --git a/src/pages/profile.tsx b/src/pages/profile.tsx deleted file mode 100644 index 43806eb..0000000 --- a/src/pages/profile.tsx +++ /dev/null @@ -1,14 +0,0 @@ -import Footer from "@/components/Footer" -import Header from "@/components/Header" - -export const ProfilePage = () => { - return ( -
-
-
-

Viewing snippet

-
-
-
- ) -} diff --git a/src/pages/user-profile.tsx b/src/pages/user-profile.tsx new file mode 100644 index 0000000..c568323 --- /dev/null +++ b/src/pages/user-profile.tsx @@ -0,0 +1,68 @@ +import React from "react" +import { useParams } from "wouter" +import { useQuery } from "react-query" +import { useAxios } from "@/hooks/use-axios" +import Header from "@/components/Header" +import Footer from "@/components/Footer" +import { Snippet } from "fake-snippets-api/lib/db/schema" +import { Link } from "wouter" +import { Button } from "@/components/ui/button" +import { GitHubLogoIcon } from "@radix-ui/react-icons" + +export const UserProfilePage = () => { + const { username } = useParams() + const axios = useAxios() + + const { data: userSnippets, isLoading } = useQuery( + ["userSnippets", username], + async () => { + const response = await axios.get(`/snippets/list?owner_name=${username}`) + return response.data.snippets + }, + ) + + return ( +
+
+
+

{username}'s Profile

+ +

Snippets

+ {isLoading ? ( +
Loading snippets...
+ ) : ( +
+ {userSnippets?.map((snippet) => ( + +
+

+ {snippet.unscoped_name} +

+

+ Created: {new Date(snippet.created_at).toLocaleString()} +

+
+ + ))} +
+ )} +
+
+ ) +}