mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-12-07 15:29:03 +01:00
7224e24054
Port f587ff643f
to glitch-soc
Co-authored-by: Eugen Rochko <eugen@zeonfederated.com>
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
41 lines
1,012 B
TypeScript
41 lines
1,012 B
TypeScript
import { createReducer } from '@reduxjs/toolkit';
|
|
|
|
import {
|
|
submitMarkersAction,
|
|
fetchMarkers,
|
|
} from 'flavours/glitch/actions/markers';
|
|
import { compareId } from 'flavours/glitch/compare_id';
|
|
|
|
const initialState = {
|
|
home: '0',
|
|
notifications: '0',
|
|
};
|
|
|
|
export const markersReducer = createReducer(initialState, (builder) => {
|
|
builder.addCase(
|
|
submitMarkersAction.fulfilled,
|
|
(state, { payload: { home, notifications } }) => {
|
|
if (home) state.home = home;
|
|
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;
|
|
},
|
|
);
|
|
});
|