Change drafts KVStore key
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
8c36432a06
commit
1265f99ef4
3 changed files with 29 additions and 15 deletions
|
@ -7,7 +7,7 @@ import api from 'soapbox/api';
|
||||||
import { isNativeEmoji } from 'soapbox/features/emoji';
|
import { isNativeEmoji } from 'soapbox/features/emoji';
|
||||||
import emojiSearch from 'soapbox/features/emoji/search';
|
import emojiSearch from 'soapbox/features/emoji/search';
|
||||||
import { normalizeTag } from 'soapbox/normalizers';
|
import { normalizeTag } from 'soapbox/normalizers';
|
||||||
import { selectAccount, selectOwnAccount } from 'soapbox/selectors';
|
import { selectAccount, selectOwnAccount, makeGetAccount } from 'soapbox/selectors';
|
||||||
import { tagHistory } from 'soapbox/settings';
|
import { tagHistory } from 'soapbox/settings';
|
||||||
import toast from 'soapbox/toast';
|
import toast from 'soapbox/toast';
|
||||||
import { isLoggedIn } from 'soapbox/utils/auth';
|
import { isLoggedIn } from 'soapbox/utils/auth';
|
||||||
|
@ -89,6 +89,8 @@ const COMPOSE_SET_STATUS = 'COMPOSE_SET_STATUS' as const;
|
||||||
|
|
||||||
const COMPOSE_EDITOR_STATE_SET = 'COMPOSE_EDITOR_STATE_SET' as const;
|
const COMPOSE_EDITOR_STATE_SET = 'COMPOSE_EDITOR_STATE_SET' as const;
|
||||||
|
|
||||||
|
const getAccount = makeGetAccount();
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
scheduleError: { id: 'compose.invalid_schedule', defaultMessage: 'You must schedule a post at least 5 minutes out.' },
|
scheduleError: { id: 'compose.invalid_schedule', defaultMessage: 'You must schedule a post at least 5 minutes out.' },
|
||||||
success: { id: 'compose.submit_success', defaultMessage: 'Your post was sent!' },
|
success: { id: 'compose.submit_success', defaultMessage: 'Your post was sent!' },
|
||||||
|
@ -279,11 +281,11 @@ const handleComposeSubmit = (dispatch: AppDispatch, getState: () => RootState, c
|
||||||
|
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
|
||||||
const me = state.me as string;
|
const accountUrl = getAccount(state, state.me as string)!.url;
|
||||||
const draftId = getState().compose.get(composeId)!.draft_id;
|
const draftId = getState().compose.get(composeId)!.draft_id;
|
||||||
|
|
||||||
dispatch(insertIntoTagHistory(composeId, data.tags || [], status));
|
dispatch(insertIntoTagHistory(composeId, data.tags || [], status));
|
||||||
dispatch(submitComposeSuccess(composeId, { ...data }, me, draftId));
|
dispatch(submitComposeSuccess(composeId, { ...data }, accountUrl, draftId));
|
||||||
toast.success(edit ? messages.editSuccess : messages.success, {
|
toast.success(edit ? messages.editSuccess : messages.success, {
|
||||||
actionLabel: messages.view,
|
actionLabel: messages.view,
|
||||||
actionLink: `/@${data.account.acct}/posts/${data.id}`,
|
actionLink: `/@${data.account.acct}/posts/${data.id}`,
|
||||||
|
@ -391,11 +393,11 @@ const submitComposeRequest = (composeId: string) => ({
|
||||||
id: composeId,
|
id: composeId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const submitComposeSuccess = (composeId: string, status: APIEntity, accountId: string, draftId?: string | null) => ({
|
const submitComposeSuccess = (composeId: string, status: APIEntity, accountUrl: string, draftId?: string | null) => ({
|
||||||
type: COMPOSE_SUBMIT_SUCCESS,
|
type: COMPOSE_SUBMIT_SUCCESS,
|
||||||
id: composeId,
|
id: composeId,
|
||||||
status: status,
|
status: status,
|
||||||
accountId,
|
accountUrl,
|
||||||
draftId,
|
draftId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
|
|
||||||
|
import { makeGetAccount } from 'soapbox/selectors';
|
||||||
import KVStore from 'soapbox/storage/kv-store';
|
import KVStore from 'soapbox/storage/kv-store';
|
||||||
|
|
||||||
import type { AppDispatch, RootState } from 'soapbox/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 PERSIST_DRAFT_STATUS = 'PERSIST_DRAFT_STATUS';
|
||||||
const CANCEL_DRAFT_STATUS = 'DELETE_DRAFT_STATUS';
|
const CANCEL_DRAFT_STATUS = 'DELETE_DRAFT_STATUS';
|
||||||
|
|
||||||
|
const getAccount = makeGetAccount();
|
||||||
|
|
||||||
const fetchDraftStatuses = () =>
|
const fetchDraftStatuses = () =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) =>
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
KVStore.getItem(`drafts:${getState().me}`).then((statuses) => {
|
const state = getState();
|
||||||
|
const accountUrl = getAccount(state, state.me as string)!.url;
|
||||||
|
|
||||||
|
return KVStore.getItem(`drafts:${accountUrl}`).then((statuses) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: DRAFT_STATUSES_FETCH_SUCCESS,
|
type: DRAFT_STATUSES_FETCH_SUCCESS,
|
||||||
statuses,
|
statuses,
|
||||||
});
|
});
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
|
};
|
||||||
|
|
||||||
const saveDraftStatus = (composeId: string) =>
|
const saveDraftStatus = (composeId: string) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
const accountUrl = getAccount(state, state.me as string)!.url;
|
||||||
|
|
||||||
const compose = state.compose.get(composeId)!;
|
const compose = state.compose.get(composeId)!;
|
||||||
|
|
||||||
|
@ -32,17 +40,21 @@ const saveDraftStatus = (composeId: string) =>
|
||||||
dispatch({
|
dispatch({
|
||||||
type: PERSIST_DRAFT_STATUS,
|
type: PERSIST_DRAFT_STATUS,
|
||||||
status: draft,
|
status: draft,
|
||||||
accountId: state.me,
|
accountUrl,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const cancelDraftStatus = (id: string) =>
|
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({
|
dispatch({
|
||||||
type: CANCEL_DRAFT_STATUS,
|
type: CANCEL_DRAFT_STATUS,
|
||||||
id,
|
id,
|
||||||
accountId: getState().me,
|
accountUrl,
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
DRAFT_STATUSES_FETCH_SUCCESS,
|
DRAFT_STATUSES_FETCH_SUCCESS,
|
||||||
|
|
|
@ -43,8 +43,8 @@ const deleteStatus = (state: State, id: string) => {
|
||||||
return state;
|
return state;
|
||||||
};
|
};
|
||||||
|
|
||||||
const persistState = (state: State, accountId: string) => {
|
const persistState = (state: State, accountUrl: string) => {
|
||||||
KVStore.setItem(`drafts:${accountId}`, state.toJS());
|
KVStore.setItem(`drafts:${accountUrl}`, state.toJS());
|
||||||
return state;
|
return state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,11 +53,11 @@ export default function scheduled_statuses(state: State = initialState, action:
|
||||||
case DRAFT_STATUSES_FETCH_SUCCESS:
|
case DRAFT_STATUSES_FETCH_SUCCESS:
|
||||||
return importStatuses(state, action.statuses);
|
return importStatuses(state, action.statuses);
|
||||||
case PERSIST_DRAFT_STATUS:
|
case PERSIST_DRAFT_STATUS:
|
||||||
return persistState(importStatus(state, action.status), action.accountId);
|
return persistState(importStatus(state, action.status), action.accountUrl);
|
||||||
case CANCEL_DRAFT_STATUS:
|
case CANCEL_DRAFT_STATUS:
|
||||||
return persistState(deleteStatus(state, action.id), action.accountId);
|
return persistState(deleteStatus(state, action.id), action.accountUrl);
|
||||||
case COMPOSE_SUBMIT_SUCCESS:
|
case COMPOSE_SUBMIT_SUCCESS:
|
||||||
return persistState(deleteStatus(state, action.draftId), action.accountId);
|
return persistState(deleteStatus(state, action.draftId), action.accountUrl);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue