Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
August2211 committed Oct 30, 2023
2 parents 920e6e4 + 9148076 commit 661ea76
Show file tree
Hide file tree
Showing 18 changed files with 743 additions and 190 deletions.
1 change: 1 addition & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<title>Vite + React + TS + Tailwind</title>
</head>
<body>

<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
Expand Down
104 changes: 76 additions & 28 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@fontsource-variable/inter": "^5.0.13",
"@mui/base": "^5.0.0-beta.21",
"@mui/joy": "^5.0.0-beta.11",
"@tabler/icons-react": "^2.39.0",
"react": "^18.2.0",
Expand Down
44 changes: 28 additions & 16 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Alert,
Button,
Card,
DialogActions,
Expand All @@ -15,7 +16,8 @@ import {Server} from "./pages/Server";
import {IconArrowLeft, IconExternalLink, IconPlus, IconRefresh} from "@tabler/icons-react";
import {CreateServer, GetAllServers, GetAllServersFromDir, GetServerDir} from "../wailsjs/go/server/ServerController";
import {server} from "../wailsjs/go/models";
import {BrowserOpenURL, EventsOff, EventsOn, LogDebug, LogError} from "../wailsjs/runtime";
import {BrowserOpenURL, EventsOff, EventsOn, LogDebug} from "../wailsjs/runtime";
import {AlertProvider} from "./components/AlertProvider";

enum ServerListType {
CARD,
Expand All @@ -27,6 +29,10 @@ function App() {
const [drawerOpen, setDrawerOpen] = useState(false);
const [servers, setServers] = useState<{[key: number]: server.Server}|null>(null);





//This gets all the servers but if one server is changed manually it does not update it!
function getServers() {
GetAllServers()
Expand Down Expand Up @@ -61,6 +67,7 @@ function App() {

useEffect(() => {
getServers()

}, []);

//events
Expand Down Expand Up @@ -89,8 +96,8 @@ function App() {
<DialogActions>
<List>
<ListItem>
<Tooltip title={'Reload servers from disk'}><IconButton color={'danger'} variant={"solid"} onClick={() => getServersFromDir()}><IconRefresh/></IconButton></Tooltip>
<Tooltip title={'Refresh server list from cache'}><IconButton onClick={() => getServers()}><IconRefresh/></IconButton></Tooltip>
<Tooltip title={'Reload servers from disk'}><IconButton color={'danger'} variant={"solid"} onClick={() => {getServersFromDir(); setActiveServer(undefined)}}><IconRefresh/></IconButton></Tooltip>
<Tooltip title={'Refresh server list from cache'}><IconButton onClick={() => {getServers(); setActiveServer(undefined)}}><IconRefresh/></IconButton></Tooltip>
<Tooltip title={'Open servers folder'}><IconButton onClick={() => {GetServerDir().then((dir: string) => BrowserOpenURL("file:///" + dir))}}><IconExternalLink/></IconButton></Tooltip>
</ListItem>
<ListItem>
Expand Down Expand Up @@ -125,22 +132,27 @@ function App() {
}
}




return (
<div className={'min-h-screen max-h-screen overflow-y-auto flex-col'}>
<div className={'h-16 flex'}>
<div className={'text-lg font-bold ml-8 my-auto'}>
<Button color={'neutral'} variant={'soft'} onClick={() => setDrawerOpen(true)}>
<IconArrowLeft/> Select server
</Button>
</div>
<div className={'ml-auto my-auto mr-8 gap-2 flex'}>
<ThemeSwitcher/>
<HomeButton setServ={setActiveServer}/>
<div className={'min-h-screen max-h-screen overflow-y-auto flex-col flex'}>
<AlertProvider>
<div className={'h-16 flex'}>
<div className={'text-lg font-bold ml-8 my-auto'}>
<Button color={'neutral'} variant={'soft'} onClick={() => setDrawerOpen(true)}>
<IconArrowLeft/> Select server
</Button>
</div>
<div className={'ml-auto my-auto mr-8 gap-2 flex'}>
<ThemeSwitcher/>
<HomeButton setServ={setActiveServer}/>
</div>
</div>
</div>
{mainUi}
{mainUi}

{ServerDrawer}
{ServerDrawer}
</AlertProvider>
</div>
)
}
Expand Down
59 changes: 59 additions & 0 deletions frontend/src/components/AlertProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React, { createContext, useContext, useState, ReactNode } from 'react';
import { Alert } from '@mui/joy';
import {IconX} from "@tabler/icons-react";

type AlertContextType = {
addAlert: (message: string, severity: "success" | "warning" | "primary" | "neutral" | "danger" | undefined) => void;
alerts: Alert[];
};

const AlertContext = createContext<AlertContextType | undefined>(undefined);

type AlertProviderProps = {
children: ReactNode;
};

type Alert = {
message: string;
severity: "success" | "warning" | "primary" | "neutral" | "danger" | undefined
};

export function AlertProvider({ children }: AlertProviderProps) {

const [alerts, setAlerts] = useState<Alert[]>([])

const addAlert = (message: string, severity: "success" | "warning" | "primary" | "neutral" | "danger" | undefined) => {
const newAlert = { message, severity };
setAlerts([...alerts, newAlert]);

console.log(alerts)
};

const removeAlert = (index: number) => {
const updatedAlerts = [...alerts];
updatedAlerts.splice(index, 1);
setAlerts(updatedAlerts);
};

return (
<AlertContext.Provider value={{ addAlert, alerts }}>
{children}

<div className={"m-4 absolute bottom-0 w-[80vw] left-1/2 -ml-[40vw]"}>
{alerts.map((alert, index) => (
<Alert key={index} className={"m-4 "} color={alert.severity} endDecorator={<IconX onClick={() => removeAlert(index)}/>}>
{alert.message}
</Alert>
))}
</div>
</AlertContext.Provider>
);
}

export function useAlert() {
const context = useContext(AlertContext);
if (!context) {
throw new Error('useAlert must be used within an AlertProvider');
}
return context;
}
4 changes: 3 additions & 1 deletion frontend/src/components/PasswordInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ type Props = {
onChange: React.ChangeEventHandler<HTMLInputElement> | undefined
value: string | ReadonlyArray<string> | number | undefined;
children?: any
className?: string | undefined
}

export function PasswordInput({onChange, value, children}: Props) {
export function PasswordInput({onChange, value, children, className}: Props) {
const [textVisible, setTextVisible] = useState(false)
return (
<Input type={textVisible? 'text' : 'password'}
endDecorator={<IconButton onClick={() => setTextVisible(!textVisible)}>{textVisible? <IconEye/> : <IconEyeClosed/>}</IconButton>}
value={value}
onChange={onChange}
className={className}
>{children}</Input>
);
}
7 changes: 3 additions & 4 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import React from 'react'
import ReactDOM, {createRoot} from 'react-dom/client'
import {createRoot} from 'react-dom/client'
import App from './App'
import './index.css'
import '@fontsource-variable/inter';
import {
Button,
CssBaseline,
CssVarsProvider,
getInitColorSchemeScript,
StyledEngineProvider,
useColorScheme
} from "@mui/joy";



const container = document.getElementById('root')

const root = createRoot(container!)
Expand Down
Loading

0 comments on commit 661ea76

Please sign in to comment.