Skip to content

Commit fba2ec3

Browse files
committed
Add UserBadge
1 parent 0f1fce3 commit fba2ec3

File tree

3 files changed

+54
-39
lines changed

3 files changed

+54
-39
lines changed

src/components/UserBadge.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { User } from "~/lib/auth";
2+
3+
export const UserBadge = ({ user }: { user: User }) => {
4+
return (
5+
<div class="flex gap-4 bg-base-300 p-2 rounded-full">
6+
{user.image ? (
7+
<div class="avatar">
8+
<div class="w-12 rounded-full">
9+
<img src={user.image} />
10+
</div>
11+
</div>
12+
) : (
13+
<div class="avatar placeholder">
14+
<div class="bg-neutral text-neutral-content w-12 rounded-full">
15+
<span>{user.name.slice(0, 2)}</span>
16+
</div>
17+
</div>
18+
)}
19+
<div class="flex flex-col justify-center">
20+
<b>{user.name}</b>
21+
<span>{user.email}</span>
22+
</div>
23+
</div>
24+
);
25+
};

src/lib/auth.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const schemaUser = z.object({
4646
image: z.string().optional(),
4747
});
4848

49+
export interface User extends z.infer<typeof schemaUser> {}
50+
4951
export const getUser = async () => {
5052
"use server";
5153
const request = getWebRequest();

src/routes/cloud.tsx

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import SideBar from "~/components/cloud/SideBar";
2-
import { A, useLocation } from "@solidjs/router";
2+
import { A, createAsync, useLocation } from "@solidjs/router";
33
import type { RouteSectionProps } from "@solidjs/router";
44
import {
55
ChartPieIcon,
@@ -9,33 +9,16 @@ import {
99
Squares2X2Icon,
1010
} from "@deploy-cat/heroicons-solid/24/solid/esm";
1111
import { Breadcrumbs } from "~/components/Breadcrumbs";
12+
import { getUser } from "~/lib";
13+
import { UserBadge } from "~/components/UserBadge";
14+
import { Show } from "solid-js";
1215

13-
// const getUser = cache(async () => {
14-
// "use server";
15-
// const navigate = useNavigate();
16-
// // const supabase = useSupabase();
17-
// const {
18-
// data: { user },
19-
// } = await supabase.auth.getUser();
20-
// console.log(user);
21-
// if (!user) {
22-
// navigate("/login");
23-
// return;
24-
// }
25-
// return user;
26-
// }, "user");
27-
28-
// export const route = {
29-
// load: () => getUser(),
30-
// };
16+
export const route = {
17+
load: () => getUser(),
18+
};
3119

3220
export default (props: RouteSectionProps) => {
33-
// const user = createAsync(getUser);
34-
// const supabase = useSupabase();
35-
// const {
36-
// data: { user },
37-
// } = await supabase.auth.getUser();
38-
// console.log(user);
21+
const user = createAsync(() => getUser());
3922

4023
return (
4124
<main>
@@ -122,20 +105,25 @@ export default (props: RouteSectionProps) => {
122105
aria-label="close sidebar"
123106
class="drawer-overlay"
124107
></label>
125-
<ul class="menu p-4 w-80 min-h-full bg-base-200 text-base-content">
126-
<li>
127-
<A href="/cloud" end={true}>
128-
<ChartPieIcon class="flex-shrink-0 w-6 h-6 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white" />
129-
<span class="ml-3">Dashboard</span>
130-
</A>
131-
</li>
132-
<li>
133-
<A href="/cloud/apps">
134-
<Squares2X2Icon class="flex-shrink-0 w-6 h-6 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white" />
135-
<span class="flex-1 ml-3 whitespace-nowrap">Apps</span>
136-
</A>
137-
</li>
138-
</ul>
108+
<div class="menu flex flex-col justify-between p-4 w-80 min-h-full bg-base-200 text-base-content">
109+
<ul>
110+
<li>
111+
<A href="/cloud" end={true}>
112+
<ChartPieIcon class="flex-shrink-0 w-6 h-6 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white" />
113+
<span class="ml-3">Dashboard</span>
114+
</A>
115+
</li>
116+
<li>
117+
<A href="/cloud/apps">
118+
<Squares2X2Icon class="flex-shrink-0 w-6 h-6 text-gray-500 transition duration-75 dark:text-gray-400 group-hover:text-gray-900 dark:group-hover:text-white" />
119+
<span class="flex-1 ml-3 whitespace-nowrap">Apps</span>
120+
</A>
121+
</li>
122+
</ul>
123+
<Show when={user()}> {}
124+
<UserBadge user={user()} />
125+
</Show>
126+
</div>
139127
</div>
140128
</div>
141129
</main>

0 commit comments

Comments
 (0)