11import { ProfileView } from "@/atproto/types/app/bsky/actor/defs" ;
22import { isView } from "@/atproto/types/app/bsky/embed/images" ;
3- import { PostView } from "@/atproto/types/app/bsky/feed/defs" ;
3+ import {
4+ GeneratorView ,
5+ PostView ,
6+ isGeneratorView ,
7+ isPostView ,
8+ } from "@/atproto/types/app/bsky/feed/defs" ;
49import { isRecord } from "@/atproto/types/app/bsky/feed/post" ;
510import Avatar from "@/components/Avatar" ;
611import DistanceToNow from "@/components/DistanceToNow" ;
7- import PostEmbed from "@/components/PostEmbed" ;
12+ import PostEmbed , { Generator } from "@/components/PostEmbed" ;
813import Post from "@/components/PostView" ;
914import { NotificationReason } from "@/constants" ;
1015import { useAutoAnimate } from "@formkit/auto-animate/react" ;
@@ -23,12 +28,27 @@ export interface NotificationGroup {
2328 authors : ProfileView [ ] ;
2429}
2530
31+ const PostContent : FC < { post : PostView } > = ( { post } ) => {
32+ return (
33+ < >
34+ { post . record && isRecord ( post . record ) && (
35+ < div className = "text-muted whitespace-pre-wrap" > { post . record . text } </ div >
36+ ) }
37+ { isView ( post . embed ) && (
38+ < div className = "w-1/4" >
39+ < PostEmbed embed = { post . embed } />
40+ </ div >
41+ ) }
42+ </ >
43+ ) ;
44+ } ;
45+
2646const NotificationView : FC <
2747 PropsWithChildren < {
2848 group : NotificationGroup ;
29- post ?: PostView | null ;
49+ content ?: PostView | GeneratorView | null ;
3050 } >
31- > = ( { group, post , children } ) => {
51+ > = ( { group, content , children } ) => {
3252 const { reason, indexedAt, authors } = group ;
3353 const avatars = (
3454 < div className = "flex items-center mb-1" >
@@ -89,57 +109,55 @@ const NotificationView: FC<
89109 < div >
90110 { subject } { children }
91111 </ div >
92- { post ?. record && isRecord ( post . record ) && (
93- < div className = "text-muted whitespace-pre-wrap" >
94- { post . record . text }
95- </ div >
96- ) }
97- { post && isView ( post . embed ) && (
98- < div className = "w-1/4" >
99- < PostEmbed embed = { post . embed } />
100- </ div >
101- ) }
112+ { isPostView ( content ) && < PostContent post = { content } /> }
113+ { isGeneratorView ( content ) && < Generator generator = { content } /> }
102114 </ div >
103115 </ div >
104116 ) ;
105117} ;
106118
107119const NotificationItem : FC < {
108120 group : NotificationGroup ;
109- post ?: PostView | null ;
110- } > = ( { group, post } ) => {
121+ content ?: PostView | GeneratorView | null ;
122+ } > = ( { group, content } ) => {
123+ // TODO: other content?
124+ const contentName = ( ( ) => {
125+ if ( isPostView ( content ) ) return "your post" ;
126+ if ( isGeneratorView ( content ) ) return "your custom feed" ;
127+ return null ;
128+ } ) ( ) ;
111129 switch ( group . reason ) {
112130 case NotificationReason . Like :
113131 return (
114- < NotificationView group = { group } post = { post } >
115- liked your post
132+ < NotificationView group = { group } content = { content } >
133+ liked { contentName }
116134 </ NotificationView >
117135 ) ;
118136 case NotificationReason . Repost :
119137 return (
120- < NotificationView group = { group } post = { post } >
138+ < NotificationView group = { group } content = { content } >
121139 reposted your post
122140 </ NotificationView >
123141 ) ;
124142 case NotificationReason . Follow :
125143 return < NotificationView group = { group } > followed you</ NotificationView > ;
126144 default :
127- return post && < Post post = { post } /> ;
145+ return content && isPostView ( content ) && < Post post = { content } /> ;
128146 }
129147} ;
130148
131149const NotificationList : FC < {
132150 groups : NotificationGroup [ ] ;
133- posts : Map < string , PostView | null > ;
134- } > = ( { groups, posts } ) => {
151+ contents : Map < string , PostView | GeneratorView | null > ;
152+ } > = ( { groups, contents } ) => {
135153 const [ parent , _ ] = useAutoAnimate ( ) ;
136154 return (
137155 < div ref = { parent } >
138156 { groups . map ( ( group ) => (
139157 < div key = { group . key } className = "border-b border-slate-500 px-3 pt-3" >
140158 < NotificationItem
141159 group = { group }
142- post = { group . uri ? posts . get ( group . uri ) : undefined }
160+ content = { group . uri ? contents . get ( group . uri ) : undefined }
143161 />
144162 </ div >
145163 ) ) }
0 commit comments