Skip to content

Commit 58fb719

Browse files
committed
fix(pr-comments): address review feedback for chat and migrations
1 parent 19986cf commit 58fb719

21 files changed

Lines changed: 73 additions & 16 deletions

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ next-env.d.ts
4848
# supabase
4949
supabase/*
5050
!supabase/migrations
51-
supabase/.temp/
52-
.temp/
5351

5452

5553
yarn.lock

app/components/Chat.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"use client";
1+
"use client";
22

33
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
44
import { RealtimeChannel, User } from "@supabase/supabase-js";
@@ -1400,12 +1400,15 @@ export default function Chat({ user }: { user: User }) {
14001400
? "G"
14011401
: activeOtherUser?.email?.[0]?.toUpperCase() ?? "?";
14021402

1403-
const allMediaAttachments = messages
1404-
.flatMap((m) => m.attachments || [])
1405-
.filter(
1406-
(a) => a?.mimetype?.startsWith("image/") || a?.mimetype?.startsWith("video/")
1407-
)
1408-
.reverse();
1403+
const allMediaAttachments = useMemo(() => {
1404+
return messages
1405+
.flatMap((m) => m.attachments || [])
1406+
.filter(
1407+
(a) =>
1408+
a?.mimetype?.startsWith("image/") || a?.mimetype?.startsWith("video/"),
1409+
)
1410+
.reverse();
1411+
}, [messages]);
14091412

14101413
const currentMediaIndex = mediaViewer ? allMediaAttachments.findIndex((a) => a.public_url === mediaViewer.url) : -1;
14111414
const hasPrevMedia = currentMediaIndex > 0;

app/components/chat/Conversations.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { User } from "@supabase/supabase-js";
1+
import { User } from "@supabase/supabase-js";
22
import { Conversation, TypingState } from "../Chat";
33

44
export default function Conversations({

app/components/chat/Messages.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"use client";
1+
"use client";
22

33
import { User } from "@supabase/supabase-js";
44
import ReactMarkdown from "react-markdown";

app/components/dashboard/Navbar.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ export default function DashboardLayout({
358358
role: string;
359359
children: React.ReactNode;
360360
}) {
361-
const [collapsed, setCollapsed] = useState(true);
361+
const [collapsed, setCollapsed] = useState(false);
362362
const [mobileHidden, setMobileHidden] = useState(false);
363363
const [isMobile, setIsMobile] = useState(false);
364364

@@ -397,8 +397,7 @@ export default function DashboardLayout({
397397
setCollapsed(true);
398398
setMobileHidden(true);
399399
} else {
400-
// default to collapsed on desktop too
401-
setCollapsed(true);
400+
setCollapsed(false);
402401
setMobileHidden(false);
403402
}
404403
};

app/lib/supabase/help/user.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { cache } from "react";
12
import { createClient } from "../server";
23

3-
export async function getUserWithProfile() {
4+
export const getUserWithProfile = cache(async () => {
45
const supabase = await createClient();
56

67
const {
@@ -16,4 +17,4 @@ export async function getUserWithProfile() {
1617
.single();
1718

1819
return { user, profile };
19-
}
20+
});

supabase/migrations/20260320234600_add_user_stats.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@ create table public.user_stats (
1313
daily_stats jsonb NOT NULL default '[]'::jsonb,
1414
last_fetched_at timestamp with time zone NOT NULL default now()
1515
);
16+
1617
alter table public.user_stats enable row level security;
18+
1719
/* ---- RLS Policy ----- */
1820
create policy "Users can insert their stats"
1921
on public.user_stats
2022
for insert
2123
with check (auth.uid() = user_id);
24+
2225
create policy "Users can update their stats"
2326
on public.user_stats
2427
for update
2528
using (auth.uid() = user_id);
29+
2630
create policy "Authenticated users can view stats"
2731
on public.user_stats
2832
for select

supabase/migrations/20260320234653_add_profiles.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@ create table public.profiles (
55
wakatime_api_key text default null unique,
66
created_at timestamp with time zone NOT NULL default now()
77
);
8+
89
/* ---- RLS Policies ----- */
910
alter table public.profiles enable row level security;
11+
1012
create policy "Users can view their own profile"
1113
on public.profiles
1214
for select
1315
using (auth.uid() = id);
16+
1417
create policy "Users can update their own profile"
1518
on public.profiles
1619
for update
1720
using (auth.uid() = id);
21+
1822
create policy "Users can insert their own profile"
1923
on public.profiles
2024
for insert
2125
with check (auth.uid() = id);
26+
2227
/* ---- Auto Create Profile on Signup Trigger ----- */
2328
create or replace function public.handle_new_user()
2429
returns trigger as $$
@@ -28,6 +33,7 @@ begin
2833
return new;
2934
end;
3035
$$ language plpgsql security definer;
36+
3137
create trigger on_auth_user_created
3238
after insert on auth.users
3339
for each row execute procedure public.handle_new_user();

supabase/migrations/20260320234714_add_leaderboards.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ create table public.leaderboards (
99
join_code text not null unique,
1010
created_at timestamptz NOT NULL default now()
1111
);
12+
1213
alter table public.leaderboards enable row level security;
14+
1315
/* ---- Leaderboards Members ----- */
1416
create table public.leaderboard_members (
1517
id uuid primary key default gen_random_uuid(),
@@ -19,7 +21,9 @@ create table public.leaderboard_members (
1921
joined_at timestamptz NOT NULL default now(),
2022
unique (leaderboard_id, user_id)
2123
);
24+
2225
alter table public.leaderboard_members enable row level security;
26+
2327
/* ---- Leaderboards Members View ----- */
2428
create view public.leaderboard_members_view as
2529
select
@@ -35,32 +39,39 @@ select
3539
from public.leaderboard_members lm
3640
join auth.users u on lm.user_id = u.id
3741
left join public.user_stats us on lm.user_id = us.user_id;
42+
3843
/* ---- RLS Policies ----- */
3944
create policy "Public leaderboards are viewable"
4045
on public.leaderboards
4146
for select
4247
using (is_public = true OR owner_id = auth.uid());
48+
4349
create policy "Users can create leaderboards"
4450
on public.leaderboards
4551
for insert
4652
with check (auth.uid() = owner_id);
53+
4754
create policy "Owner can update leaderboard"
4855
on public.leaderboards
4956
for update
5057
using (auth.uid() = owner_id);
58+
5159
/* ---- Members Policies ----- */
5260
create policy "Users can see their own membership"
5361
on public.leaderboard_members
5462
for select
5563
using (user_id = auth.uid());
64+
5665
create policy "Users can join leaderboard"
5766
on public.leaderboard_members
5867
for insert
5968
with check (auth.uid() = user_id);
69+
6070
create policy "Members can leave leaderboard"
6171
on public.leaderboard_members
6272
for delete
6373
using (user_id = auth.uid());
74+
6475
create policy "Owner can manage members"
6576
on public.leaderboard_members
6677
for delete

supabase/migrations/20260320234731_add_enforcement_checks.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
alter table public.leaderboards
22
add constraint leaderboards_name_length
33
check (length(trim(name)) between 3 and 50);
4+
45
alter table public.leaderboards
56
add constraint leaderboards_description_length
67
check (description is null or length(description) <= 150);
8+
79
alter table public.leaderboards
810
add constraint leaderboards_join_code_format
911
check (join_code ~ '^[A-Za-z0-9]{1,8}$');
12+
1013
create policy "Owner can delete leaderboard"
1114
on public.leaderboards
1215
for delete

0 commit comments

Comments
 (0)