Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mfechner committed Oct 16, 2024
1 parent 0b9a2e4 commit f296d85
Show file tree
Hide file tree
Showing 28 changed files with 1,309 additions and 974 deletions.
59 changes: 28 additions & 31 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
"homepage": ".",
"proxy": "http://localhost:80",
"dependencies": {
"@material-ui/core": "^4.11.4",
"@material-ui/icons": "^4.9.1",
"axios": "^0.21.1",
"codemirror": "^5.61.1",
"@material-ui/core": "4.12.3",
"@material-ui/icons": "4.11.2",
"axios": "1.7.4",
"codemirror": "5.64.0",
"detect-browser": "^5.2.0",
"js-base64": "^3.6.1",
"mobx": "^6.13.3",
"mobx-react": "^9.1.1",
"mobx-utils": "^6.1.0",
"notifyjs": "^3.0.0",
"prop-types": "^15.6.2",
"react": "^16.8.6",
"react-codemirror2": "^7.2.1",
"react-dom": "^16.8.6",
"react-infinite": "^0.13.0",
"react-markdown": "^6.0.2",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-timeago": "^6.2.1",
"remark-gfm": "^1.0.0",
"remove-markdown": "^0.3.0",
"mobx": "6.13.4",
"mobx-react": "9.1.1",
"mobx-utils": "6.1.0",
"notifyjs": "3.0.0",
"prop-types": "15.8.1",
"react": "17.0.2",
"react-codemirror2": "7.2.1",
"react-dom": "17.0.2",
"react-infinite": "0.13.0",
"react-markdown": "9.0.1",
"react-router": "6.27.0",
"react-router-dom": "6.27.0",
"react-timeago": "7.2.0",
"remark-gfm": "4.0.0",
"remove-markdown": "0.5.5",
"typeface-roboto": "1.1.13"
},
"scripts": {
Expand All @@ -40,18 +40,15 @@
"devDependencies": {
"@types/codemirror": "5.60.0",
"@types/detect-browser": "^4.0.0",
"@types/get-port": "^4.0.0",
"@types/jest": "^26.0.23",
"@types/js-base64": "^3.3.1",
"@types/node": "^15.12.2",
"@types/node": "20.16.11",
"@types/notifyjs": "^3.0.2",
"@types/puppeteer": "^5.4.6",
"@types/react": "^16.9.49",
"@types/react-dom": "^16.9.8",
"@types/react": "17.0.83",
"@types/react-dom": "17.0.25",
"@types/react-infinite": "0.0.35",
"@types/react-router-dom": "^5.1.7",
"@types/react-router-dom": "5.3.0",
"@types/remove-markdown": "^0.3.0",
"@types/rimraf": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^4.1.0",
"@typescript-eslint/parser": "^4.1.0",
"@vitejs/plugin-react": "^4.3.2",
Expand All @@ -61,15 +58,15 @@
"eslint-plugin-prefer-arrow": "^1.2.2",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-unicorn": "^21.0.0",
"get-port": "^5.1.1",
"get-port": "7.1.0",
"prettier": "^2.3.1",
"puppeteer": "^17.1.3",
"rimraf": "^3.0.2",
"rimraf": "6.0.1",
"tree-kill": "^1.2.0",
"typescript": "4.0.2",
"vite": "^5.4.8",
"vitest": "^2.1.3",
"wait-on": "^5.3.0"
"vite": "5.4.9",
"vitest": "2.1.3",
"wait-on": "8.0.1"
},
"eslintConfig": {
"extends": "react-app"
Expand Down
62 changes: 25 additions & 37 deletions ui/src/CurrentUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as config from './config';
import {Base64} from 'js-base64';
import {detect} from 'detect-browser';
import {SnackReporter} from './snack/SnackManager';
import { makeObservable, observable, action } from 'mobx';
import { observable, action, runInAction } from 'mobx';
import {IClient, IUser} from './types';

const tokenKey = 'gotify-login-key';
Expand All @@ -21,19 +21,7 @@ export class CurrentUser {
@observable
public connectionErrorMessage: string | null = null;

public constructor(private readonly snack: SnackReporter) {
makeObservable(this);
}

@action
private setLoggedIn = (value: boolean) => {
this.loggedIn = value;
};

@action
private setConnectionErrorMessage = (message: string | null): void => {
this.connectionErrorMessage = message;
};
public constructor(private readonly snack: SnackReporter) {}

public token = (): string => {
if (this.tokenCache !== null) {
Expand Down Expand Up @@ -75,9 +63,8 @@ export class CurrentUser {
return false;
});

@action
public login = async (username: string, password: string) => {
this.setLoggedIn(false);
this.loggedIn = false;
this.authenticating = true;
const browser = detect();
const name = (browser && browser.name + ' ' + browser.version) || 'unknown browser';
Expand All @@ -91,27 +78,30 @@ export class CurrentUser {
headers: {Authorization: 'Basic ' + Base64.encode(username + ':' + password)},
})
.then((resp: AxiosResponse<IClient>) => {
this.snack(`A client named '${name}' was created for your session.`);
this.setToken(resp.data.token);
this.tryAuthenticate()
.then(() => {
this.authenticating = false;
this.setLoggedIn(true);
})
.catch(() => {
this.authenticating = false;
console.log(
'create client succeeded, but authenticated with given token failed'
);
});
runInAction(() => {
this.snack(`A client named '${name}' was created for your session.`);
this.setToken(resp.data.token);
this.tryAuthenticate()
.then(() => {
runInAction(() => {
this.authenticating = false;
this.loggedIn = true;
})
})
.catch(() => {
this.authenticating = false;
console.log(
'create client succeeded, but authenticated with given token failed'
);
});
})
})
.catch(() => {
this.authenticating = false;
return this.snack('Login failed');
});
};

@action
public tryAuthenticate = async (): Promise<AxiosResponse<IUser>> => {
if (this.token() === '') {
return Promise.reject();
Expand All @@ -122,10 +112,10 @@ export class CurrentUser {
.create()
// eslint-disable-next-line @typescript-eslint/naming-convention
.get(config.get('url') + 'current/user', {headers: {'X-Gotify-Key': this.token()}})
.then((passThrough) => {
.then((passThrough: { data: IUser; }) => {
this.user = passThrough.data;
this.setLoggedIn(true);
this.setConnectionErrorMessage(null);
this.loggedIn = true;
this.connectionErrorMessage = null;
this.reconnectTime = 7500;
return passThrough;
})
Expand All @@ -142,7 +132,7 @@ export class CurrentUser {
return Promise.reject(error);
}

this.setConnectionErrorMessage(null);
this.connectionErrorMessage = null;

if (error.response.status >= 400 && error.response.status < 500) {
this.logout();
Expand All @@ -152,7 +142,6 @@ export class CurrentUser {
);
};

@action
public logout = async () => {
await axios
.get(config.get('url') + 'client')
Expand All @@ -164,7 +153,7 @@ export class CurrentUser {
.catch(() => Promise.resolve());
window.localStorage.removeItem(tokenKey);
this.tokenCache = null;
this.setLoggedIn(false);
this.loggedIn = false;
};

public changePassword = (pass: string) => {
Expand All @@ -181,7 +170,6 @@ export class CurrentUser {
});
};

@action
private readonly connectionError = (message: string) => {
this.connectionErrorMessage = message;
if (this.reconnectTimeoutId !== null) {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/application/AddApplicationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ export default class AddDialog extends Component<IProps, IState> {
className="name"
label="Name *"
type="text"
value={name}
defaultValue={name}
onChange={this.handleChange.bind(this, 'name')}
fullWidth
/>
<TextField
margin="dense"
className="description"
label="Short Description"
value={description}
defaultValue={description}
onChange={this.handleChange.bind(this, 'description')}
fullWidth
multiline
Expand Down
34 changes: 7 additions & 27 deletions ui/src/application/Applications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Button from '@material-ui/core/Button';
import CopyableSecret from '../common/CopyableSecret';
import AddApplicationDialog from './AddApplicationDialog';
import {observer} from 'mobx-react';
import { action, makeObservable, observable } from 'mobx';
import { action, observable } from 'mobx';
import {inject, Stores} from '../inject';
import * as config from '../config';
import UpdateDialog from './UpdateApplicationDialog';
Expand All @@ -35,26 +35,6 @@ class Applications extends Component<Stores<'appStore'>> {
private uploadId = -1;
private upload: HTMLInputElement | null = null;

constructor(props: any) {
super(props);
makeObservable(this);
}

@action
private setDeleteId = (id: number | false) => {
this.deleteId = id;
};

@action
private setUpdateId = (id: number | false) => {
this.updateId = id;
};

@action
private setCreateDialog = (dialog: boolean) => {
this.createDialog = dialog;
};

public componentDidMount = () => this.props.appStore.refresh();

public render() {
Expand All @@ -73,7 +53,7 @@ class Applications extends Component<Stores<'appStore'>> {
id="create-app"
variant="contained"
color="primary"
onClick={() => (this.setCreateDialog(true))}>
onClick={() => (this.createDialog = true)}>
Create Application
</Button>
}
Expand Down Expand Up @@ -104,8 +84,8 @@ class Applications extends Component<Stores<'appStore'>> {
value={app.token}
lastUsed={app.lastUsed}
fUpload={() => this.uploadImage(app.id)}
fDelete={() => (this.setDeleteId(app.id))}
fEdit={() => (this.setUpdateId(app.id))}
fDelete={() => (this.deleteId = app.id)}
fEdit={() => (this.updateId = app.id)}
noDelete={app.internal}
/>
))}
Expand All @@ -121,13 +101,13 @@ class Applications extends Component<Stores<'appStore'>> {
</Grid>
{createDialog && (
<AddApplicationDialog
fClose={() => (this.setCreateDialog(false))}
fClose={() => (this.createDialog = false)}
fOnSubmit={appStore.create}
/>
)}
{updateId !== false && (
<UpdateDialog
fClose={() => (this.setUpdateId(false))}
fClose={() => (this.updateId = false)}
fOnSubmit={(name, description, defaultPriority) =>
appStore.update(updateId, name, description, defaultPriority)
}
Expand All @@ -140,7 +120,7 @@ class Applications extends Component<Stores<'appStore'>> {
<ConfirmDialog
title="Confirm Delete"
text={'Delete ' + appStore.getByID(deleteId).name + '?'}
fClose={() => (this.setDeleteId(false))}
fClose={() => (this.deleteId = false)}
fOnSubmit={() => appStore.remove(deleteId)}
/>
)}
Expand Down
4 changes: 2 additions & 2 deletions ui/src/application/UpdateApplicationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ export default class UpdateDialog extends Component<IProps, IState> {
className="name"
label="Name *"
type="text"
value={name}
defaultValue={name}
onChange={this.handleChange.bind(this, 'name')}
fullWidth
/>
<TextField
margin="dense"
className="description"
label="Short Description"
value={description}
defaultValue={description}
onChange={this.handleChange.bind(this, 'description')}
fullWidth
multiline
Expand Down
2 changes: 1 addition & 1 deletion ui/src/client/AddClientDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class AddDialog extends Component<IProps, {name: string}> {
className="name"
label="Name *"
type="email"
value={name}
defaultValue={name}
onChange={this.handleChange.bind(this, 'name')}
fullWidth
/>
Expand Down
4 changes: 1 addition & 3 deletions ui/src/client/ClientStore.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import {BaseStore} from '../common/BaseStore';
import axios from 'axios';
import * as config from '../config';
import { action, makeObservable } from 'mobx';
import { action } from 'mobx';
import {SnackReporter} from '../snack/SnackManager';
import {IClient} from '../types';

export class ClientStore extends BaseStore<IClient> {
public constructor(private readonly snack: SnackReporter) {
super();
makeObservable(this);
}

@action
protected requestItems = (): Promise<IClient[]> =>
axios.get<IClient[]>(`${config.get('url')}client`).then((response) => response.data);

Expand Down
Loading

0 comments on commit f296d85

Please sign in to comment.