Rewrite markers reducer in Typescript (#27644)
This commit is contained in:
parent
d49343ed11
commit
27d014a7fa
9 changed files with 202 additions and 185 deletions
|
@ -21,7 +21,7 @@ import history from './history';
|
|||
import listAdder from './list_adder';
|
||||
import listEditor from './list_editor';
|
||||
import lists from './lists';
|
||||
import markers from './markers';
|
||||
import { markersReducer } from './markers';
|
||||
import media_attachments from './media_attachments';
|
||||
import meta from './meta';
|
||||
import { modalReducer } from './modal';
|
||||
|
@ -77,7 +77,7 @@ const reducers = {
|
|||
suggestions,
|
||||
polls,
|
||||
trends,
|
||||
markers,
|
||||
markers: markersReducer,
|
||||
picture_in_picture,
|
||||
history,
|
||||
tags,
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
import { Map as ImmutableMap } from 'immutable';
|
||||
|
||||
import {
|
||||
MARKERS_SUBMIT_SUCCESS,
|
||||
} from '../actions/markers';
|
||||
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
home: '0',
|
||||
notifications: '0',
|
||||
});
|
||||
|
||||
export default function markers(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case MARKERS_SUBMIT_SUCCESS:
|
||||
if (action.home) {
|
||||
state = state.set('home', action.home);
|
||||
}
|
||||
if (action.notifications) {
|
||||
state = state.set('notifications', action.notifications);
|
||||
}
|
||||
return state;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
18
app/javascript/mastodon/reducers/markers.ts
Normal file
18
app/javascript/mastodon/reducers/markers.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { createReducer } from '@reduxjs/toolkit';
|
||||
|
||||
import { submitMarkersAction } from 'mastodon/actions/markers';
|
||||
|
||||
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;
|
||||
},
|
||||
);
|
||||
});
|
|
@ -13,7 +13,7 @@ import {
|
|||
unfocusApp,
|
||||
} from '../actions/app';
|
||||
import {
|
||||
MARKERS_FETCH_SUCCESS,
|
||||
fetchMarkers,
|
||||
} from '../actions/markers';
|
||||
import {
|
||||
notificationsUpdate,
|
||||
|
@ -255,8 +255,8 @@ const recountUnread = (state, last_read_id) => {
|
|||
|
||||
export default function notifications(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case MARKERS_FETCH_SUCCESS:
|
||||
return action.markers.notifications ? recountUnread(state, action.markers.notifications.last_read_id) : state;
|
||||
case fetchMarkers.fulfilled.type:
|
||||
return action.payload.markers.notifications ? recountUnread(state, action.payload.markers.notifications.last_read_id) : state;
|
||||
case NOTIFICATIONS_MOUNT:
|
||||
return updateMounted(state);
|
||||
case NOTIFICATIONS_UNMOUNT:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue