chore: fixed unread and read errors 2ad39a95
Steve · 2025-11-01 23:18 3 file(s) · +14 −14
TODO.md +1 −1
13 13
- [ ] Find a way to paginate through feeds and get more posts if they only return a few
14 14
- [ ] Collapse both side bars if desired?
15 15
- [x] Update logo in top left
16 -
- [ ] Marking Read and Unread
16 +
- [x] Marking Read and Unread
src/components/app-sidebar.tsx +11 −11
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
			}
src/lib/scheme.ts +2 −2
4 4
	NonEmptyString,
5 5
	NonEmptyString1000,
6 6
	nullOr,
7 -
	SqliteBoolean,
7 +
	Number,
8 8
} from "@evolu/common";
9 9
10 10
// RSS Feed ID
44 44
		id: id("ReadStatus"),
45 45
		feedId: RSSFeedId,
46 46
		postId: RSSPostId,
47 -
		isRead: SqliteBoolean,
47 +
		isRead: nullOr(Number), // 0 for false, 1 for true
48 48
	},
49 49
	userPreferences: {
50 50
		id: id("UserPreferences"),