summaryrefslogtreecommitdiffhomepage
path: root/frontend
diff options
context:
space:
mode:
authorLASER-Yi <[email protected]>2021-08-30 10:05:54 +0800
committerLASER-Yi <[email protected]>2021-08-30 10:05:54 +0800
commit2ed054f41b0db2314b23278d4a037fbadd59fc73 (patch)
treef7e766de8918d56fdd1bdf315b9b8087e6d238a0 /frontend
parent0e9cd7d05fd2a9492d61cb552204c08254c0b470 (diff)
downloadbazarr-2ed054f41b0db2314b23278d4a037fbadd59fc73.tar.gz
bazarr-2ed054f41b0db2314b23278d4a037fbadd59fc73.zip
no log: Handle "reset-*-wanted" events
Diffstat (limited to 'frontend')
-rw-r--r--frontend/src/@modules/socketio/reducer.ts16
-rw-r--r--frontend/src/@modules/socketio/socket.d.ts2
-rw-r--r--frontend/src/@redux/__tests__/entity-reducer.test.ts10
-rw-r--r--frontend/src/@redux/actions/movie.ts4
-rw-r--r--frontend/src/@redux/actions/series.ts4
-rw-r--r--frontend/src/@redux/reducers/movie.ts4
-rw-r--r--frontend/src/@redux/reducers/series.ts4
-rw-r--r--frontend/src/@redux/utils/factory.ts14
8 files changed, 55 insertions, 3 deletions
diff --git a/frontend/src/@modules/socketio/reducer.ts b/frontend/src/@modules/socketio/reducer.ts
index 6aa684285..13e2f2459 100644
--- a/frontend/src/@modules/socketio/reducer.ts
+++ b/frontend/src/@modules/socketio/reducer.ts
@@ -3,15 +3,19 @@ import {
episodesMarkBlacklistDirty,
episodesMarkDirtyById,
episodesRemoveById,
+ episodesResetHistory,
movieMarkBlacklistDirty,
movieMarkDirtyById,
movieMarkWantedDirtyById,
movieRemoveById,
movieRemoveWantedById,
+ movieResetHistory,
+ movieResetWanted,
seriesMarkDirtyById,
seriesMarkWantedDirtyById,
seriesRemoveById,
seriesRemoveWantedById,
+ seriesResetWanted,
siteAddNotifications,
siteAddProgress,
siteBootstrap,
@@ -124,7 +128,7 @@ export function createDefaultReducer(): SocketIO.Reducer[] {
},
{
key: "movie-history",
- // any: bindReduxAction(movieMarkHistoryDirty),
+ any: bindReduxAction(movieResetHistory),
},
{
key: "movie-blacklist",
@@ -132,13 +136,21 @@ export function createDefaultReducer(): SocketIO.Reducer[] {
},
{
key: "episode-history",
- // any: bindReduxAction(episodesMarkHistoryDirty),
+ any: bindReduxAction(episodesResetHistory),
},
{
key: "episode-blacklist",
any: bindReduxAction(episodesMarkBlacklistDirty),
},
{
+ key: "reset-episode-wanted",
+ any: bindReduxAction(seriesResetWanted),
+ },
+ {
+ key: "reset-movie-wanted",
+ any: bindReduxAction(movieResetWanted),
+ },
+ {
key: "task",
any: bindReduxAction(systemMarkTasksDirty),
},
diff --git a/frontend/src/@modules/socketio/socket.d.ts b/frontend/src/@modules/socketio/socket.d.ts
index 77a1179cd..7e35c9ceb 100644
--- a/frontend/src/@modules/socketio/socket.d.ts
+++ b/frontend/src/@modules/socketio/socket.d.ts
@@ -16,6 +16,8 @@ declare namespace SocketIO {
| "episode-history"
| "movie-blacklist"
| "movie-history"
+ | "reset-episode-wanted"
+ | "reset-movie-wanted"
| "badges"
| "task"
| "settings"
diff --git a/frontend/src/@redux/__tests__/entity-reducer.test.ts b/frontend/src/@redux/__tests__/entity-reducer.test.ts
index b380dff98..cf1be21c3 100644
--- a/frontend/src/@redux/__tests__/entity-reducer.test.ts
+++ b/frontend/src/@redux/__tests__/entity-reducer.test.ts
@@ -124,6 +124,7 @@ const rangeRejected = createAsyncThunk(
);
const removeIds = createAction<number[]>("remove/id");
const dirty = createAction<number[]>("dirty/id");
+const reset = createAction("reset");
const reducer = createReducer(defaultState, (builder) => {
createAsyncEntityReducer(builder, (s) => s.entities, {
@@ -132,6 +133,7 @@ const reducer = createReducer(defaultState, (builder) => {
ids: idsResolved,
dirty,
removeIds,
+ reset,
});
createAsyncEntityReducer(builder, (s) => s.entities, {
all: allRejected,
@@ -197,6 +199,14 @@ it("entity update all rejected", async () => {
});
});
+it("entity reset", async () => {
+ await store.dispatch(allResolved());
+ store.dispatch(reset());
+ use((entities) => {
+ expect(entities).toEqual(defaultState.entities);
+ });
+});
+
it("entity mark dirty", async () => {
await store.dispatch(allResolved());
diff --git a/frontend/src/@redux/actions/movie.ts b/frontend/src/@redux/actions/movie.ts
index af9aa4c1b..d37dcfdcb 100644
--- a/frontend/src/@redux/actions/movie.ts
+++ b/frontend/src/@redux/actions/movie.ts
@@ -43,6 +43,8 @@ export const movieRemoveWantedById = createAction<number[]>(
"movies/wanted/remove/id"
);
+export const movieResetWanted = createAction("movies/wanted/reset");
+
export const movieMarkWantedDirtyById = createAction<number[]>(
"movies/wanted/mark_dirty/id"
);
@@ -67,6 +69,8 @@ export const movieMarkHistoryDirty = createAction<number[]>(
"movies/history/mark_dirty"
);
+export const movieResetHistory = createAction("movie/history/reset");
+
export const movieUpdateBlacklist = createAsyncThunk(
"movies/blacklist/update",
async () => {
diff --git a/frontend/src/@redux/actions/series.ts b/frontend/src/@redux/actions/series.ts
index a9ab035a6..cc80780f2 100644
--- a/frontend/src/@redux/actions/series.ts
+++ b/frontend/src/@redux/actions/series.ts
@@ -21,6 +21,8 @@ export const seriesRemoveWantedById = createAction<number[]>(
"series/wanted/remove/id"
);
+export const seriesResetWanted = createAction("series/wanted/reset");
+
export const seriesMarkWantedDirtyById = createAction<number[]>(
"series/wanted/mark_dirty/episode_id"
);
@@ -89,6 +91,8 @@ export const episodesMarkHistoryDirty = createAction<number[]>(
"episodes/history/update"
);
+export const episodesResetHistory = createAction("episodes/history/reset");
+
export const episodesUpdateBlacklist = createAsyncThunk(
"episodes/blacklist/update",
async () => {
diff --git a/frontend/src/@redux/reducers/movie.ts b/frontend/src/@redux/reducers/movie.ts
index 78ad5e86c..9ec47abbc 100644
--- a/frontend/src/@redux/reducers/movie.ts
+++ b/frontend/src/@redux/reducers/movie.ts
@@ -6,6 +6,8 @@ import {
movieMarkWantedDirtyById,
movieRemoveById,
movieRemoveWantedById,
+ movieResetHistory,
+ movieResetWanted,
movieUpdateAll,
movieUpdateBlacklist,
movieUpdateById,
@@ -48,11 +50,13 @@ const reducer = createReducer(defaultMovie, (builder) => {
ids: movieUpdateWantedById,
removeIds: movieRemoveWantedById,
dirty: movieMarkWantedDirtyById,
+ reset: movieResetWanted,
});
createAsyncEntityReducer(builder, (s) => s.historyList, {
range: movieUpdateHistoryByRange,
dirty: movieMarkHistoryDirty,
+ reset: movieResetHistory,
});
createAsyncItemReducer(builder, (s) => s.blacklist, {
diff --git a/frontend/src/@redux/reducers/series.ts b/frontend/src/@redux/reducers/series.ts
index 1ce6dbc25..88266dbd1 100644
--- a/frontend/src/@redux/reducers/series.ts
+++ b/frontend/src/@redux/reducers/series.ts
@@ -4,6 +4,7 @@ import {
episodesMarkDirtyById,
episodesMarkHistoryDirty,
episodesRemoveById,
+ episodesResetHistory,
episodesUpdateBlacklist,
episodesUpdateHistoryByRange,
episodeUpdateById,
@@ -12,6 +13,7 @@ import {
seriesMarkWantedDirtyById,
seriesRemoveById,
seriesRemoveWantedById,
+ seriesResetWanted,
seriesUpdateAll,
seriesUpdateById,
seriesUpdateByRange,
@@ -70,11 +72,13 @@ const reducer = createReducer(defaultSeries, (builder) => {
ids: seriesUpdateWantedById,
removeIds: seriesRemoveWantedById,
dirty: seriesMarkWantedDirtyById,
+ reset: seriesResetWanted,
});
createAsyncEntityReducer(builder, (s) => s.historyList, {
range: episodesUpdateHistoryByRange,
dirty: episodesMarkHistoryDirty,
+ reset: episodesResetHistory,
});
createAsyncItemReducer(builder, (s) => s.blacklist, {
diff --git a/frontend/src/@redux/utils/factory.ts b/frontend/src/@redux/utils/factory.ts
index 46184dca4..5a362d280 100644
--- a/frontend/src/@redux/utils/factory.ts
+++ b/frontend/src/@redux/utils/factory.ts
@@ -22,6 +22,7 @@ interface ActionParam<T, ID = null> {
all?: AsyncThunk<T, void, {}>;
ids?: AsyncThunk<T, ID[], {}>;
removeIds?: ActionCreatorWithPayload<ID[]>;
+ reset?: ActionCreatorWithoutPayload;
dirty?: ID extends null
? ActionCreatorWithoutPayload
: ActionCreatorWithPayload<ID[]>;
@@ -154,7 +155,7 @@ export function createAsyncEntityReducer<S, T, ID extends Async.IdType>(
getEntity: (state: Draft<S>) => Draft<Async.Entity<T>>,
actions: ActionParam<AsyncDataWrapper<T>, ID>
) {
- const { all, removeIds, ids, range, dirty } = actions;
+ const { all, removeIds, ids, range, dirty, reset } = actions;
const checkSizeUpdate = (entity: Draft<Async.Entity<T>>, newSize: number) => {
if (entity.content.ids.length !== newSize) {
@@ -324,4 +325,15 @@ export function createAsyncEntityReducer<S, T, ID extends Async.IdType>(
const entity = getEntity(state);
ReducerUtility.markDirty(entity, action.payload.map(String));
});
+
+ reset &&
+ builder.addCase(reset, (state) => {
+ const entity = getEntity(state);
+ entity.content.entities = {};
+ entity.content.ids = [];
+ entity.didLoaded = [];
+ entity.dirtyEntities = [];
+ entity.error = null;
+ entity.state = "uninitialized";
+ });
}