mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 00:04:48 -07:00
refactor redux data model
This commit is contained in:
parent
ae1bc3da38
commit
0ff391491d
243 changed files with 5212 additions and 5963 deletions
|
|
@ -1,14 +1,12 @@
|
|||
import React from 'react';
|
||||
import { Navigate } from 'react-router-dom';
|
||||
|
||||
import { ServerSelectors } from '@app/store';
|
||||
import { ServerSelectors, useAppSelector } from '@app/store';
|
||||
import { App } from '@app/types';
|
||||
import { useAppSelector } from '@app/store';
|
||||
import { AuthenticationService } from '@app/api';
|
||||
|
||||
const AuthGuard = () => {
|
||||
const state = useAppSelector(s => ServerSelectors.getState(s));
|
||||
return !AuthenticationService.isConnected(state)
|
||||
const isConnected = useAppSelector(ServerSelectors.getIsConnected);
|
||||
return !isConnected
|
||||
? <Navigate to={App.RouteEnum.LOGIN} />
|
||||
: <div></div>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
import React from 'react';
|
||||
import { Navigate } from 'react-router-dom';
|
||||
|
||||
import { ServerSelectors } from '@app/store';
|
||||
import { AuthenticationService } from '@app/api';
|
||||
import { ServerSelectors, useAppSelector } from '@app/store';
|
||||
import { App } from '@app/types';
|
||||
import { useAppSelector } from '@app/store';
|
||||
|
||||
const ModGuard = () => {
|
||||
const user = useAppSelector(state => ServerSelectors.getUser(state));
|
||||
return !AuthenticationService.isModerator(user)
|
||||
const isModerator = useAppSelector(ServerSelectors.getIsUserModerator);
|
||||
return !isModerator
|
||||
? <Navigate to={App.RouteEnum.SERVER} />
|
||||
: <></>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import AddIcon from '@mui/icons-material/Add';
|
|||
import EditRoundedIcon from '@mui/icons-material/Edit';
|
||||
import ErrorOutlinedIcon from '@mui/icons-material/ErrorOutlined';
|
||||
|
||||
import { AuthenticationService } from '@app/api';
|
||||
import { request } from '@app/api';
|
||||
import { KnownHostDialog } from '@app/dialogs';
|
||||
import { useReduxEffect } from '@app/hooks';
|
||||
import { HostDTO } from '@app/services';
|
||||
|
|
@ -197,7 +197,7 @@ const KnownHosts = (props) => {
|
|||
setTestingConnection(TestConnection.TESTING);
|
||||
|
||||
const options = { ...App.getHostPort(hostsState.selectedHost) };
|
||||
AuthenticationService.testConnection(options);
|
||||
request.authentication.testConnection(options);
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import Menu from '@mui/material/Menu';
|
|||
import MenuItem from '@mui/material/MenuItem';
|
||||
|
||||
import { Images } from '@app/images';
|
||||
import { SessionService } from '@app/api';
|
||||
import { request } from '@app/api';
|
||||
import { ServerSelectors } from '@app/store';
|
||||
import { App, Data } from '@app/types';
|
||||
import { useAppSelector } from '@app/store';
|
||||
|
|
@ -28,23 +28,23 @@ const UserDisplay = ({ user }: UserDisplayProps) => {
|
|||
|
||||
const handleClose = () => setPosition(null);
|
||||
|
||||
const isABuddy = buddyList.filter(u => u.name === user.name).length;
|
||||
const isIgnored = ignoreList.filter(u => u.name === user.name).length;
|
||||
const isABuddy = Boolean(buddyList[user.name]);
|
||||
const isIgnored = Boolean(ignoreList[user.name]);
|
||||
|
||||
const onAddBuddy = () => {
|
||||
SessionService.addToBuddyList(user.name);
|
||||
request.session.addToBuddyList(user.name);
|
||||
handleClose();
|
||||
};
|
||||
const onRemoveBuddy = () => {
|
||||
SessionService.removeFromBuddyList(user.name);
|
||||
request.session.removeFromBuddyList(user.name);
|
||||
handleClose();
|
||||
};
|
||||
const onAddIgnore = () => {
|
||||
SessionService.addToIgnoreList(user.name);
|
||||
request.session.addToIgnoreList(user.name);
|
||||
handleClose();
|
||||
};
|
||||
const onRemoveIgnore = () => {
|
||||
SessionService.removeFromIgnoreList(user.name);
|
||||
request.session.removeFromIgnoreList(user.name);
|
||||
handleClose();
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue