refactor(core): overhaul state transition architecture, persistent job queue, and API layer
- Implement atomic state transitions: add EntryService.PatchEntry() with EntryDiff computation and EventEntryTransition event emission. - Add persistent SQLite task queue (JobEngine): add jobs table with crash recovery, exponential backoff retries, concurrency control, and idempotency key deduplication. - Decompose monolithic HTTP handlers: split handlers.go into domain handlers (auth, feeds, entries, jobs, settings, rules, sse). - Implement real-time Server-Sent Events (/api/events/stream) for multi-tab/device state synchronization. - Fix SQLite concurrency: apply busy_timeout(10000) and journal_mode(WAL) via DSN query parameters to resolve SQLITE_BUSY (5). - Fix AI settings & prompt loading: unmarshal JSON from ai_settings, apply configured prompt templates, and enforce strict enabled/API key validations. - Fix undo share state: remove omitempty from ShareUUID to serialize null for state resets. - Fix middle list counter: compute true unread/total stats from DB and clean switcher button labels. - Adapt mobile UI for iOS: add viewport-fit=cover in index.html and calibrate safe-area insets for the bottom navigation and article reader toolbar. - Add architectural documentation and worklog in docs/009_worklog.md.
This commit is contained in:
+50
-1
@@ -306,9 +306,57 @@ export const App: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// Connect Real-Time SSE Stream for live state sync across tabs and async background jobs
|
||||
useEffect(() => {
|
||||
if (!currentUser) return;
|
||||
|
||||
const disconnect = api.connectEventStream((eventType, data) => {
|
||||
if (eventType === 'job_completed' || eventType === 'post_updated' || eventType === 'variant_updated') {
|
||||
const updatedEntry = data?.entry || data;
|
||||
if (updatedEntry && updatedEntry.id) {
|
||||
setEntries((prev) =>
|
||||
prev.map((e) =>
|
||||
e.id === updatedEntry.id
|
||||
? {
|
||||
...e,
|
||||
...updatedEntry,
|
||||
variants: { ...(e.variants || {}), ...(updatedEntry.variants || {}) },
|
||||
}
|
||||
: e
|
||||
)
|
||||
);
|
||||
}
|
||||
} else if (eventType === 'post_created') {
|
||||
loadSidebarData();
|
||||
} else if (eventType === 'preferences_updated') {
|
||||
if (data && typeof data === 'object') {
|
||||
if (data.auto_read !== undefined) {
|
||||
localStorage.setItem('rsspipe_auto_read_scroll', data.auto_read ? 'true' : 'false');
|
||||
}
|
||||
if (data.view_preference) {
|
||||
setViewPreference(data.view_preference);
|
||||
localStorage.setItem('rsspipe_view_preference', data.view_preference);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return () => disconnect();
|
||||
}, [currentUser, loadSidebarData]);
|
||||
|
||||
// Update Single Entry Action
|
||||
const handleUpdateEntry = (updated: FeedEntry) => {
|
||||
setEntries((prev) => prev.map((e) => (e.id === updated.id ? updated : e)));
|
||||
setEntries((prev) =>
|
||||
prev.map((e) =>
|
||||
e.id === updated.id
|
||||
? {
|
||||
...e,
|
||||
...updated,
|
||||
variants: { ...(e.variants || {}), ...(updated.variants || {}) },
|
||||
}
|
||||
: e
|
||||
)
|
||||
);
|
||||
loadSidebarData();
|
||||
};
|
||||
|
||||
@@ -500,6 +548,7 @@ export const App: React.FC = () => {
|
||||
onMarkAllRead={handleMarkAllRead}
|
||||
onUpdateEntry={handleUpdateEntry}
|
||||
stats={stats}
|
||||
totalEntries={totalEntries}
|
||||
onOpenSettings={() => setViewMode('settings')}
|
||||
onOpenAddFeed={() => setShowAddFeedModal(true)}
|
||||
onPlayAudio={handlePlayAudio}
|
||||
|
||||
Reference in New Issue
Block a user