Change drafts KVStore key

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-04-02 23:32:12 +02:00
parent 8c36432a06
commit 1265f99ef4
3 changed files with 29 additions and 15 deletions

View File

@ -1,5 +1,6 @@
import { v4 as uuid } from 'uuid';
import { makeGetAccount } from 'soapbox/selectors';
import KVStore from 'soapbox/storage/kv-store';
import type { AppDispatch, RootState } from 'soapbox/store';
@ -9,18 +10,25 @@ const DRAFT_STATUSES_FETCH_SUCCESS = 'DRAFT_STATUSES_FETCH_SUCCESS';
const PERSIST_DRAFT_STATUS = 'PERSIST_DRAFT_STATUS';
const CANCEL_DRAFT_STATUS = 'DELETE_DRAFT_STATUS';
const getAccount = makeGetAccount();
const fetchDraftStatuses = () =>
(dispatch: AppDispatch, getState: () => RootState) =>
KVStore.getItem(`drafts:${getState().me}`).then((statuses) => {
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const accountUrl = getAccount(state, state.me as string)!.url;
return KVStore.getItem(`drafts:${accountUrl}`).then((statuses) => {
dispatch({
type: DRAFT_STATUSES_FETCH_SUCCESS,
statuses,
});
}).catch(() => {});
};
const saveDraftStatus = (composeId: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const accountUrl = getAccount(state, state.me as string)!.url;
const compose = state.compose.get(composeId)!;
@ -32,17 +40,21 @@ const saveDraftStatus = (composeId: string) =>
dispatch({
type: PERSIST_DRAFT_STATUS,
status: draft,
accountId: state.me,
accountUrl,
});
};
const cancelDraftStatus = (id: string) =>
(dispatch: AppDispatch, getState: () => RootState) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const accountUrl = getAccount(state, state.me as string)!.url;
dispatch({
type: CANCEL_DRAFT_STATUS,
id,
accountId: getState().me,
accountUrl,
});
};
export {
DRAFT_STATUSES_FETCH_SUCCESS,