mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-21 18:13:55 +00:00
first commit
This commit is contained in:
49
src/renderer/features/download-slice.ts
Normal file
49
src/renderer/features/download-slice.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import type { PayloadAction } from "@reduxjs/toolkit";
|
||||
import type { TorrentProgress } from "@types";
|
||||
|
||||
interface DownloadState {
|
||||
packets: TorrentProgress[];
|
||||
gameId: number | null;
|
||||
gamesWithDeletionInProgress: number[];
|
||||
}
|
||||
|
||||
const initialState: DownloadState = {
|
||||
packets: [],
|
||||
gameId: null,
|
||||
gamesWithDeletionInProgress: [],
|
||||
};
|
||||
|
||||
export const downloadSlice = createSlice({
|
||||
name: "download",
|
||||
initialState,
|
||||
reducers: {
|
||||
addPacket: (state, action: PayloadAction<TorrentProgress>) => {
|
||||
state.packets = [...state.packets, action.payload];
|
||||
if (!state.gameId) state.gameId = action.payload.game.id;
|
||||
},
|
||||
clearDownload: (state) => {
|
||||
state.packets = [];
|
||||
state.gameId = null;
|
||||
},
|
||||
setGameDeleting: (state, action: PayloadAction<number>) => {
|
||||
if (
|
||||
!state.gamesWithDeletionInProgress.includes(action.payload) &&
|
||||
action.payload
|
||||
) {
|
||||
state.gamesWithDeletionInProgress.push(action.payload);
|
||||
}
|
||||
},
|
||||
removeGameFromDeleting: (state, action: PayloadAction<number>) => {
|
||||
const index = state.gamesWithDeletionInProgress.indexOf(action.payload);
|
||||
if (index >= 0) state.gamesWithDeletionInProgress.splice(index, 1);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const {
|
||||
addPacket,
|
||||
clearDownload,
|
||||
setGameDeleting,
|
||||
removeGameFromDeleting,
|
||||
} = downloadSlice.actions;
|
||||
6
src/renderer/features/index.ts
Normal file
6
src/renderer/features/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export * from "./search-slice";
|
||||
export * from "./repackers-friendly-names-slice";
|
||||
export * from "./library-slice";
|
||||
export * from "./use-preferences-slice";
|
||||
export * from "./download-slice";
|
||||
export * from "./window-slice";
|
||||
24
src/renderer/features/library-slice.ts
Normal file
24
src/renderer/features/library-slice.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import type { PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
import type { Game } from "@types";
|
||||
|
||||
interface LibraryState {
|
||||
value: Game[];
|
||||
}
|
||||
|
||||
const initialState: LibraryState = {
|
||||
value: [],
|
||||
};
|
||||
|
||||
export const librarySlice = createSlice({
|
||||
name: "library",
|
||||
initialState,
|
||||
reducers: {
|
||||
setLibrary: (state, action: PayloadAction<LibraryState["value"]>) => {
|
||||
state.value = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setLibrary } = librarySlice.actions;
|
||||
26
src/renderer/features/repackers-friendly-names-slice.ts
Normal file
26
src/renderer/features/repackers-friendly-names-slice.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import type { PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
interface RepackersFriendlyNamesState {
|
||||
value: Record<string, string>;
|
||||
}
|
||||
|
||||
const initialState: RepackersFriendlyNamesState = {
|
||||
value: {},
|
||||
};
|
||||
|
||||
export const repackersFriendlyNamesSlice = createSlice({
|
||||
name: "repackersFriendlyNames",
|
||||
initialState,
|
||||
reducers: {
|
||||
setRepackersFriendlyNames: (
|
||||
state,
|
||||
action: PayloadAction<RepackersFriendlyNamesState["value"]>
|
||||
) => {
|
||||
state.value = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setRepackersFriendlyNames } =
|
||||
repackersFriendlyNamesSlice.actions;
|
||||
25
src/renderer/features/search-slice.ts
Normal file
25
src/renderer/features/search-slice.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import type { PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
interface SearchState {
|
||||
value: string;
|
||||
}
|
||||
|
||||
const initialState: SearchState = {
|
||||
value: "",
|
||||
};
|
||||
|
||||
export const searchSlice = createSlice({
|
||||
name: "search",
|
||||
initialState,
|
||||
reducers: {
|
||||
setSearch: (state, action: PayloadAction<string>) => {
|
||||
state.value = action.payload;
|
||||
},
|
||||
clearSearch: (state) => {
|
||||
state.value = "";
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setSearch, clearSearch } = searchSlice.actions;
|
||||
23
src/renderer/features/use-preferences-slice.ts
Normal file
23
src/renderer/features/use-preferences-slice.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import type { PayloadAction } from "@reduxjs/toolkit";
|
||||
import type { UserPreferences } from "@types";
|
||||
|
||||
interface UserPreferencesState {
|
||||
value: UserPreferences | null;
|
||||
}
|
||||
|
||||
const initialState: UserPreferencesState = {
|
||||
value: null,
|
||||
};
|
||||
|
||||
export const userPreferencesSlice = createSlice({
|
||||
name: "userPreferences",
|
||||
initialState,
|
||||
reducers: {
|
||||
setUserPreferences: (state, action: PayloadAction<UserPreferences>) => {
|
||||
state.value = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setUserPreferences } = userPreferencesSlice.actions;
|
||||
33
src/renderer/features/window-slice.ts
Normal file
33
src/renderer/features/window-slice.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import type { PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
interface WindowState {
|
||||
draggingDisabled: boolean;
|
||||
scrollingDisabled: boolean;
|
||||
headerTitle: string;
|
||||
}
|
||||
|
||||
const initialState: WindowState = {
|
||||
draggingDisabled: false,
|
||||
scrollingDisabled: false,
|
||||
headerTitle: "",
|
||||
};
|
||||
|
||||
export const windowSlice = createSlice({
|
||||
name: "window",
|
||||
initialState,
|
||||
reducers: {
|
||||
toggleDragging: (state, action: PayloadAction<boolean>) => {
|
||||
state.draggingDisabled = action.payload;
|
||||
},
|
||||
toggleScrolling: (state, action: PayloadAction<boolean>) => {
|
||||
state.scrollingDisabled = action.payload;
|
||||
},
|
||||
setHeaderTitle: (state, action: PayloadAction<string>) => {
|
||||
state.headerTitle = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { toggleDragging, toggleScrolling, setHeaderTitle } =
|
||||
windowSlice.actions;
|
||||
Reference in New Issue
Block a user