From 3ad916f71b744febfa6f51e236a9e275698efff8 Mon Sep 17 00:00:00 2001 From: LASER-Yi Date: Wed, 28 Jul 2021 22:36:17 +0800 Subject: [PATCH] Revert "Make wanted tabs update on demand" This reverts commit 90db37e04e7f8a21b78d6b7fa8d6fa684ba36fe8. --- frontend/src/@redux/actions/movie.ts | 6 ----- frontend/src/@redux/actions/series.ts | 6 ----- frontend/src/@redux/constants/index.ts | 2 -- frontend/src/@redux/hooks/index.ts | 26 ------------------- frontend/src/@redux/reducers/movie.ts | 8 ------ frontend/src/@redux/reducers/series.ts | 8 ------ frontend/src/@redux/utils/index.ts | 2 +- frontend/src/@redux/utils/mapper.ts | 20 +++----------- frontend/src/@socketio/reducer.ts | 20 +++++++++++--- .../src/components/tables/AsyncPageTable.tsx | 2 +- 10 files changed, 22 insertions(+), 78 deletions(-) diff --git a/frontend/src/@redux/actions/movie.ts b/frontend/src/@redux/actions/movie.ts index ce3797143..b76752cdc 100644 --- a/frontend/src/@redux/actions/movie.ts +++ b/frontend/src/@redux/actions/movie.ts @@ -1,10 +1,8 @@ -import { createAction } from "redux-actions"; import { createDeleteAction } from "../../@socketio/reducer"; import { MoviesApi } from "../../apis"; import { MOVIES_DELETE_ITEMS, MOVIES_DELETE_WANTED_ITEMS, - MOVIES_MARK_WANTED_LIST_DIRTY, MOVIES_UPDATE_BLACKLIST, MOVIES_UPDATE_HISTORY_LIST, MOVIES_UPDATE_LIST, @@ -28,10 +26,6 @@ export const movieDeleteWantedItems = createDeleteAction( MOVIES_DELETE_WANTED_ITEMS ); -export const movieMarkWantedListDirty = createAction( - MOVIES_MARK_WANTED_LIST_DIRTY -); - export const movieUpdateWantedByRange = createAsyncAction( MOVIES_UPDATE_WANTED_LIST, (start: number, length: number) => MoviesApi.wanted(start, length) diff --git a/frontend/src/@redux/actions/series.ts b/frontend/src/@redux/actions/series.ts index 9b7caef74..c53277469 100644 --- a/frontend/src/@redux/actions/series.ts +++ b/frontend/src/@redux/actions/series.ts @@ -1,11 +1,9 @@ -import { createAction } from "redux-actions"; import { createDeleteAction } from "../../@socketio/reducer"; import { EpisodesApi, SeriesApi } from "../../apis"; import { SERIES_DELETE_EPISODES, SERIES_DELETE_ITEMS, SERIES_DELETE_WANTED_ITEMS, - SERIES_MARK_WANTED_LIST_DIRTY, SERIES_UPDATE_BLACKLIST, SERIES_UPDATE_EPISODE_LIST, SERIES_UPDATE_HISTORY_LIST, @@ -23,10 +21,6 @@ export const seriesDeleteWantedItems = createDeleteAction( SERIES_DELETE_WANTED_ITEMS ); -export const seriesMarkWantedListDirty = createAction( - SERIES_MARK_WANTED_LIST_DIRTY -); - export const seriesUpdateWantedByRange = createAsyncAction( SERIES_UPDATE_WANTED_LIST, (start: number, length: number) => EpisodesApi.wanted(start, length) diff --git a/frontend/src/@redux/constants/index.ts b/frontend/src/@redux/constants/index.ts index b675297a5..a76476b1b 100644 --- a/frontend/src/@redux/constants/index.ts +++ b/frontend/src/@redux/constants/index.ts @@ -15,7 +15,6 @@ export const SYSTEM_UPDATE_PROVIDERS = "SYSTEM_UPDATE_PROVIDERS"; // Series action export const SERIES_UPDATE_WANTED_LIST = "UPDATE_SERIES_WANTED_LIST"; export const SERIES_DELETE_WANTED_ITEMS = "SERIES_DELETE_WANTED_ITEMS"; -export const SERIES_MARK_WANTED_LIST_DIRTY = "SERIES_MARK_WANTED_LIST_DIRTY"; export const SERIES_UPDATE_EPISODE_LIST = "UPDATE_SERIES_EPISODE_LIST"; export const SERIES_DELETE_EPISODES = "SERIES_DELETE_EPISODES"; export const SERIES_UPDATE_HISTORY_LIST = "UPDATE_SERIES_HISTORY_LIST"; @@ -26,7 +25,6 @@ export const SERIES_UPDATE_BLACKLIST = "UPDATE_SERIES_BLACKLIST"; // Movie action export const MOVIES_UPDATE_LIST = "UPDATE_MOVIE_LIST"; export const MOVIES_DELETE_ITEMS = "MOVIES_DELETE_ITEMS"; -export const MOVIES_MARK_WANTED_LIST_DIRTY = "MOVIES_MARK_WANTED_LIST_DIRTY"; export const MOVIES_UPDATE_WANTED_LIST = "UPDATE_MOVIE_WANTED_LIST"; export const MOVIES_DELETE_WANTED_ITEMS = "MOVIES_DELETE_WANTED_ITEMS"; export const MOVIES_UPDATE_HISTORY_LIST = "UPDATE_MOVIE_HISTORY_LIST"; diff --git a/frontend/src/@redux/hooks/index.ts b/frontend/src/@redux/hooks/index.ts index 364871a4f..ac15d5b21 100644 --- a/frontend/src/@redux/hooks/index.ts +++ b/frontend/src/@redux/hooks/index.ts @@ -5,13 +5,11 @@ import { episodeDeleteItems, episodeUpdateBy, episodeUpdateById, - movieDeleteWantedItems, movieUpdateBlacklist, movieUpdateHistoryList, movieUpdateList, movieUpdateWantedList, providerUpdateList, - seriesDeleteWantedItems, seriesUpdateBlacklist, seriesUpdateHistoryList, seriesUpdateList, @@ -324,18 +322,6 @@ export function useWantedSeries() { const update = useReduxAction(seriesUpdateWantedList); const items = useReduxStore((d) => d.series.wantedEpisodesList); - const updateAction = useWrapToOptionalId(update); - const deleteAction = useReduxAction(seriesDeleteWantedItems); - const reducer = useMemo( - () => ({ - key: "episode-wanted", - update: updateAction, - delete: deleteAction, - }), - [updateAction, deleteAction] - ); - useSocketIOReducer(reducer); - return stateBuilder(items, update); } @@ -343,18 +329,6 @@ export function useWantedMovies() { const update = useReduxAction(movieUpdateWantedList); const items = useReduxStore((d) => d.movie.wantedMovieList); - const updateAction = useWrapToOptionalId(update); - const deleteAction = useReduxAction(movieDeleteWantedItems); - const reducer = useMemo( - () => ({ - key: "movie-wanted", - update: updateAction, - delete: deleteAction, - }), - [updateAction, deleteAction] - ); - useSocketIOReducer(reducer); - return stateBuilder(items, update); } diff --git a/frontend/src/@redux/reducers/movie.ts b/frontend/src/@redux/reducers/movie.ts index 40c0a947f..2b7fe8df1 100644 --- a/frontend/src/@redux/reducers/movie.ts +++ b/frontend/src/@redux/reducers/movie.ts @@ -2,7 +2,6 @@ import { Action, handleActions } from "redux-actions"; import { MOVIES_DELETE_ITEMS, MOVIES_DELETE_WANTED_ITEMS, - MOVIES_MARK_WANTED_LIST_DIRTY, MOVIES_UPDATE_BLACKLIST, MOVIES_UPDATE_HISTORY_LIST, MOVIES_UPDATE_LIST, @@ -12,7 +11,6 @@ import { AsyncAction } from "../types"; import { defaultAOS } from "../utils"; import { deleteOrderListItemBy, - markOrderListDirty, updateAsyncState, updateOrderIdState, } from "../utils/mapper"; @@ -38,12 +36,6 @@ const reducer = handleActions( wantedMovieList: deleteOrderListItemBy(action, state.wantedMovieList), }; }, - [MOVIES_MARK_WANTED_LIST_DIRTY]: (state, action) => { - return { - ...state, - wantedMovieList: markOrderListDirty(state.wantedMovieList), - }; - }, [MOVIES_UPDATE_HISTORY_LIST]: ( state, action: AsyncAction diff --git a/frontend/src/@redux/reducers/series.ts b/frontend/src/@redux/reducers/series.ts index 8f72928ae..23ae4ecd6 100644 --- a/frontend/src/@redux/reducers/series.ts +++ b/frontend/src/@redux/reducers/series.ts @@ -3,7 +3,6 @@ import { SERIES_DELETE_EPISODES, SERIES_DELETE_ITEMS, SERIES_DELETE_WANTED_ITEMS, - SERIES_MARK_WANTED_LIST_DIRTY, SERIES_UPDATE_BLACKLIST, SERIES_UPDATE_EPISODE_LIST, SERIES_UPDATE_HISTORY_LIST, @@ -15,7 +14,6 @@ import { defaultAOS } from "../utils"; import { deleteAsyncListItemBy, deleteOrderListItemBy, - markOrderListDirty, updateAsyncList, updateAsyncState, updateOrderIdState, @@ -45,12 +43,6 @@ const reducer = handleActions( ), }; }, - [SERIES_MARK_WANTED_LIST_DIRTY]: (state, action) => { - return { - ...state, - wantedEpisodesList: markOrderListDirty(state.wantedEpisodesList), - }; - }, [SERIES_UPDATE_EPISODE_LIST]: ( state, action: AsyncAction diff --git a/frontend/src/@redux/utils/index.ts b/frontend/src/@redux/utils/index.ts index c269932da..e0e063f0d 100644 --- a/frontend/src/@redux/utils/index.ts +++ b/frontend/src/@redux/utils/index.ts @@ -4,7 +4,7 @@ export function defaultAOS(): AsyncOrderState { data: { items: [], order: [], - dirty: true, + dirty: false, }, }; } diff --git a/frontend/src/@redux/utils/mapper.ts b/frontend/src/@redux/utils/mapper.ts index 1236b2af9..772caa39a 100644 --- a/frontend/src/@redux/utils/mapper.ts +++ b/frontend/src/@redux/utils/mapper.ts @@ -36,7 +36,7 @@ export function updateOrderIdState( return { data: { ...state.data, - dirty: false, + dirty: true, }, updating: true, }; @@ -44,7 +44,7 @@ export function updateOrderIdState( return { data: { ...state.data, - dirty: false, + dirty: true, }, updating: false, error: action.payload.item as Error, @@ -107,7 +107,7 @@ export function updateOrderIdState( return { updating: false, data: { - dirty: false, + dirty: true, items: newItems, order: newOrder, }, @@ -131,25 +131,13 @@ export function deleteOrderListItemBy( return { ...state, data: { - dirty: false, + dirty: true, items: newItems, order: newOrder, }, }; } -export function markOrderListDirty( - state: AsyncOrderState -): AsyncOrderState { - return { - ...state, - data: { - ...state.data, - dirty: true, - }, - }; -} - export function deleteAsyncListItemBy( action: Action, state: AsyncState, diff --git a/frontend/src/@socketio/reducer.ts b/frontend/src/@socketio/reducer.ts index 4585592c3..5ea5fba94 100644 --- a/frontend/src/@socketio/reducer.ts +++ b/frontend/src/@socketio/reducer.ts @@ -3,11 +3,13 @@ import { badgeUpdateAll, bootstrap, movieDeleteItems, - movieMarkWantedListDirty, + movieDeleteWantedItems, movieUpdateList, + movieUpdateWantedList, seriesDeleteItems, - seriesMarkWantedListDirty, + seriesDeleteWantedItems, seriesUpdateList, + seriesUpdateWantedList, siteAddNotifications, siteAddProgress, siteInitializationFailed, @@ -95,11 +97,21 @@ export function createDefaultReducer(): SocketIO.Reducer[] { }, { key: "episode-wanted", - any: bindToReduxStore(seriesMarkWantedListDirty), + update: (ids: number[] | undefined) => { + if (ids) { + reduxStore.dispatch(seriesUpdateWantedList(ids) as any); + } + }, + delete: bindToReduxStore(seriesDeleteWantedItems), }, { key: "movie-wanted", - any: bindToReduxStore(movieMarkWantedListDirty), + update: (ids: number[] | undefined) => { + if (ids) { + reduxStore.dispatch(movieUpdateWantedList(ids) as any); + } + }, + delete: bindToReduxStore(movieDeleteWantedItems), }, { key: "settings", diff --git a/frontend/src/components/tables/AsyncPageTable.tsx b/frontend/src/components/tables/AsyncPageTable.tsx index 2af0809dc..54bb969c9 100644 --- a/frontend/src/components/tables/AsyncPageTable.tsx +++ b/frontend/src/components/tables/AsyncPageTable.tsx @@ -85,7 +85,7 @@ export default function AsyncPageTable(props: Props) { }, [pageIndex]); useEffect(() => { - const needFetch = visibleItemIds.length === 0 || dirty === true; + const needFetch = visibleItemIds.length === 0 && dirty === false; const needRefresh = !visibleItemIds.every(isNonNullable); if (needFetch || needRefresh) { loader(pageStart, pageSize);