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-11-15 12:48:54 -08:00
|
|
|
import * as BuildConfig from 'soapbox/build-config';
|
2022-12-04 14:58:13 -08:00
|
|
|
import entities from 'soapbox/entity-store/reducer';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-11-16 05:32:32 -08:00
|
|
|
import accounts_meta from './accounts-meta';
|
2022-01-10 14:17:52 -08:00
|
|
|
import admin from './admin';
|
2023-02-07 13:22:23 -08:00
|
|
|
import admin_announcements from './admin-announcements';
|
2022-11-15 12:39:43 -08:00
|
|
|
import admin_log from './admin-log';
|
2022-12-25 15:31:07 -08:00
|
|
|
import admin_user_index from './admin-user-index';
|
2022-01-10 14:17:52 -08:00
|
|
|
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-11-15 12:39:43 -08:00
|
|
|
import chat_message_lists from './chat-message-lists';
|
|
|
|
import chat_messages from './chat-messages';
|
2022-01-10 14:17:52 -08:00
|
|
|
import chats from './chats';
|
2020-03-27 13:59:38 -07:00
|
|
|
import compose from './compose';
|
2022-11-30 10:32:35 -08:00
|
|
|
import compose_event from './compose-event';
|
2022-01-10 14:17:52 -08:00
|
|
|
import contexts from './contexts';
|
|
|
|
import conversations from './conversations';
|
2022-11-15 12:39:43 -08:00
|
|
|
import custom_emojis from './custom-emojis';
|
|
|
|
import domain_lists from './domain-lists';
|
|
|
|
import dropdown_menu from './dropdown-menu';
|
2020-03-27 13:59:38 -07:00
|
|
|
import filters from './filters';
|
2023-07-02 04:19:27 -07:00
|
|
|
import followed_tags from './followed-tags';
|
2022-12-11 12:37:00 -08:00
|
|
|
import group_memberships from './group-memberships';
|
|
|
|
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-11-15 12:39:43 -08:00
|
|
|
import listAdder from './list-adder';
|
|
|
|
import listEditor from './list-editor';
|
2022-01-10 14:17:52 -08:00
|
|
|
import lists from './lists';
|
2022-08-30 13:26:42 -07:00
|
|
|
import locations from './locations';
|
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';
|
2023-06-25 10:37:37 -07:00
|
|
|
import patron from './patron';
|
2022-11-15 12:39:43 -08:00
|
|
|
import pending_statuses from './pending-statuses';
|
2022-01-10 14:17:52 -08:00
|
|
|
import polls from './polls';
|
2022-11-15 12:39:43 -08:00
|
|
|
import profile_hover_card from './profile-hover-card';
|
|
|
|
import push_notifications from './push-notifications';
|
2022-01-10 14:17:52 -08:00
|
|
|
import relationships from './relationships';
|
|
|
|
import reports from './reports';
|
2022-04-27 07:11:21 -07:00
|
|
|
import rules from './rules';
|
2022-11-15 12:39:43 -08: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-11-15 12:39:43 -08:00
|
|
|
import status_lists from './status-lists';
|
2022-01-10 14:17:52 -08:00
|
|
|
import statuses from './statuses';
|
|
|
|
import suggestions from './suggestions';
|
2023-01-19 06:06:17 -08:00
|
|
|
import tags from './tags';
|
2022-01-10 14:17:52 -08:00
|
|
|
import timelines from './timelines';
|
2022-11-15 12:39:43 -08:00
|
|
|
import trending_statuses from './trending-statuses';
|
2022-01-10 14:17:52 -08:00
|
|
|
import trends from './trends';
|
2022-11-15 12:39:43 -08:00
|
|
|
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 = {
|
2023-02-07 13:22:23 -08:00
|
|
|
accounts_meta,
|
|
|
|
admin,
|
|
|
|
admin_announcements,
|
|
|
|
admin_log,
|
|
|
|
admin_user_index,
|
|
|
|
aliases,
|
|
|
|
announcements,
|
|
|
|
auth,
|
|
|
|
backups,
|
|
|
|
chat_message_lists,
|
|
|
|
chat_messages,
|
|
|
|
chats,
|
2020-03-27 13:59:38 -07:00
|
|
|
compose,
|
2023-02-07 13:22:23 -08:00
|
|
|
compose_event,
|
|
|
|
contexts,
|
|
|
|
conversations,
|
2020-03-27 13:59:38 -07:00
|
|
|
custom_emojis,
|
2023-02-07 13:22:23 -08:00
|
|
|
domain_lists,
|
|
|
|
dropdown_menu,
|
2023-03-09 08:36:07 -08:00
|
|
|
entities,
|
2020-03-27 13:59:38 -07:00
|
|
|
filters,
|
2023-05-11 11:10:22 -07:00
|
|
|
followed_tags,
|
2023-02-07 13:22:23 -08:00
|
|
|
group_memberships,
|
|
|
|
group_relationships,
|
|
|
|
groups,
|
|
|
|
history,
|
2020-04-01 13:05:52 -07:00
|
|
|
instance,
|
2020-03-27 13:59:38 -07:00
|
|
|
listAdder,
|
2023-02-07 13:22:23 -08:00
|
|
|
listEditor,
|
|
|
|
lists,
|
2022-08-30 13:26:42 -07:00
|
|
|
locations,
|
2020-04-01 19:20:47 -07:00
|
|
|
me,
|
2023-02-07 13:22:23 -08:00
|
|
|
meta,
|
|
|
|
modals,
|
|
|
|
mutes,
|
|
|
|
notifications,
|
|
|
|
onboarding,
|
2023-06-25 10:37:37 -07:00
|
|
|
patron,
|
2023-02-07 13:22:23 -08:00
|
|
|
pending_statuses,
|
2020-03-27 13:59:38 -07:00
|
|
|
polls,
|
2020-09-10 17:09:27 -07:00
|
|
|
profile_hover_card,
|
2023-02-07 13:22:23 -08:00
|
|
|
push_notifications,
|
|
|
|
relationships,
|
|
|
|
reports,
|
|
|
|
rules,
|
2021-06-27 12:58:40 -07:00
|
|
|
scheduled_statuses,
|
2023-02-07 13:22:23 -08:00
|
|
|
search,
|
|
|
|
security,
|
|
|
|
settings,
|
2020-03-27 13:59:38 -07:00
|
|
|
sidebar,
|
2020-04-01 12:38:08 -07:00
|
|
|
soapbox,
|
2022-06-16 21:19:53 -07:00
|
|
|
status_hover_card,
|
2023-02-07 13:22:23 -08:00
|
|
|
status_lists,
|
|
|
|
statuses,
|
|
|
|
suggestions,
|
2023-05-02 14:32:43 -07:00
|
|
|
tags,
|
2023-02-07 13:22:23 -08:00
|
|
|
timelines,
|
2022-03-21 11:09:01 -07:00
|
|
|
trending_statuses,
|
2023-02-07 13:22:23 -08:00
|
|
|
trends,
|
|
|
|
user_lists,
|
2022-03-21 11:09:01 -07:00
|
|
|
verification,
|
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
|
|
|
};
|
|
|
|
|
2023-09-11 15:28:34 -07:00
|
|
|
export default rootReducer;
|