Admin persistence changes (#5086)

This commit is contained in:
Joseph Insalaco 2024-08-16 22:31:57 -04:00 committed by GitHub
parent 090a48515c
commit b111f0921c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 148 additions and 10 deletions

View file

@ -1,4 +1,4 @@
import { SortDirection, StatusEnum, UserSortField } from 'types';
import { SortDirection, StatusEnum, UserLevelFlag, UserSortField } from 'types';
import { SortUtil } from '../common';
@ -35,6 +35,11 @@ const initialState: ServerState = {
userInfo: {},
notifications: [],
serverShutdown: null,
banUser: '',
banHistory: {},
warnHistory: {},
warnListOptions: [],
warnUser: '',
};
export const serverReducer = (state = initialState, action: any) => {
@ -278,6 +283,69 @@ export const serverReducer = (state = initialState, action: any) => {
serverShutdown: data,
};
}
case Types.BAN_FROM_SERVER: {
const { userName } = action;
return {
...state,
banUser: userName,
};
}
case Types.BAN_HISTORY: {
const { userName, banHistory } = action;
return {
...state,
banHistory: {
...state.banHistory,
[userName]: banHistory,
}
};
}
case Types.WARN_HISTORY: {
const { userName, warnHistory } = action;
return {
...state,
warnHistory: {
...state.warnHistory,
[userName]: warnHistory,
}
};
}
case Types.WARN_LIST_OPTIONS: {
const { warnList } = action;
return {
...state,
warnListOptions: warnList,
};
}
case Types.WARN_USER: {
const { userName } = action;
return {
...state,
warnUser: userName,
};
}
case Types.ADJUST_MOD: {
const { userName, shouldBeMod, shouldBeJudge } = action;
return {
...state,
users: state.users.map((user) => {
if (user.name !== userName) {
return user;
}
const judgeFlag = shouldBeJudge ? UserLevelFlag.IsJudge : UserLevelFlag.IsNothing;
const modFlag = shouldBeMod ? UserLevelFlag.IsModerator : UserLevelFlag.IsNothing;
return {
...user,
userLevel: user.userLevel & (judgeFlag | modFlag)
}
})
};
}
default:
return state;
}