| 122 |
122 |
|
const handlePostSelect = React.useCallback( |
| 123 |
123 |
|
(postId: string) => { |
| 124 |
124 |
|
// Mark as read |
| 125 |
|
- |
const existingStatus = allReadStatuses.find( |
|
125 |
+ |
const existingStatus = allReadStatusesWithUnread.find( |
| 126 |
126 |
|
(status) => status.postId === postId, |
| 127 |
127 |
|
); |
| 128 |
128 |
|
const post = feedPosts.find((p) => p.id === postId); |
|
| 130 |
130 |
|
if (existingStatus) { |
| 131 |
131 |
|
// Update existing status to read |
| 132 |
132 |
|
update("readStatus", { |
| 133 |
|
- |
id: existingStatus.id, |
| 134 |
|
- |
isRead: true, |
|
133 |
+ |
id: existingStatus.id as any, |
|
134 |
+ |
isRead: 1, |
| 135 |
135 |
|
}); |
| 136 |
136 |
|
} else if (post && post.feedId) { |
| 137 |
137 |
|
// Create new read status |
| 138 |
138 |
|
insert("readStatus", { |
| 139 |
139 |
|
postId: postId, |
| 140 |
140 |
|
feedId: post.feedId, |
| 141 |
|
- |
isRead: true, |
|
141 |
+ |
isRead: 1, |
| 142 |
142 |
|
}); |
| 143 |
143 |
|
} |
| 144 |
144 |
|
|
| 145 |
145 |
|
// Call the original onPostSelect |
| 146 |
146 |
|
onPostSelect(postId); |
| 147 |
147 |
|
}, |
| 148 |
|
- |
[allReadStatuses, feedPosts, insert, update, onPostSelect], |
|
148 |
+ |
[allReadStatusesWithUnread, feedPosts, insert, update, onPostSelect], |
| 149 |
149 |
|
); |
| 150 |
150 |
|
|
| 151 |
151 |
|
// Mark all visible posts as read |
|
| 159 |
159 |
|
if (existingStatus && !existingStatus.isRead) { |
| 160 |
160 |
|
// Update existing status to read |
| 161 |
161 |
|
update("readStatus", { |
| 162 |
|
- |
id: existingStatus.id, |
| 163 |
|
- |
isRead: true, |
|
162 |
+ |
id: existingStatus.id as any, |
|
163 |
+ |
isRead: 1, |
| 164 |
164 |
|
}); |
| 165 |
165 |
|
markedCount++; |
| 166 |
166 |
|
} else if (!existingStatus && post.feedId) { |
|
| 168 |
168 |
|
insert("readStatus", { |
| 169 |
169 |
|
postId: post.id, |
| 170 |
170 |
|
feedId: post.feedId, |
| 171 |
|
- |
isRead: true, |
|
171 |
+ |
isRead: 1, |
| 172 |
172 |
|
}); |
| 173 |
173 |
|
markedCount++; |
| 174 |
174 |
|
} |
|
| 189 |
189 |
|
if (existingStatus && existingStatus.isRead) { |
| 190 |
190 |
|
// Update existing status to unread |
| 191 |
191 |
|
update("readStatus", { |
| 192 |
|
- |
id: existingStatus.id, |
| 193 |
|
- |
isRead: false, |
|
192 |
+ |
id: existingStatus.id as any, |
|
193 |
+ |
isRead: 0, |
| 194 |
194 |
|
}); |
| 195 |
195 |
|
unmarkedCount++; |
| 196 |
196 |
|
} else if (!existingStatus && post.feedId) { |
|
| 198 |
198 |
|
insert("readStatus", { |
| 199 |
199 |
|
postId: post.id, |
| 200 |
200 |
|
feedId: post.feedId, |
| 201 |
|
- |
isRead: false, |
|
201 |
+ |
isRead: 0, |
| 202 |
202 |
|
}); |
| 203 |
203 |
|
unmarkedCount++; |
| 204 |
204 |
|
} |