From 840706a5003a7002b7ede916415be80b7dc1f097 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 27 Jun 2021 14:58:40 -0500 Subject: [PATCH] ScheduledStatuses: import into reducer --- app/soapbox/reducers/index.js | 2 ++ app/soapbox/reducers/scheduled_statuses.js | 34 +++++----------------- app/soapbox/reducers/status_lists.js | 5 ++++ 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/app/soapbox/reducers/index.js b/app/soapbox/reducers/index.js index 48ddd77b8..751a04afb 100644 --- a/app/soapbox/reducers/index.js +++ b/app/soapbox/reducers/index.js @@ -52,6 +52,7 @@ import profile_hover_card from './profile_hover_card'; import backups from './backups'; import admin_log from './admin_log'; import security from './security'; +import scheduled_statuses from './scheduled_statuses'; const appReducer = combineReducers({ dropdown_menu, @@ -105,6 +106,7 @@ const appReducer = combineReducers({ backups, admin_log, security, + scheduled_statuses, }); // Clear the state (mostly) when the user logs out diff --git a/app/soapbox/reducers/scheduled_statuses.js b/app/soapbox/reducers/scheduled_statuses.js index 9441406aa..e2ab142e4 100644 --- a/app/soapbox/reducers/scheduled_statuses.js +++ b/app/soapbox/reducers/scheduled_statuses.js @@ -1,44 +1,24 @@ +import { STATUS_CREATE_SUCCESS } from 'soapbox/actions/statuses'; +import { STATUS_IMPORT, STATUSES_IMPORT } from '../actions/importer'; import { Map as ImmutableMap, fromJS } from 'immutable'; -const importStatus = (state, status) => state.set(status.id, fromJS(status)); +const importStatus = (state, status) => { + if (!status.scheduled_at) return state; + return state.set(status.id, fromJS(status)); +}; const importStatuses = (state, statuses) => state.withMutations(mutable => statuses.forEach(status => importStatus(mutable, status))); -const deleteStatus = (state, id, references) => { - references.forEach(ref => { - state = deleteStatus(state, ref[0], []); - }); - - return state.delete(id); -}; - const initialState = ImmutableMap(); export default function statuses(state = initialState, action) { switch(action.type) { case STATUS_IMPORT: + case STATUS_CREATE_SUCCESS: return importStatus(state, action.status); case STATUSES_IMPORT: return importStatuses(state, action.statuses); - case STATUS_REVEAL: - return state.withMutations(map => { - action.ids.forEach(id => { - if (!(state.get(id) === undefined)) { - map.setIn([id, 'hidden'], false); - } - }); - }); - case STATUS_HIDE: - return state.withMutations(map => { - action.ids.forEach(id => { - if (!(state.get(id) === undefined)) { - map.setIn([id, 'hidden'], true); - } - }); - }); - case TIMELINE_DELETE: - return deleteStatus(state, action.id, action.references); default: return state; } diff --git a/app/soapbox/reducers/status_lists.js b/app/soapbox/reducers/status_lists.js index 3471eca34..b5a96abe5 100644 --- a/app/soapbox/reducers/status_lists.js +++ b/app/soapbox/reducers/status_lists.js @@ -51,6 +51,11 @@ const initialState = ImmutableMap({ loaded: false, items: ImmutableList(), }), + scheduled_statuses: ImmutableMap({ + next: null, + loaded: false, + items: ImmutableList(), + }), }); const normalizeList = (state, listType, statuses, next) => {