2022-03-09 13:24:42 -08:00
|
|
|
import { Record as ImmutableRecord } from 'immutable';
|
2022-01-10 14:17:52 -08:00
|
|
|
import { combineReducers } from 'redux-immutable';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2020-09-27 17:09:35 -07:00
|
|
|
import { AUTH_LOGGED_OUT } from 'soapbox/actions/auth';
|
2022-03-21 11:09:01 -07:00
|
|
|
import * as BuildConfig from 'soapbox/build_config';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-02-26 06:57:09 -08:00
|
|
|
import account_notes from './account_notes';
|
2020-03-27 13:59:38 -07:00
|
|
|
import accounts from './accounts';
|
|
|
|
import accounts_counters from './accounts_counters';
|
2022-01-10 14:17:52 -08:00
|
|
|
import accounts_meta from './accounts_meta';
|
|
|
|
import admin from './admin';
|
|
|
|
import admin_log from './admin_log';
|
|
|
|
import alerts from './alerts';
|
|
|
|
import aliases from './aliases';
|
2022-07-06 14:25:19 -07:00
|
|
|
import announcements from './announcements';
|
2022-01-10 14:17:52 -08:00
|
|
|
import auth from './auth';
|
|
|
|
import backups from './backups';
|
2022-06-22 05:55:42 -07:00
|
|
|
import carousels from './carousels';
|
2022-01-10 14:17:52 -08:00
|
|
|
import chat_message_lists from './chat_message_lists';
|
|
|
|
import chat_messages from './chat_messages';
|
|
|
|
import chats from './chats';
|
2020-03-27 13:59:38 -07:00
|
|
|
import compose from './compose';
|
2022-01-10 14:17:52 -08:00
|
|
|
import contexts from './contexts';
|
|
|
|
import conversations from './conversations';
|
2020-03-27 13:59:38 -07:00
|
|
|
import custom_emojis from './custom_emojis';
|
2022-01-10 14:17:52 -08:00
|
|
|
import domain_lists from './domain_lists';
|
|
|
|
import dropdown_menu from './dropdown_menu';
|
2020-03-27 13:59:38 -07:00
|
|
|
import filters from './filters';
|
|
|
|
import group_editor from './group_editor';
|
2022-01-10 14:17:52 -08:00
|
|
|
import group_lists from './group_lists';
|
|
|
|
import group_relationships from './group_relationships';
|
|
|
|
import groups from './groups';
|
2022-04-27 13:50:35 -07:00
|
|
|
import history from './history';
|
2020-04-01 13:05:52 -07:00
|
|
|
import instance from './instance';
|
2022-01-10 14:17:52 -08:00
|
|
|
import listAdder from './list_adder';
|
|
|
|
import listEditor from './list_editor';
|
|
|
|
import lists from './lists';
|
2020-04-01 19:20:47 -07:00
|
|
|
import me from './me';
|
2022-01-10 14:17:52 -08:00
|
|
|
import meta from './meta';
|
2022-02-02 05:33:12 -08:00
|
|
|
import modals from './modals';
|
2022-01-10 14:17:52 -08:00
|
|
|
import mutes from './mutes';
|
|
|
|
import notifications from './notifications';
|
2022-05-02 13:55:52 -07:00
|
|
|
import onboarding from './onboarding';
|
2022-01-10 14:17:52 -08:00
|
|
|
import patron from './patron';
|
|
|
|
import pending_statuses from './pending_statuses';
|
|
|
|
import polls from './polls';
|
2020-09-10 17:09:27 -07:00
|
|
|
import profile_hover_card from './profile_hover_card';
|
2022-01-10 14:17:52 -08:00
|
|
|
import push_notifications from './push_notifications';
|
|
|
|
import relationships from './relationships';
|
|
|
|
import reports from './reports';
|
2022-04-27 07:11:21 -07:00
|
|
|
import rules from './rules';
|
2021-06-27 12:58:40 -07:00
|
|
|
import scheduled_statuses from './scheduled_statuses';
|
2022-01-10 14:17:52 -08:00
|
|
|
import search from './search';
|
|
|
|
import security from './security';
|
|
|
|
import settings from './settings';
|
|
|
|
import sidebar from './sidebar';
|
|
|
|
import soapbox from './soapbox';
|
2022-06-17 12:39:17 -07:00
|
|
|
import status_hover_card from './status-hover-card';
|
2022-01-10 14:17:52 -08:00
|
|
|
import status_lists from './status_lists';
|
|
|
|
import statuses from './statuses';
|
|
|
|
import suggestions from './suggestions';
|
|
|
|
import timelines from './timelines';
|
2022-03-21 11:09:01 -07:00
|
|
|
import trending_statuses from './trending_statuses';
|
2022-01-10 14:17:52 -08:00
|
|
|
import trends from './trends';
|
|
|
|
import user_lists from './user_lists';
|
2022-03-21 11:09:01 -07:00
|
|
|
import verification from './verification';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-03-09 13:24:42 -08:00
|
|
|
const reducers = {
|
2020-03-27 13:59:38 -07:00
|
|
|
dropdown_menu,
|
|
|
|
timelines,
|
|
|
|
meta,
|
|
|
|
alerts,
|
2022-02-02 05:33:12 -08:00
|
|
|
modals,
|
2020-03-27 13:59:38 -07:00
|
|
|
user_lists,
|
|
|
|
domain_lists,
|
|
|
|
status_lists,
|
2022-02-26 06:57:09 -08:00
|
|
|
account_notes,
|
2020-03-27 13:59:38 -07:00
|
|
|
accounts,
|
|
|
|
accounts_counters,
|
|
|
|
statuses,
|
|
|
|
relationships,
|
|
|
|
settings,
|
|
|
|
push_notifications,
|
|
|
|
mutes,
|
|
|
|
reports,
|
|
|
|
contexts,
|
|
|
|
compose,
|
|
|
|
search,
|
|
|
|
notifications,
|
|
|
|
custom_emojis,
|
|
|
|
lists,
|
|
|
|
listEditor,
|
|
|
|
listAdder,
|
|
|
|
filters,
|
|
|
|
conversations,
|
|
|
|
suggestions,
|
|
|
|
polls,
|
|
|
|
trends,
|
|
|
|
groups,
|
|
|
|
group_relationships,
|
|
|
|
group_lists,
|
|
|
|
group_editor,
|
|
|
|
sidebar,
|
2020-03-31 15:45:12 -07:00
|
|
|
patron,
|
2020-04-01 12:38:08 -07:00
|
|
|
soapbox,
|
2020-04-01 13:05:52 -07:00
|
|
|
instance,
|
2020-04-01 19:20:47 -07:00
|
|
|
me,
|
2020-04-05 14:54:51 -07:00
|
|
|
auth,
|
2020-08-24 15:18:53 -07:00
|
|
|
admin,
|
2020-08-24 19:26:42 -07:00
|
|
|
chats,
|
2020-08-25 18:33:49 -07:00
|
|
|
chat_messages,
|
2020-08-26 13:54:14 -07:00
|
|
|
chat_message_lists,
|
2020-09-10 17:09:27 -07:00
|
|
|
profile_hover_card,
|
2022-06-16 21:19:53 -07:00
|
|
|
status_hover_card,
|
2021-01-07 12:17:06 -08:00
|
|
|
backups,
|
2021-03-15 15:29:48 -07:00
|
|
|
admin_log,
|
2021-03-23 19:15:47 -07:00
|
|
|
security,
|
2021-06-27 12:58:40 -07:00
|
|
|
scheduled_statuses,
|
2021-10-09 14:56:03 -07:00
|
|
|
pending_statuses,
|
2021-08-05 06:31:29 -07:00
|
|
|
aliases,
|
2021-08-23 15:51:32 -07:00
|
|
|
accounts_meta,
|
2022-03-21 11:09:01 -07:00
|
|
|
trending_statuses,
|
|
|
|
verification,
|
2022-05-02 13:55:52 -07:00
|
|
|
onboarding,
|
2022-04-27 07:11:21 -07:00
|
|
|
rules,
|
2022-04-27 13:50:35 -07:00
|
|
|
history,
|
2022-06-22 05:55:42 -07:00
|
|
|
carousels,
|
2022-07-06 14:25:19 -07:00
|
|
|
announcements,
|
2022-03-09 13:24:42 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Build a default state from all reducers: it has the key and `undefined`
|
2022-03-16 19:15:38 -07:00
|
|
|
export const StateRecord = ImmutableRecord(
|
2022-03-15 06:48:18 -07:00
|
|
|
Object.keys(reducers).reduce((params: Record<string, any>, reducer) => {
|
2022-03-09 13:24:42 -08:00
|
|
|
params[reducer] = undefined;
|
|
|
|
return params;
|
|
|
|
}, {}),
|
|
|
|
);
|
|
|
|
|
|
|
|
const appReducer = combineReducers(reducers, StateRecord);
|
2020-09-27 17:09:35 -07:00
|
|
|
|
|
|
|
// Clear the state (mostly) when the user logs out
|
2022-03-15 06:48:18 -07:00
|
|
|
const logOut = (state: any = StateRecord()): ReturnType<typeof appReducer> => {
|
2022-03-21 11:09:01 -07:00
|
|
|
if (BuildConfig.NODE_ENV === 'production') {
|
|
|
|
location.href = '/login';
|
|
|
|
}
|
|
|
|
|
2022-03-15 06:48:18 -07:00
|
|
|
const whitelist: string[] = ['instance', 'soapbox', 'custom_emojis', 'auth'];
|
2020-09-27 17:09:35 -07:00
|
|
|
|
2022-03-09 13:24:42 -08:00
|
|
|
return StateRecord(
|
2022-03-15 06:48:18 -07:00
|
|
|
whitelist.reduce((acc: Record<string, any>, curr) => {
|
2020-09-27 17:09:35 -07:00
|
|
|
acc[curr] = state.get(curr);
|
|
|
|
return acc;
|
2020-10-07 11:08:36 -07:00
|
|
|
}, {}),
|
2022-03-15 06:48:18 -07:00
|
|
|
) as unknown as ReturnType<typeof appReducer>;
|
2020-09-27 17:09:35 -07:00
|
|
|
};
|
|
|
|
|
2022-03-15 06:48:18 -07:00
|
|
|
const rootReducer: typeof appReducer = (state, action) => {
|
2022-05-11 10:40:34 -07:00
|
|
|
switch (action.type) {
|
2022-05-11 14:06:35 -07:00
|
|
|
case AUTH_LOGGED_OUT:
|
|
|
|
return appReducer(logOut(state), action);
|
|
|
|
default:
|
|
|
|
return appReducer(state, action);
|
2020-09-27 17:09:35 -07:00
|
|
|
}
|
2020-03-27 13:59:38 -07:00
|
|
|
};
|
|
|
|
|
2020-09-27 17:09:35 -07:00
|
|
|
export default rootReducer;
|