first commit

This commit is contained in:
Hydra
2024-04-18 08:46:06 +01:00
commit f1bdec484e
165 changed files with 20993 additions and 0 deletions

View 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;

View 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";

View 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;

View 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;

View 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;

View 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;

View 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;