Skip to content

Commit

Permalink
Revert "Make wanted tabs update on demand"
Browse files Browse the repository at this point in the history
This reverts commit 90db37e.
  • Loading branch information
LASER-Yi committed Jul 28, 2021
1 parent 90db37e commit 3ad916f
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 78 deletions.
6 changes: 0 additions & 6 deletions 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,
Expand All @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions 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,
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/@redux/constants/index.ts
Expand Up @@ -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";
Expand All @@ -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";
Expand Down
26 changes: 0 additions & 26 deletions frontend/src/@redux/hooks/index.ts
Expand Up @@ -5,13 +5,11 @@ import {
episodeDeleteItems,
episodeUpdateBy,
episodeUpdateById,
movieDeleteWantedItems,
movieUpdateBlacklist,
movieUpdateHistoryList,
movieUpdateList,
movieUpdateWantedList,
providerUpdateList,
seriesDeleteWantedItems,
seriesUpdateBlacklist,
seriesUpdateHistoryList,
seriesUpdateList,
Expand Down Expand Up @@ -324,37 +322,13 @@ 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<SocketIO.Reducer>(
() => ({
key: "episode-wanted",
update: updateAction,
delete: deleteAction,
}),
[updateAction, deleteAction]
);
useSocketIOReducer(reducer);

return stateBuilder(items, update);
}

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<SocketIO.Reducer>(
() => ({
key: "movie-wanted",
update: updateAction,
delete: deleteAction,
}),
[updateAction, deleteAction]
);
useSocketIOReducer(reducer);

return stateBuilder(items, update);
}

Expand Down
8 changes: 0 additions & 8 deletions frontend/src/@redux/reducers/movie.ts
Expand Up @@ -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,
Expand All @@ -12,7 +11,6 @@ import { AsyncAction } from "../types";
import { defaultAOS } from "../utils";
import {
deleteOrderListItemBy,
markOrderListDirty,
updateAsyncState,
updateOrderIdState,
} from "../utils/mapper";
Expand All @@ -38,12 +36,6 @@ const reducer = handleActions<ReduxStore.Movie, any>(
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<History.Movie[]>
Expand Down
8 changes: 0 additions & 8 deletions frontend/src/@redux/reducers/series.ts
Expand Up @@ -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,
Expand All @@ -15,7 +14,6 @@ import { defaultAOS } from "../utils";
import {
deleteAsyncListItemBy,
deleteOrderListItemBy,
markOrderListDirty,
updateAsyncList,
updateAsyncState,
updateOrderIdState,
Expand Down Expand Up @@ -45,12 +43,6 @@ const reducer = handleActions<ReduxStore.Series, any>(
),
};
},
[SERIES_MARK_WANTED_LIST_DIRTY]: (state, action) => {
return {
...state,
wantedEpisodesList: markOrderListDirty(state.wantedEpisodesList),
};
},
[SERIES_UPDATE_EPISODE_LIST]: (
state,
action: AsyncAction<Item.Episode[]>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/@redux/utils/index.ts
Expand Up @@ -4,7 +4,7 @@ export function defaultAOS(): AsyncOrderState<any> {
data: {
items: [],
order: [],
dirty: true,
dirty: false,
},
};
}
20 changes: 4 additions & 16 deletions frontend/src/@redux/utils/mapper.ts
Expand Up @@ -36,15 +36,15 @@ export function updateOrderIdState<T extends LooseObject>(
return {
data: {
...state.data,
dirty: false,
dirty: true,
},
updating: true,
};
} else if (action.error !== undefined) {
return {
data: {
...state.data,
dirty: false,
dirty: true,
},
updating: false,
error: action.payload.item as Error,
Expand Down Expand Up @@ -107,7 +107,7 @@ export function updateOrderIdState<T extends LooseObject>(
return {
updating: false,
data: {
dirty: false,
dirty: true,
items: newItems,
order: newOrder,
},
Expand All @@ -131,25 +131,13 @@ export function deleteOrderListItemBy<T extends LooseObject>(
return {
...state,
data: {
dirty: false,
dirty: true,
items: newItems,
order: newOrder,
},
};
}

export function markOrderListDirty(
state: AsyncOrderState<any>
): AsyncOrderState<any> {
return {
...state,
data: {
...state.data,
dirty: true,
},
};
}

export function deleteAsyncListItemBy<T extends LooseObject>(
action: Action<number[]>,
state: AsyncState<T[]>,
Expand Down
20 changes: 16 additions & 4 deletions frontend/src/@socketio/reducer.ts
Expand Up @@ -3,11 +3,13 @@ import {
badgeUpdateAll,
bootstrap,
movieDeleteItems,
movieMarkWantedListDirty,
movieDeleteWantedItems,
movieUpdateList,
movieUpdateWantedList,
seriesDeleteItems,
seriesMarkWantedListDirty,
seriesDeleteWantedItems,
seriesUpdateList,
seriesUpdateWantedList,
siteAddNotifications,
siteAddProgress,
siteInitializationFailed,
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/tables/AsyncPageTable.tsx
Expand Up @@ -85,7 +85,7 @@ export default function AsyncPageTable<T extends object>(props: Props<T>) {
}, [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);
Expand Down

0 comments on commit 3ad916f

Please sign in to comment.