diff --git a/.gitignore b/.gitignore index 79ac016..c85b641 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ supabase/.temp supabase/.branches _to_delete .env.deploy +tsconfig.tsbuildinfo diff --git a/Claude outputs/20261005140000_reviews_reactions_notifications.sql b/Claude outputs/20261005140000_reviews_reactions_notifications.sql deleted file mode 100644 index 715d4a9..0000000 --- a/Claude outputs/20261005140000_reviews_reactions_notifications.sql +++ /dev/null @@ -1,198 +0,0 @@ --- ════════════════════════════════════════════════════════════════════════════ --- AzuuCine — Avis par titre, réactions et notifications (5 octobre 2026) --- 1. Voir tous les avis sur un titre (amis / autres). --- 2. Réagir aux avis (emoji). --- 3. Notifications (cloche) : abonnements, demandes acceptées, réactions reçues. --- --- À coller dans Supabase → SQL Editor → Run. Idempotent (réexécutable sans risque). --- ════════════════════════════════════════════════════════════════════════════ - --- ── Tables ── -create table if not exists public.review_reactions ( - author_id uuid not null references auth.users(id) on delete cascade, -- auteur de l'avis - item_id text not null, - user_id uuid not null default auth.uid() references auth.users(id) on delete cascade, -- qui réagit - emoji text not null, - created_at timestamptz not null default now(), - primary key (author_id, item_id, user_id) -); -create index if not exists review_reactions_target_idx on public.review_reactions (author_id, item_id); -alter table public.review_reactions enable row level security; -alter table public.review_reactions force row level security; -revoke all on public.review_reactions from anon, authenticated; - -create table if not exists public.notifications ( - id bigint generated always as identity primary key, - user_id uuid not null references auth.users(id) on delete cascade, -- destinataire - kind text not null check (kind in ('follow_request','follow_accepted','new_follower','reaction')), - actor_id uuid references auth.users(id) on delete cascade, - item_id text, - emoji text, - created_at timestamptz not null default now(), - read_at timestamptz -); -create index if not exists notifications_user_idx on public.notifications (user_id, created_at desc); -alter table public.notifications enable row level security; -alter table public.notifications force row level security; -revoke all on public.notifications from anon, authenticated; - --- ── Création de notifications + bornage de l'historique ── -create or replace function public.azuu_notify(p_user uuid, p_kind text, p_actor uuid, p_item text default null, p_emoji text default null) -returns void language plpgsql security definer set search_path = '' as $$ -begin - if p_user is null or p_actor is null or p_user = p_actor then return; end if; - insert into public.notifications (user_id, kind, actor_id, item_id, emoji) - values (p_user, p_kind, p_actor, p_item, p_emoji); - delete from public.notifications - where user_id = p_user and id not in ( - select id from public.notifications where user_id = p_user order by created_at desc limit 300 - ); -end; -$$; - --- Abonnement / demande -> notifie le compte suivi ; demande acceptée -> notifie le demandeur -create or replace function public.azuu_follow_notify() -returns trigger language plpgsql security definer set search_path = '' as $$ -begin - if tg_op = 'INSERT' then - perform public.azuu_notify(new.following_id, - case when new.status = 'pending' then 'follow_request' else 'new_follower' end, new.follower_id); - elsif tg_op = 'UPDATE' and old.status = 'pending' and new.status = 'accepted' then - perform public.azuu_notify(new.follower_id, 'follow_accepted', new.following_id); - end if; - return null; -end; -$$; -drop trigger if exists follows_notify on public.follows; -create trigger follows_notify after insert or update on public.follows - for each row execute function public.azuu_follow_notify(); - --- Réaction reçue -> notifie l'auteur de l'avis -create or replace function public.azuu_reaction_notify() -returns trigger language plpgsql security definer set search_path = '' as $$ -begin - perform public.azuu_notify(new.author_id, 'reaction', new.user_id, new.item_id, new.emoji); - return null; -end; -$$; -drop trigger if exists reactions_notify on public.review_reactions; -create trigger reactions_notify after insert on public.review_reactions - for each row execute function public.azuu_reaction_notify(); - --- ── Réagir à un avis ── -create or replace function public.react_to_review(p_author uuid, p_item text, p_emoji text) -returns jsonb language plpgsql security definer set search_path = '' as $$ -begin - if auth.uid() is null then raise exception 'auth'; end if; - if p_author = auth.uid() then raise exception 'cannot react to your own review'; end if; - if p_emoji is null or p_emoji <> all (array['👍','❤️','🔥','😂','😮','😢']) then raise exception 'bad emoji'; end if; - if not public.can_view(p_author) or not exists ( - select 1 from public.items i join public.profiles pr on pr.id = i.user_id - where i.user_id = p_author and i.id = p_item and not i.deleted - and coalesce(i.data->>'notes','') <> '' and not pr.suspended - ) then - raise exception 'review not found'; - end if; - insert into public.review_reactions (author_id, item_id, user_id, emoji) - values (p_author, p_item, auth.uid(), p_emoji) - on conflict (author_id, item_id, user_id) do update set emoji = excluded.emoji, created_at = now(); - return jsonb_build_object('ok', true); -end; -$$; - -create or replace function public.unreact_review(p_author uuid, p_item text) -returns jsonb language plpgsql security definer set search_path = '' as $$ -begin - if auth.uid() is null then raise exception 'auth'; end if; - delete from public.review_reactions where author_id = p_author and item_id = p_item and user_id = auth.uid(); - return jsonb_build_object('ok', true); -end; -$$; - --- ── Tous les avis sur un titre (amis / autres) ── -create or replace function public.title_reviews(p_external_id text, p_offset integer default 0) -returns jsonb language plpgsql stable security definer set search_path = '' as $$ -declare me uuid := auth.uid(); res jsonb; -begin - if me is null or p_external_id !~ '^(tmdb:(movie|tv):[0-9]{1,10}|anilist:[0-9]{1,10})$' then - return jsonb_build_object('friends', '[]'::jsonb, 'others', '[]'::jsonb); - end if; - with revs as ( - select i.user_id, i.id as item_id, i.updated_at, - nullif(i.data->>'rating','')::numeric as rating, - i.data->>'notes' as notes, pr, - exists(select 1 from public.follows f where f.follower_id = me and f.following_id = i.user_id and f.status = 'accepted') as friend - from public.items i - join public.profiles pr on pr.id = i.user_id - where i.data->>'externalId' = p_external_id - and not i.deleted and coalesce(i.data->>'notes','') <> '' - and i.user_id <> me and not pr.suspended - and (not pr.is_private - or exists(select 1 from public.follows f where f.follower_id = me and f.following_id = i.user_id and f.status = 'accepted')) - ), - enriched as ( - select r.*, - (select coalesce(jsonb_object_agg(e.emoji, e.c), '{}'::jsonb) - from (select emoji, count(*) c from public.review_reactions rr - where rr.author_id = r.user_id and rr.item_id = r.item_id group by emoji) e) as reactions, - (select count(*) from public.review_reactions rr where rr.author_id = r.user_id and rr.item_id = r.item_id) as total, - (select emoji from public.review_reactions rr where rr.author_id = r.user_id and rr.item_id = r.item_id and rr.user_id = me) as mine - from revs r - ) - select jsonb_build_object( - 'friends', coalesce((select jsonb_agg(entry order by total desc, updated_at desc) from ( - select jsonb_build_object('user', public.profile_card(pr), 'user_id', user_id, 'item_id', item_id, - 'updated_at', updated_at, 'rating', rating, 'notes', notes, - 'reactions', reactions, 'total', total, 'mine', mine) entry, total, updated_at - from enriched where friend offset greatest(p_offset, 0) limit 40) f), '[]'::jsonb), - 'others', coalesce((select jsonb_agg(entry order by total desc, updated_at desc) from ( - select jsonb_build_object('user', public.profile_card(pr), 'user_id', user_id, 'item_id', item_id, - 'updated_at', updated_at, 'rating', rating, 'notes', notes, - 'reactions', reactions, 'total', total, 'mine', mine) entry, total, updated_at - from enriched where not friend offset greatest(p_offset, 0) limit 40) o), '[]'::jsonb) - ) into res; - return res; -end; -$$; - --- ── Notifications ── -create or replace function public.get_notifications(p_offset integer default 0) -returns jsonb language sql stable security definer set search_path = '' as $$ - select coalesce(jsonb_agg(x order by created_at desc), '[]'::jsonb) - from ( - select n.id, n.kind, n.created_at, n.read_at, n.emoji, n.item_id, - case when p.id is null then null else - jsonb_build_object('username', p.username, 'display_name', p.display_name, 'avatar_url', p.avatar_url) end as actor, - case when n.kind = 'reaction' - then (select it.data->>'title' from public.items it where it.user_id = n.user_id and it.id = n.item_id) end as title - from public.notifications n - left join public.profiles p on p.id = n.actor_id - where n.user_id = auth.uid() - order by n.created_at desc - offset greatest(p_offset, 0) limit 30 - ) x -$$; - -create or replace function public.notifications_unread() -returns integer language sql stable security definer set search_path = '' as $$ - select count(*)::int from public.notifications where user_id = auth.uid() and read_at is null -$$; - -create or replace function public.mark_notifications_read() -returns void language sql security definer set search_path = '' as $$ - update public.notifications set read_at = now() where user_id = auth.uid() and read_at is null -$$; - --- ── Droits (gate interne : auth.uid() / can_view) ── -revoke all on function public.react_to_review(uuid, text, text) from public, anon; -revoke all on function public.unreact_review(uuid, text) from public, anon; -revoke all on function public.title_reviews(text, integer) from public, anon; -revoke all on function public.get_notifications(integer) from public, anon; -revoke all on function public.notifications_unread() from public, anon; -revoke all on function public.mark_notifications_read() from public, anon; -grant execute on function public.react_to_review(uuid, text, text) to authenticated; -grant execute on function public.unreact_review(uuid, text) to authenticated; -grant execute on function public.title_reviews(text, integer) to authenticated; -grant execute on function public.get_notifications(integer) to authenticated; -grant execute on function public.notifications_unread() to authenticated; -grant execute on function public.mark_notifications_read() to authenticated; diff --git a/src/components/JournalView.tsx b/src/components/JournalView.tsx index fd954a3..d2fd647 100644 --- a/src/components/JournalView.tsx +++ b/src/components/JournalView.tsx @@ -34,7 +34,7 @@ function buildEntries(items: MediaItem[]): Entry[] { /** Onglet « Journal » du catalogue : chronologie groupée par mois. */ export default function JournalView({ onOpen }: { onOpen: (item: MediaItem) => void }) { - const { items, settings } = useMedia() + const { items } = useMedia() const entries = useMemo(() => buildEntries(items), [items]) const years = useMemo(() => [...new Set(entries.map((e) => e.date.slice(0, 4)))], [entries]) const [year, setYear] = useState('') diff --git a/src/components/MediaCard.tsx b/src/components/MediaCard.tsx index 2a363a5..741c7f4 100644 --- a/src/components/MediaCard.tsx +++ b/src/components/MediaCard.tsx @@ -41,7 +41,7 @@ function Progress({ item }: { item: MediaItem }) { * (elle se redessine quand même si la bibliothèque ou les réglages changent, via useMedia). */ export const MediaCard = memo(function MediaCard({ item, onOpen }: { item: MediaItem; onOpen: (item: MediaItem) => void }) { - const { settings, incrementEpisode } = useMedia() + const { incrementEpisode } = useMedia() // Revisionnage en cours : la progression montrée est celle du revisionnage const view = progressView(item) const canIncrement = diff --git a/src/components/Roulette.tsx b/src/components/Roulette.tsx index a8d1cf7..e9fba34 100644 --- a/src/components/Roulette.tsx +++ b/src/components/Roulette.tsx @@ -46,7 +46,7 @@ const shuffle = (arr: T[]) => { } export default function Roulette({ onClose, onOpen }: Props) { - const { items, settings, update, lists } = useMedia() + const { items, update, lists } = useMedia() const [filters, setFilters] = useState(loadFilters) const pool = useMemo(() => buildPool(items, filters), [items, filters]) const base = useMemo(() => sourcePool(items, filters.sources, filters.listIds), [items, filters.sources, filters.listIds]) diff --git a/src/components/social/FriendsFeed.tsx b/src/components/social/FriendsFeed.tsx index 6896bb9..06d4448 100644 --- a/src/components/social/FriendsFeed.tsx +++ b/src/components/social/FriendsFeed.tsx @@ -5,7 +5,6 @@ import { FEED_PAGE, getFeed, type FeedEntry } from '../../lib/cloud/social' import { useOnResume } from '../../lib/onResume' import { timeAgo } from '../../lib/timeAgo' import { formatRating } from '../../lib/utils' -import { useMedia } from '../../store' import Poster from '../Poster' import { LinkArrow, SectionTitle } from '../ui' import Avatar from './Avatar' @@ -30,7 +29,6 @@ const VERB = { finished: 'feed.finished', started: 'feed.started', rewatched: 'f /** Accueil : ce que regardent mes abonnements. */ export default function FriendsFeed() { const social = useSocial() - const { settings } = useMedia() const [entries, setEntries] = useState() const [more, setMore] = useState(false) const [loadingMore, setLoadingMore] = useState(false) diff --git a/src/components/social/ItemPeek.tsx b/src/components/social/ItemPeek.tsx index dfc7b22..5155894 100644 --- a/src/components/social/ItemPeek.tsx +++ b/src/components/social/ItemPeek.tsx @@ -27,7 +27,7 @@ export interface PeekOwner { /** Aperçu d'un titre de quelqu'un d'autre : sa note, son avis public, et ajout à ma liste « À voir ». */ export default function ItemPeek({ item, owner, onClose }: { item: MediaItem; owner?: PeekOwner; onClose: () => void }) { - const { items, add, settings } = useMedia() + const { items, add } = useMedia() const social = useSocial() const [busy, setBusy] = useState(false) const [added, setAdded] = useState(false) diff --git a/src/components/social/ProfileView.tsx b/src/components/social/ProfileView.tsx index d0f119f..aaf7d45 100644 --- a/src/components/social/ProfileView.tsx +++ b/src/components/social/ProfileView.tsx @@ -16,7 +16,6 @@ import Sheet from './Sheet' import { useSocial } from './SocialProvider' function PosterTile({ item, onOpen, caption }: { item: MediaItem; onOpen: () => void; caption?: string }) { - const { settings } = useMedia() return (