PageSourceSearch

https://www.aceplay.app/assets/Notifications-Hez2fQoL.js

js aceplay.app collected 2026-10-02 15:53:23 UTC 7,631 bytes, 1 lines download raw bytes

1import{n as O,cI as U,u as Z,aE as z,bi as G,a as o,e as J,fR as V,j3 as X,af as x,lx as w,eZ as ee,b as e,d5 as te,d2 as se,bc as ae,c$ as ie,hC as ne,K as re,bC as le,ly as oe,lz as ce,lA as de,lB as ue,lC as me,jY as fe,L as xe,d8 as he,lD as pe,lE as ye,db as ge}from"./index-Bo1fPnLQ.js";import{u as ve}from"./use-swipe-back-UFlEqoCZ.js";const N=50,Ne=["today","yesterday","thisWeek","earlier"],je={today:"common:label.today",yesterday:"common:label.yesterday",thisWeek:"common:label.thisWeek",earlier:"common:label.earlier"};function be(i){const h=new Date,p=new Date(h.getFullYear(),h.getMonth(),h.getDate()),y=new Date(p);y.setDate(y.getDate()-1);const n=new Date(p);n.setDate(n.getDate()-7);const c={today:[],yesterday:[],thisWeek:[],earlier:[]};for(const a of i){const u=new Date(a.created_at);u>=p?c.today.push(a):u>=y?c.yesterday.push(a):u>=n?c.thisWeek.push(a):c.earlier.push(a)}const g=[];for(const a of Ne)c[a].length>0&&g.push({labelKey:je[a],items:c[a]});return g}function _e(){const{t:i,i18n:h}=O("notifications"),p=U(h.language),y=Z(),n=z(),c=G("/home"),g=o.useRef(null);ve(c,g);const{user:a,profile:u}=J(),{activeProfile:K,switchToPlayer:E}=V(),{toast:j}=ge(),{lightImpact:k,mediumImpact:R,selectionChanged:A}=he(),M=X(),[l,d]=o.useState([]),[Q,_]=o.useState(!0),[T,S]=o.useState(!1),[b,q]=o.useState(!1),[C,D]=o.useState(!0);o.useEffect(()=>{if(!a)return;v();const s=x.channel("notifications-page-realtime").on("postgres_changes",{event:"INSERT",schema:"public",table:"notifications",filter:`user_id=eq.${a.id}`},r=>{const m=w(r.new);d(f=>[m,...f])}).subscribe(),t=ee(()=>{v()});return()=>{t(),x.removeChannel(s)}},[a]);const v=async()=>{const{data:s,error:t}=await x.from("notifications").select("*").eq("user_id",a.id).order("created_at",{ascending:!1}).limit(N);S(!!t&&l.length===0),s&&(d(s.map(w)),D(s.length===N)),_(!1)},B=async()=>{if(!C||b||l.length===0)return;q(!0);const s=l[l.length-1].created_at,{data:t}=await x.from("notifications").select("*").eq("user_id",a.id).lt("created_at",s).order("created_at",{ascending:!1}).limit(N);t&&(d(r=>[...r,...t.map(w)]),D(t.length===N)),q(!1)},I=async s=>{const t=l;d(m=>m.map(f=>f.id===s?{...f,read:!0}:f));const{error:r}=await x.from("notifications").update({read:!0}).eq("id",s);r&&(d(t),j({title:i("error.markReadFailed"),variant:"destructive"}))},F=async()=>{A();const s=l;d(r=>r.map(m=>({...m,read:!0})));const{error:t}=await x.from("notifications").update({read:!0}).eq("user_id",a.id).eq("read",!1);t&&(d(s),j({title:i("error.markAllReadFailed"),variant:"destructive"}))},L=s=>{k(),I(s.id);const t=s.data,r=pe(s.type,t);r&&(t.match_id&&(n.invalidateQueries({queryKey:["match-detail",t.match_id]}),n.invalidateQueries({queryKey:["match-score",t.match_id]})),t.tournament_id&&(n.invalidateQueries({queryKey:["tournament",t.tournament_id]}),n.invalidateQueries({queryKey:["tournament-players",t.tournament_id]}),n.invalidateQueries({queryKey:["tournament-rounds",t.tournament_id]}),n.invalidateQueries({queryKey:["tournament-matches",t.tournament_id]}),n.invalidateQueries({queryKey:["tournament-rating-changes",t.tournament_id]}),n.invalidateQueries({queryKey:["tournament-teams",t.tournament_id]}),n.invalidateQueries({queryKey:["tournament-partner-invites",t.tournament_id]})),n.invalidateQueries({queryKey:["matches"]}),n.invalidateQueries({queryKey:["community-feed"]}),ye(r,K.type==="community")&&E(),y(r))},W=async s=>{R();const t=l;d(m=>m.filter(f=>f.id!==s));const{error:r}=await x.from("notifications").delete().eq("id",s);r&&(d(t),j({title:i("error.deleteFailed"),variant:"destructive"}))},P=l.filter(s=>!s.read).length,$=o.useMemo(()=>be(l),[l]),[Y,H]=o.useState(!1);return o.useEffect(()=>{const s=()=>H(window.scrollY>8);return window.addEventListener("scroll",s,{passive:!0}),()=>window.removeEventListener("scroll",s)},[]),e.jsx(te,{onRefresh:v,children:e.jsxs("div",{ref:g,className:`flex flex-col min-h-screen bg-background mx-auto w-full ${M}`,children:[e.jsxs(se,{className:`transition-all duration-200 ${Y?"bg-background/70 backdrop-blur-xl saturate-150":"bg-background"}`,children:[e.jsx("div",{className:"pt-safe"}),e.jsxs("div",{className:"px-4 py-3 flex items-center",children:[e.jsx("button",{onClick:c,className:"h-10 w-10 shrink-0 flex items-center justify-center active:scale-95 transition-transform",children:e.jsx(ae,{className:"h-5 w-5"})}),e.jsx("h1",{className:"text-[17px] font-semibold flex-1 text-center",children:i("title")}),P>0?e.jsx("button",{onClick:F,className:"text-[15px] text-primary font-medium active:opacity-60 transition-opacity shrink-0",children:i("markAllRead")}
1):e.jsx("div",{className:"w-10 shrink-0"})]})]}),e.jsxs("div",{className:"flex-1 px-4",style:{WebkitOverflowScrolling:"touch"},children:[Q?e.jsx("div",{className:"space-y-3 pt-2",children:[1,2,3].map(s=>e.jsx(ie,{className:"h-20 w-full rounded-xl"},s))}):T&&l.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center text-center py-20",children:[e.jsx("div",{className:"h-16 w-16 rounded-2xl bg-muted flex items-center justify-center mb-4",children:e.jsx(ne,{className:"h-8 w-8 text-muted-foreground"})}),e.jsx("h2",{className:"text-lg font-semibold mb-1",children:i("common:offline.connectionError")}),e.jsxs(re,{className:"mt-4",onClick:()=>{_(!0),S(!1),v()},children:[e.jsx(le,{className:"mr-2 h-4 w-4"}),i("common:action.retry")]})]}):l.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center text-center py-20",children:[e.jsx("div",{className:"h-16 w-16 rounded-2xl bg-muted flex items-center justify-center mb-4",children:e.jsx(oe,{className:"h-8 w-8 text-muted-foreground"})}),e.jsx("h2",{className:"text-lg font-semibold mb-1",children:i("empty.title")}),e.jsx("p",{className:"text-[15px] text-muted-foreground max-w-[250px]",children:i("empty.description")})]}):e.jsxs("div",{className:"space-y-5 pb-8",children:[$.map(s=>e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground px-1 pb-1.5 pt-2",children:i(s.labelKey)}),e.jsx("div",{className:"rounded-xl bg-card overflow-hidden",children:s.items.map((t,r)=>e.jsx(ce,{onDelete:()=>W(t.id),children:e.jsxs("div",{className:"bg-card",children:[e.jsxs("button",{onClick:()=>L(t),className:"w-full text-left px-4 py-3 flex items-center gap-3 active:bg-muted/50 transition-colors duration-100",children:[e.jsx("div",{className:"w-[6px] shrink-0 flex justify-center",children:!t.read&&e.jsx("span",{className:"h-[6px] w-[6px] rounded-full bg-primary"})}),e.jsx("div",{className:`h-[29px] w-[29px] rounded-[7px] flex items-center justify-center shrink-0 ${de(t.type,t.read)}`,children:e.jsx("div",{className:"[&_svg]:h-[17px] [&_svg]:w-[17px]",children:ue(t.type)})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:`text-[15px] leading-tight ${t.read?"text-foreground":"font-medium text-foreground"}`,children:me(t.type,t.data,t.message,i,(u==null?void 0:u.gender)??void 0)}),e.jsx("p",{className:"text-[13px] text-muted-foreground mt-0.5",children:fe(new Date(t.created_at),{addSuffix:!0,locale:p})})]})]}),r<s.items.length-1&&e.jsx("div",{className:"ml-[60px] h-[0.5px] bg-border/60"})]})},t.id))})]},s.labelKey)),C&&e.jsx("div",{className:"flex justify-center pt-2 pb-4",children:e.jsx("button",{onClick:()=>{k(),B()},disabled:b,className:"text-[15px] text-primary font-medium active:opacity-60 transition-opacity disabled:opacity-40",children:b?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(xe,{className:"h-4 w-4 animate-spin"}),i("loading")]}):i("loadMore")})})]}),e.jsx("div",{className:"pb-safe"})]})]})})}export{_e as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.