Initial implementation completion and refactor (#6806)
Some checks failed
Build Desktop / Configure (push) Has been cancelled
Build Docker Image / amd64 & arm64 (push) Has been cancelled
Build Web / React (Node 16) (push) Has been cancelled
Build Web / React (Node lts/*) (push) Has been cancelled
Build Desktop / Debian 11 (push) Has been cancelled
Build Desktop / Debian 13 (push) Has been cancelled
Build Desktop / Debian 12 (push) Has been cancelled
Build Desktop / Fedora 43 (push) Has been cancelled
Build Desktop / Fedora 42 (push) Has been cancelled
Build Desktop / Servatrice_Debian 11 (push) Has been cancelled
Build Desktop / Ubuntu 24.04 (push) Has been cancelled
Build Desktop / Ubuntu 26.04 (push) Has been cancelled
Build Desktop / Ubuntu 22.04 (push) Has been cancelled
Build Desktop / Arch (push) Has been cancelled
Build Desktop / macOS 14 (push) Has been cancelled
Build Desktop / macOS 15 (push) Has been cancelled
Build Desktop / macOS 13 Intel (push) Has been cancelled
Build Desktop / macOS 15 Debug (push) Has been cancelled
Build Desktop / Windows 10 (push) Has been cancelled

This commit is contained in:
Jeremy Letto 2026-04-11 22:51:10 -05:00 committed by GitHub
parent 2e10b2f5d5
commit 8cc65b8967
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
76 changed files with 897 additions and 890 deletions

View file

@ -1,10 +1,60 @@
import { SortDirection, StatusEnum, UserLevelFlag, UserSortField } from 'types';
import { DeckStorageFolder, DeckStorageTreeItem, SortDirection, StatusEnum, UserLevelFlag, UserSortField } from 'types';
import { SortUtil } from '../common';
import { ServerState } from './server.interfaces'
import { Types } from './server.types';
function splitPath(path: string): string[] {
return path ? path.split('/') : [];
}
function insertAtPath(folder: DeckStorageFolder, pathSegments: string[], item: DeckStorageTreeItem): DeckStorageFolder {
if (pathSegments.length === 0 || (pathSegments.length === 1 && pathSegments[0] === '')) {
return { items: [...folder.items, item] };
}
const [head, ...tail] = pathSegments;
const match = folder.items.find(child => child.name === head && child.folder);
if (match) {
return {
items: folder.items.map(child =>
child === match
? { ...child, folder: insertAtPath(child.folder!, tail, item) }
: child
),
};
}
const created: DeckStorageTreeItem = { id: 0, name: head, file: null, folder: insertAtPath({ items: [] }, tail, item) };
return { items: [...folder.items, created] };
}
function removeById(folder: DeckStorageFolder, id: number): DeckStorageFolder {
return {
items: folder.items
.filter(item => item.id !== id)
.map(item =>
item.folder ? { ...item, folder: removeById(item.folder, id) } : item
),
};
}
function removeByPath(folder: DeckStorageFolder, pathSegments: string[]): DeckStorageFolder {
if (pathSegments.length === 0 || (pathSegments.length === 1 && pathSegments[0] === '')) {
return folder;
}
const [head, ...tail] = pathSegments;
if (tail.length === 0) {
return { items: folder.items.filter(item => !(item.name === head && item.folder !== null)) };
}
return {
items: folder.items.map(item =>
item.name === head && item.folder
? { ...item, folder: removeByPath(item.folder, tail) }
: item
),
};
}
const initialState: ServerState = {
initialized: false,
buddyList: [],
@ -40,6 +90,9 @@ const initialState: ServerState = {
warnHistory: {},
warnListOptions: [],
warnUser: '',
adminNotes: {},
replays: [],
backendDecks: null,
};
export const serverReducer = (state = initialState, action: any) => {
@ -247,7 +300,7 @@ export const serverReducer = (state = initialState, action: any) => {
messages: {
...state.messages,
[userName]: [
...state.messages[userName],
...(state.messages[userName] ?? []),
action.messageData,
],
}
@ -328,6 +381,17 @@ export const serverReducer = (state = initialState, action: any) => {
warnUser: userName,
};
}
case Types.GET_ADMIN_NOTES:
case Types.UPDATE_ADMIN_NOTES: {
const { userName, notes } = action;
return {
...state,
adminNotes: {
...state.adminNotes,
[userName]: notes,
}
};
}
case Types.ADJUST_MOD: {
const { userName, shouldBeMod, shouldBeJudge } = action;
@ -346,6 +410,71 @@ export const serverReducer = (state = initialState, action: any) => {
})
};
}
case Types.REPLAY_LIST: {
return { ...state, replays: [...action.matchList] };
}
case Types.REPLAY_ADDED: {
return { ...state, replays: [...state.replays, action.matchInfo] };
}
case Types.REPLAY_MODIFY_MATCH: {
return {
...state,
replays: state.replays.map(r =>
r.gameId === action.gameId ? { ...r, doNotHide: action.doNotHide } : r
),
};
}
case Types.REPLAY_DELETE_MATCH: {
return { ...state, replays: state.replays.filter(r => r.gameId !== action.gameId) };
}
case Types.BACKEND_DECKS: {
return { ...state, backendDecks: action.deckList };
}
case Types.DECK_UPLOAD: {
if (!state.backendDecks) {
return state;
}
return {
...state,
backendDecks: {
root: insertAtPath(state.backendDecks.root, splitPath(action.path), action.treeItem),
},
};
}
case Types.DECK_DELETE: {
if (!state.backendDecks) {
return state;
}
return {
...state,
backendDecks: {
root: removeById(state.backendDecks.root, action.deckId),
},
};
}
case Types.DECK_NEW_DIR: {
if (!state.backendDecks) {
return state;
}
const newFolder: DeckStorageTreeItem = { id: 0, name: action.dirName, file: null, folder: { items: [] } };
return {
...state,
backendDecks: {
root: insertAtPath(state.backendDecks.root, splitPath(action.path), newFolder),
},
};
}
case Types.DECK_DEL_DIR: {
if (!state.backendDecks) {
return state;
}
return {
...state,
backendDecks: {
root: removeByPath(state.backendDecks.root, splitPath(action.path)),
},
};
}
default:
return state;
}