nicolium: migrate pins from redux
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@ -1,11 +0,0 @@
|
||||
const PIN_SUCCESS = 'PIN_SUCCESS' as const;
|
||||
|
||||
const UNPIN_SUCCESS = 'UNPIN_SUCCESS' as const;
|
||||
|
||||
type InteractionsAction = {
|
||||
type: typeof PIN_SUCCESS | typeof UNPIN_SUCCESS;
|
||||
statusId: string;
|
||||
accountId: string;
|
||||
};
|
||||
|
||||
export { PIN_SUCCESS, UNPIN_SUCCESS, type InteractionsAction };
|
||||
@ -9,8 +9,6 @@ import { create } from 'mutative';
|
||||
import { defineMessages, useIntl } from 'react-intl';
|
||||
|
||||
import { importEntities } from '@/actions/importer';
|
||||
import { PIN_SUCCESS, UNPIN_SUCCESS, type InteractionsAction } from '@/actions/interactions';
|
||||
import { useAppDispatch } from '@/hooks/use-app-dispatch';
|
||||
import { useClient } from '@/hooks/use-client';
|
||||
import { useFeatures } from '@/hooks/use-features';
|
||||
import { useOwnAccount } from '@/hooks/use-own-account';
|
||||
@ -429,7 +427,6 @@ const useUnbookmarkStatus = (statusId: string) => {
|
||||
|
||||
const usePinStatus = (statusId: string) => {
|
||||
const client = useClient();
|
||||
const dispatch = useAppDispatch();
|
||||
const queryClient = useQueryClient();
|
||||
const { data: account } = useOwnAccount();
|
||||
|
||||
@ -441,18 +438,12 @@ const usePinStatus = (statusId: string) => {
|
||||
onSuccess: (status) => {
|
||||
importEntities({ statuses: [status] });
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.statusLists.pins(account!.id) });
|
||||
dispatch<InteractionsAction>({
|
||||
type: PIN_SUCCESS,
|
||||
statusId: status.id,
|
||||
accountId: status.account.id,
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const useUnpinStatus = (statusId: string) => {
|
||||
const client = useClient();
|
||||
const dispatch = useAppDispatch();
|
||||
const queryClient = useQueryClient();
|
||||
const { data: account } = useOwnAccount();
|
||||
|
||||
@ -464,11 +455,6 @@ const useUnpinStatus = (statusId: string) => {
|
||||
onSuccess: (status) => {
|
||||
importEntities({ statuses: [status] });
|
||||
queryClient.setQueryData(queryKeys.statusLists.pins(account!.id), filterById(statusId));
|
||||
dispatch<InteractionsAction>({
|
||||
type: UNPIN_SUCCESS,
|
||||
statusId: status.id,
|
||||
accountId: status.account.id,
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@ -5,7 +5,6 @@ import {
|
||||
ACCOUNT_MUTE_SUCCESS,
|
||||
type AccountsAction,
|
||||
} from '@/actions/accounts';
|
||||
import { PIN_SUCCESS, UNPIN_SUCCESS, type InteractionsAction } from '@/actions/interactions';
|
||||
import {
|
||||
STATUS_CREATE_REQUEST,
|
||||
STATUS_CREATE_SUCCESS,
|
||||
@ -131,12 +130,6 @@ const expandNormalizedTimeline = (
|
||||
|
||||
if (!next) timeline.hasMore = false;
|
||||
|
||||
// Pinned timelines can be replaced entirely
|
||||
if (timelineId.endsWith(':pinned')) {
|
||||
timeline.items = newIds;
|
||||
return;
|
||||
}
|
||||
|
||||
if (newIds.length) {
|
||||
if (pos === 'end') {
|
||||
timeline.items = mergeStatusIds(newIds, timeline.items);
|
||||
@ -343,7 +336,7 @@ const handleExpandFail = (state: State, timelineId: string) => {
|
||||
|
||||
const timelines = (
|
||||
state: State = initialState,
|
||||
action: AccountsAction | InteractionsAction | StatusesAction | TimelineAction,
|
||||
action: AccountsAction | StatusesAction | TimelineAction,
|
||||
): State => {
|
||||
switch (action.type) {
|
||||
case STATUS_CREATE_REQUEST:
|
||||
@ -404,18 +397,6 @@ const timelines = (
|
||||
return create(state, (draft) => {
|
||||
updateTop(draft, action.timeline, action.top);
|
||||
});
|
||||
case PIN_SUCCESS:
|
||||
return create(state, (draft) => {
|
||||
updateTimeline(draft, `account:${action.accountId}:with_replies:pinned`, (timeline) => {
|
||||
timeline.items = [...new Set([action.statusId, ...timeline.items])];
|
||||
});
|
||||
});
|
||||
case UNPIN_SUCCESS:
|
||||
return create(state, (draft) => {
|
||||
updateTimeline(draft, `account:${action.accountId}:with_replies:pinned`, (timeline) => {
|
||||
timeline.items = timeline.items.filter((id) => id !== action.statusId);
|
||||
});
|
||||
});
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user