From ea2bb53379e726d235e289513505757da232b2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sun, 1 Jan 2023 23:21:05 +0100 Subject: [PATCH 1/4] Fix scheduled statuses page crashing on delete MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- .../scheduled-statuses/components/scheduled-status.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/soapbox/features/scheduled-statuses/components/scheduled-status.tsx b/app/soapbox/features/scheduled-statuses/components/scheduled-status.tsx index 1d1a68c94..cca79ffd4 100644 --- a/app/soapbox/features/scheduled-statuses/components/scheduled-status.tsx +++ b/app/soapbox/features/scheduled-statuses/components/scheduled-status.tsx @@ -20,7 +20,12 @@ interface IScheduledStatus { } const ScheduledStatus: React.FC = ({ statusId, ...other }) => { - const status = useAppSelector((state) => buildStatus(state, state.scheduled_statuses.get(statusId)!)) as StatusEntity; + const status = useAppSelector((state) => { + const scheduledStatus = state.scheduled_statuses.get(statusId); + + if (!scheduledStatus) return null; + return buildStatus(state, scheduledStatus); + }) as StatusEntity | null; if (!status) return null; From c7e140bf3f60da009c518d27301ef6cb848a18ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sun, 1 Jan 2023 23:46:47 +0100 Subject: [PATCH 2/4] Append scheduled statuses to status list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/reducers/status-lists.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/soapbox/reducers/status-lists.ts b/app/soapbox/reducers/status-lists.ts index eea737a05..38e19b009 100644 --- a/app/soapbox/reducers/status-lists.ts +++ b/app/soapbox/reducers/status-lists.ts @@ -12,6 +12,7 @@ import { STATUS_QUOTES_FETCH_REQUEST, STATUS_QUOTES_FETCH_SUCCESS, } from 'soapbox/actions/status-quotes'; +import { STATUS_CREATE_SUCCESS } from 'soapbox/actions/statuses'; import { BOOKMARKED_STATUSES_FETCH_REQUEST, @@ -66,7 +67,7 @@ import { } from '../actions/scheduled-statuses'; import type { AnyAction } from 'redux'; -import type { Status as StatusEntity } from 'soapbox/types/entities'; +import type { APIEntity } from 'soapbox/types/entities'; export const StatusListRecord = ImmutableRecord({ next: null as string | null, @@ -77,8 +78,6 @@ export const StatusListRecord = ImmutableRecord({ type State = ImmutableMap; type StatusList = ReturnType; -type Status = string | StatusEntity; -type Statuses = Array; const initialState: State = ImmutableMap({ favourites: StatusListRecord(), @@ -89,15 +88,15 @@ const initialState: State = ImmutableMap({ joined_events: StatusListRecord(), }); -const getStatusId = (status: string | StatusEntity) => typeof status === 'string' ? status : status.id; +const getStatusId = (status: string | APIEntity) => typeof status === 'string' ? status : status.id; -const getStatusIds = (statuses: Statuses = []) => ( +const getStatusIds = (statuses: APIEntity[] = []) => ( ImmutableOrderedSet(statuses.map(getStatusId)) ); const setLoading = (state: State, listType: string, loading: boolean) => state.setIn([listType, 'isLoading'], loading); -const normalizeList = (state: State, listType: string, statuses: Statuses, next: string | null) => { +const normalizeList = (state: State, listType: string, statuses: APIEntity[], next: string | null) => { return state.update(listType, StatusListRecord(), listMap => listMap.withMutations(map => { map.set('next', next); map.set('loaded', true); @@ -106,7 +105,7 @@ const normalizeList = (state: State, listType: string, statuses: Statuses, next: })); }; -const appendToList = (state: State, listType: string, statuses: Statuses, next: string | null) => { +const appendToList = (state: State, listType: string, statuses: APIEntity[], next: string | null) => { const newIds = getStatusIds(statuses); return state.update(listType, StatusListRecord(), listMap => listMap.withMutations(map => { @@ -116,18 +115,23 @@ const appendToList = (state: State, listType: string, statuses: Statuses, next: })); }; -const prependOneToList = (state: State, listType: string, status: Status) => { +const prependOneToList = (state: State, listType: string, status: APIEntity) => { const statusId = getStatusId(status); return state.updateIn([listType, 'items'], ImmutableOrderedSet(), items => { return ImmutableOrderedSet([statusId]).union(items as ImmutableOrderedSet); }); }; -const removeOneFromList = (state: State, listType: string, status: Status) => { +const removeOneFromList = (state: State, listType: string, status: APIEntity) => { const statusId = getStatusId(status); return state.updateIn([listType, 'items'], ImmutableOrderedSet(), items => (items as ImmutableOrderedSet).delete(statusId)); }; +const maybeAppendScheduledStatus = (state: State, status: APIEntity) => { + if (!status.scheduled_at) return state; + return prependOneToList(state, 'scheduled_statuses', getStatusId(status)); +}; + export default function statusLists(state = initialState, action: AnyAction) { switch (action.type) { case FAVOURITED_STATUSES_FETCH_REQUEST: @@ -209,6 +213,8 @@ export default function statusLists(state = initialState, action: AnyAction) { return setLoading(state, 'joined_events', false); case JOINED_EVENTS_FETCH_SUCCESS: return normalizeList(state, 'joined_events', action.statuses, action.next); + case STATUS_CREATE_SUCCESS: + return maybeAppendScheduledStatus(state, action.status); default: return state; } From 0001ea47dff0a5318bdc088fa2239f694838864b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sun, 1 Jan 2023 23:50:55 +0100 Subject: [PATCH 3/4] Set scheduled post date to 10 minutes after current time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/reducers/compose.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/soapbox/reducers/compose.ts b/app/soapbox/reducers/compose.ts index d321ec05e..18a1fdac2 100644 --- a/app/soapbox/reducers/compose.ts +++ b/app/soapbox/reducers/compose.ts @@ -455,7 +455,7 @@ export default function compose(state = initialState, action: AnyAction) { case COMPOSE_POLL_REMOVE: return updateCompose(state, action.id, compose => compose.set('poll', null)); case COMPOSE_SCHEDULE_ADD: - return updateCompose(state, action.id, compose => compose.set('schedule', new Date())); + return updateCompose(state, action.id, compose => compose.set('schedule', new Date(Date.now() + 10 * 60 * 1000))); case COMPOSE_SCHEDULE_SET: return updateCompose(state, action.id, compose => compose.set('schedule', action.date)); case COMPOSE_SCHEDULE_REMOVE: From 135b3c7ade109c7b1e086b4cbbb816e3d9ce2ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sun, 1 Jan 2023 23:31:31 +0000 Subject: [PATCH 4/4] Update file CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05162696f..5dfd256cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Layout: use accent color for "floating action button" (mobile compose button). - ServiceWorker: don't serve favicon, robots.txt, and others from ServiceWorker. - Datepicker: correctly default to the current year. +- Scheduled posts: fix page crashing on deleting a scheduled post. ## [3.0.0] - 2022-12-25