Handle `fetchMarkers` action in markers reducer

grouped-notifications-frontend
Claire 2024-07-04 15:37:14 +02:00 committed by Renaud Chaput
parent 29963226d4
commit ccb8fa81c2
No known key found for this signature in database
GPG Key ID: BCFC859D49B46990
1 changed files with 21 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import { createReducer } from '@reduxjs/toolkit';
import { submitMarkersAction } from 'mastodon/actions/markers';
import { submitMarkersAction, fetchMarkers } from 'mastodon/actions/markers';
import { compareId } from 'mastodon/compare_id';
const initialState = {
home: '0',
@ -15,4 +16,23 @@ export const markersReducer = createReducer(initialState, (builder) => {
if (notifications) state.notifications = notifications;
},
);
builder.addCase(
fetchMarkers.fulfilled,
(
state,
{
payload: {
markers: { home, notifications },
},
},
) => {
if (home && compareId(home.last_read_id, state.home) > 0)
state.home = home.last_read_id;
if (
notifications &&
compareId(notifications.last_read_id, state.notifications) > 0
)
state.notifications = notifications.last_read_id;
},
);
});