@@ -21,32 +21,33 @@ import Image from "../Image.vue";
2121
2222const getActor = (notification : Notification ) => {
2323 if (notification .speaker && typeof notification .speaker === " object" ) {
24+ const speaker = notification .speaker as Speaker ;
2425 return {
25- id: (notification .speaker as Speaker ).id ,
26- name: (notification .speaker as Speaker ).name ,
27- avatar:
28- (notification .speaker as Speaker ).imgs .internal ||
29- (notification .speaker as Speaker ).imgs .speaker ,
26+ id: speaker .id ,
27+ name: speaker .name ,
28+ avatar: speaker .imgs .internal || speaker .imgs .speaker ,
3029 };
3130 }
3231 if (notification .company && typeof notification .company === " object" ) {
32+ const company = notification .company as Company ;
3333 return {
34- id: (notification .company as Company ).id ,
35- name: (notification .company as Company ).name ,
36- avatar:
37- (notification .company as Company ).imgs ?.internal ||
38- (notification .company as Company ).imgs ?.public ,
34+ id: company .id ,
35+ name: company .name ,
36+ avatar: company .imgs ?.internal || company .imgs ?.public ,
3937 };
4038 }
4139 return null ;
4240};
4341
44- const makeMessage = (notification : Notification ) => {
42+ const makeMessage = (
43+ notification : Notification ,
44+ actorArg ? : { id? : string ; name? : string ; avatar? : string } | null ,
45+ ) => {
4546 const thread = notification .thread ;
4647 const kind = notification .kind ;
47- // Actor is the entity (company/speaker) related to the notification
48- const actor = getActor (notification );
49- const actorName = actor ? actor .name : " " ;
48+ // Actor is the entity (company/speaker) related to the notification. Prefer the precomputed actor when provided.
49+ const actor = actorArg ?? getActor (notification );
50+ const actorName = actor && actor . name ? actor .name : " " ;
5051 const isActorPresent = actorName .length > 0 ;
5152
5253 switch (kind ) {
@@ -102,10 +103,18 @@ const { data: notifications } = useQuery({
102103 query: getMyNotifications ,
103104});
104105
105- const notificationItems = computed (() => {
106+ type NotificationEntry = {
107+ n: Notification ;
108+ actor: { id? : string ; name? : string ; avatar? : string } | null ;
109+ };
110+
111+ const notificationItems = computed <NotificationEntry []>(() => {
106112 const items = (notifications .value ?.data as Notification []) || [];
107113 // sort newest first — try common timestamp fields (date, createdAt, created_at)
108- return items .slice ().sort ((a , b ) => b .date ?.localeCompare (a .date ?? " " ) || 0 );
114+ const sorted = items
115+ .slice ()
116+ .sort ((a , b ) => b .date ?.localeCompare (a .date ?? " " ) || 0 );
117+ return sorted .map ((n ) => ({ n , actor: getActor (n ) }));
109118});
110119
111120const _deleteNotificationMutation = useDeleteNotificationMutation ();
@@ -116,7 +125,7 @@ const removeNotification = async (id: string) => {
116125};
117126
118127const removeAllNotifications = async () => {
119- const ids = notificationItems .value .map ((i ) => i .id );
128+ const ids = notificationItems .value .map ((i ) => i .n . id );
120129 if (! ids .length ) return ;
121130 await _deleteAllNotificationsMutation .mutate ();
122131};
@@ -189,29 +198,31 @@ const onNotificationClick = async (n: Notification) => {
189198
190199 <ul >
191200 <li
192- v-for =" n in notificationItems"
193- :key =" n.id"
201+ v-for =" entry in notificationItems"
202+ :key =" entry. n.id"
194203 class =" flex items-center justify-between px-3 py-2 hover:bg-gray-50 cursor-pointer"
195- @click =" onNotificationClick(n)"
204+ @click =" onNotificationClick(entry. n)"
196205 >
197206 <div class =" flex items-center gap-3" >
198207 <Image
199- v-if =" getActor(n) ?.avatar"
200- :src =" getActor(n) ?.avatar"
208+ v-if =" entry.actor ?.avatar"
209+ :src =" entry.actor ?.avatar"
201210 alt =" actor"
202211 class =" h-8 w-8 rounded-full object-cover"
203212 />
204213 <div class =" text-sm" >
205- <div class =" font-medium" >{{ makeMessage(n) }}</div >
214+ <div class =" font-medium" >
215+ {{ makeMessage(entry.n, entry.actor) }}
216+ </div >
206217 <div class =" text-xs text-gray-500" >
207- {{ getActor(n) ?.name || n.date }}
218+ {{ entry.actor ?.name || entry. n.date }}
208219 </div >
209220 </div >
210221 </div >
211222 <div >
212223 <button
213224 class =" text-red-500 text-sm"
214- @click.stop.prevent =" removeNotification(n.id)"
225+ @click.stop.prevent =" removeNotification(entry. n.id)"
215226 >
216227 <Trash :size =" 16" />
217228 </button >
0 commit comments