mirror of
https://github.com/kikobar/mastodon.git
synced 2024-11-16 12:12:14 +00:00
Rewrite actions/app.ts and reducers/missed_updates.ts with createAction (#24801)
This commit is contained in:
parent
c98b012583
commit
0999cb4601
|
@ -1,17 +0,0 @@
|
|||
export const APP_FOCUS = 'APP_FOCUS';
|
||||
export const APP_UNFOCUS = 'APP_UNFOCUS';
|
||||
|
||||
export const focusApp = () => ({
|
||||
type: APP_FOCUS,
|
||||
});
|
||||
|
||||
export const unfocusApp = () => ({
|
||||
type: APP_UNFOCUS,
|
||||
});
|
||||
|
||||
export const APP_LAYOUT_CHANGE = 'APP_LAYOUT_CHANGE';
|
||||
|
||||
export const changeLayout = layout => ({
|
||||
type: APP_LAYOUT_CHANGE,
|
||||
layout,
|
||||
});
|
10
app/javascript/mastodon/actions/app.ts
Normal file
10
app/javascript/mastodon/actions/app.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { createAction } from '@reduxjs/toolkit';
|
||||
|
||||
export const focusApp = createAction('APP_FOCUS');
|
||||
export const unfocusApp = createAction('APP_UNFOCUS');
|
||||
|
||||
type ChangeLayoutPayload = {
|
||||
layout: 'mobile' | 'single-column' | 'multi-column';
|
||||
};
|
||||
export const changeLayout =
|
||||
createAction<ChangeLayoutPayload>('APP_LAYOUT_CHANGE');
|
|
@ -362,7 +362,7 @@ class UI extends React.PureComponent {
|
|||
|
||||
if (layout !== this.props.layout) {
|
||||
this.handleLayoutChange.cancel();
|
||||
this.props.dispatch(changeLayout(layout));
|
||||
this.props.dispatch(changeLayout({ layout }));
|
||||
} else {
|
||||
this.handleLayoutChange();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { STORE_HYDRATE } from 'mastodon/actions/store';
|
||||
import { APP_LAYOUT_CHANGE } from 'mastodon/actions/app';
|
||||
import { changeLayout } from 'mastodon/actions/app';
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
import { layoutFromWindow } from 'mastodon/is_mobile';
|
||||
|
||||
|
@ -14,8 +14,8 @@ export default function meta(state = initialState, action) {
|
|||
switch(action.type) {
|
||||
case STORE_HYDRATE:
|
||||
return state.merge(action.state.get('meta')).set('permissions', action.state.getIn(['role', 'permissions']));
|
||||
case APP_LAYOUT_CHANGE:
|
||||
return state.set('layout', action.layout);
|
||||
case changeLayout.type:
|
||||
return state.set('layout', action.payload.layout);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
import { Map as ImmutableMap } from 'immutable';
|
||||
import { NOTIFICATIONS_UPDATE } from 'mastodon/actions/notifications';
|
||||
import { APP_FOCUS, APP_UNFOCUS } from 'mastodon/actions/app';
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
focused: true,
|
||||
unread: 0,
|
||||
});
|
||||
|
||||
export default function missed_updates(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case APP_FOCUS:
|
||||
return state.set('focused', true).set('unread', 0);
|
||||
case APP_UNFOCUS:
|
||||
return state.set('focused', false);
|
||||
case NOTIFICATIONS_UPDATE:
|
||||
return state.get('focused') ? state : state.update('unread', x => x + 1);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
31
app/javascript/mastodon/reducers/missed_updates.ts
Normal file
31
app/javascript/mastodon/reducers/missed_updates.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { Record } from 'immutable';
|
||||
import type { Action } from 'redux';
|
||||
import { NOTIFICATIONS_UPDATE } from '../actions/notifications';
|
||||
import { focusApp, unfocusApp } from '../actions/app';
|
||||
|
||||
type MissedUpdatesState = {
|
||||
focused: boolean;
|
||||
unread: number;
|
||||
};
|
||||
const initialState = Record<MissedUpdatesState>({
|
||||
focused: true,
|
||||
unread: 0,
|
||||
})();
|
||||
|
||||
export default function missed_updates(
|
||||
state = initialState,
|
||||
action: Action<string>,
|
||||
) {
|
||||
switch (action.type) {
|
||||
case focusApp.type:
|
||||
return state.set('focused', true).set('unread', 0);
|
||||
case unfocusApp.type:
|
||||
return state.set('focused', false);
|
||||
case NOTIFICATIONS_UPDATE:
|
||||
return state.get('focused')
|
||||
? state
|
||||
: state.update('unread', (x) => x + 1);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue