Change drafts KVStore key
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user