fix: upgrade mobx

This commit is contained in:
Jannis Mattheis 2025-08-04 11:01:32 +02:00
parent f4ca0cc266
commit 86285f4316
11 changed files with 87 additions and 65 deletions

View File

@ -15,9 +15,9 @@
"@vitejs/plugin-react": "^4.7.0", "@vitejs/plugin-react": "^4.7.0",
"axios": "^1.11.0", "axios": "^1.11.0",
"detect-browser": "^5.3.0", "detect-browser": "^5.3.0",
"mobx": "^5.15.6", "mobx": "^6.13.7",
"mobx-react": "^6.3.0", "mobx-react": "^9.2.0",
"mobx-utils": "^5.6.1", "mobx-utils": "^6.1.1",
"notifyjs": "^3.0.0", "notifyjs": "^3.0.0",
"notistack": "^3.0.2", "notistack": "^3.0.2",
"react": "^19.1.1", "react": "^19.1.1",

View File

@ -2,7 +2,7 @@ import axios, {AxiosError, AxiosResponse} from 'axios';
import * as config from './config'; import * as config from './config';
import {detect} from 'detect-browser'; import {detect} from 'detect-browser';
import {SnackReporter} from './snack/SnackManager'; import {SnackReporter} from './snack/SnackManager';
import {observable} from 'mobx'; import {observable, makeObservable} from 'mobx';
import {IClient, IUser} from './types'; import {IClient, IUser} from './types';
const tokenKey = 'gotify-login-key'; const tokenKey = 'gotify-login-key';
@ -11,16 +11,19 @@ export class CurrentUser {
private tokenCache: string | null = null; private tokenCache: string | null = null;
private reconnectTimeoutId: number | null = null; private reconnectTimeoutId: number | null = null;
private reconnectTime = 7500; private reconnectTime = 7500;
@observable
public loggedIn = false; public loggedIn = false;
@observable
public authenticating = true; public authenticating = true;
@observable
public user: IUser = {name: 'unknown', admin: false, id: -1}; public user: IUser = {name: 'unknown', admin: false, id: -1};
@observable
public connectionErrorMessage: string | null = null; public connectionErrorMessage: string | null = null;
public constructor(private readonly snack: SnackReporter) {} public constructor(private readonly snack: SnackReporter) {
makeObservable(this, {
loggedIn: observable,
authenticating: observable,
user: observable,
connectionErrorMessage: observable,
});
}
public token = (): string => { public token = (): string => {
if (this.tokenCache !== null) { if (this.tokenCache !== null) {

View File

@ -1,7 +1,7 @@
import {BaseStore} from '../common/BaseStore'; import {BaseStore} from '../common/BaseStore';
import axios from 'axios'; import axios from 'axios';
import * as config from '../config'; import * as config from '../config';
import {action} from 'mobx'; import {action, makeObservable} from 'mobx';
import {SnackReporter} from '../snack/SnackManager'; import {SnackReporter} from '../snack/SnackManager';
import {IApplication} from '../types'; import {IApplication} from '../types';
@ -10,6 +10,12 @@ export class AppStore extends BaseStore<IApplication> {
public constructor(private readonly snack: SnackReporter) { public constructor(private readonly snack: SnackReporter) {
super(); super();
makeObservable(this, {
uploadImage: action,
update: action,
create: action,
});
} }
protected requestItems = (): Promise<IApplication[]> => protected requestItems = (): Promise<IApplication[]> =>
@ -23,7 +29,6 @@ export class AppStore extends BaseStore<IApplication> {
return this.snack('Application deleted'); return this.snack('Application deleted');
}); });
@action
public uploadImage = async (id: number, file: Blob): Promise<void> => { public uploadImage = async (id: number, file: Blob): Promise<void> => {
const formData = new FormData(); const formData = new FormData();
formData.append('file', file); formData.append('file', file);
@ -34,7 +39,6 @@ export class AppStore extends BaseStore<IApplication> {
this.snack('Application image updated'); this.snack('Application image updated');
}; };
@action
public update = async ( public update = async (
id: number, id: number,
name: string, name: string,
@ -50,7 +54,6 @@ export class AppStore extends BaseStore<IApplication> {
this.snack('Application updated'); this.snack('Application updated');
}; };
@action
public create = async ( public create = async (
name: string, name: string,
description: string, description: string,

View File

@ -1,13 +1,19 @@
import {BaseStore} from '../common/BaseStore'; import {BaseStore} from '../common/BaseStore';
import axios from 'axios'; import axios from 'axios';
import * as config from '../config'; import * as config from '../config';
import {action} from 'mobx'; import {action, makeObservable} from 'mobx';
import {SnackReporter} from '../snack/SnackManager'; import {SnackReporter} from '../snack/SnackManager';
import {IClient} from '../types'; import {IClient} from '../types';
export class ClientStore extends BaseStore<IClient> { export class ClientStore extends BaseStore<IClient> {
public constructor(private readonly snack: SnackReporter) { public constructor(private readonly snack: SnackReporter) {
super(); super();
makeObservable(this, {
update: action,
createNoNotifcation: action,
create: action,
});
} }
protected requestItems = (): Promise<IClient[]> => protected requestItems = (): Promise<IClient[]> =>
@ -19,21 +25,18 @@ export class ClientStore extends BaseStore<IClient> {
.then(() => this.snack('Client deleted')); .then(() => this.snack('Client deleted'));
} }
@action
public update = async (id: number, name: string): Promise<void> => { public update = async (id: number, name: string): Promise<void> => {
await axios.put(`${config.get('url')}client/${id}`, {name}); await axios.put(`${config.get('url')}client/${id}`, {name});
await this.refresh(); await this.refresh();
this.snack('Client updated'); this.snack('Client updated');
}; };
@action
public createNoNotifcation = async (name: string): Promise<IClient> => { public createNoNotifcation = async (name: string): Promise<IClient> => {
const client = await axios.post(`${config.get('url')}client`, {name}); const client = await axios.post(`${config.get('url')}client`, {name});
await this.refresh(); await this.refresh();
return client.data; return client.data;
}; };
@action
public create = async (name: string): Promise<void> => { public create = async (name: string): Promise<void> => {
await this.createNoNotifcation(name); await this.createNoNotifcation(name);
this.snack('Client added'); this.snack('Client added');

View File

@ -1,4 +1,4 @@
import {action, observable} from 'mobx'; import {action, observable, makeObservable} from 'mobx';
interface HasID { interface HasID {
id: number; id: number;
@ -12,25 +12,21 @@ export interface IClearable {
* Base implementation for handling items with ids. * Base implementation for handling items with ids.
*/ */
export abstract class BaseStore<T extends HasID> implements IClearable { export abstract class BaseStore<T extends HasID> implements IClearable {
@observable
protected items: T[] = []; protected items: T[] = [];
protected abstract requestItems(): Promise<T[]>; protected abstract requestItems(): Promise<T[]>;
protected abstract requestDelete(id: number): Promise<void>; protected abstract requestDelete(id: number): Promise<void>;
@action
public remove = async (id: number): Promise<void> => { public remove = async (id: number): Promise<void> => {
await this.requestDelete(id); await this.requestDelete(id);
await this.refresh(); await this.refresh();
}; };
@action
public refresh = async (): Promise<void> => { public refresh = async (): Promise<void> => {
this.items = await this.requestItems().then((items) => items || []); this.items = await this.requestItems().then((items) => items || []);
}; };
@action
public refreshIfMissing = async (id: number): Promise<void> => { public refreshIfMissing = async (id: number): Promise<void> => {
if (this.getByIDOrUndefined(id) === undefined) { if (this.getByIDOrUndefined(id) === undefined) {
await this.refresh(); await this.refresh();
@ -50,8 +46,18 @@ export abstract class BaseStore<T extends HasID> implements IClearable {
public getItems = (): T[] => this.items; public getItems = (): T[] => this.items;
@action
public clear = (): void => { public clear = (): void => {
this.items = []; this.items = [];
}; };
constructor() {
// eslint-disable-next-line
makeObservable<BaseStore<any>, 'items'>(this, {
items: observable,
remove: action,
refresh: action,
refreshIfMissing: action,
clear: action,
});
}
} }

View File

@ -1,5 +1,5 @@
import {BaseStore} from '../common/BaseStore'; import {BaseStore} from '../common/BaseStore';
import {action, IObservableArray, observable, reaction} from 'mobx'; import {action, IObservableArray, observable, reaction, makeObservable} from 'mobx';
import axios, {AxiosResponse} from 'axios'; import axios, {AxiosResponse} from 'axios';
import * as config from '../config'; import * as config from '../config';
import {createTransformer} from 'mobx-utils'; import {createTransformer} from 'mobx-utils';
@ -16,7 +16,6 @@ interface MessagesState {
} }
export class MessagesStore { export class MessagesStore {
@observable
private state: Record<string, MessagesState> = {}; private state: Record<string, MessagesState> = {};
private loading = false; private loading = false;
@ -25,6 +24,16 @@ export class MessagesStore {
private readonly appStore: BaseStore<IApplication>, private readonly appStore: BaseStore<IApplication>,
private readonly snack: SnackReporter private readonly snack: SnackReporter
) { ) {
makeObservable<MessagesStore, 'state'>(this, {
state: observable,
loadMore: action,
publishSingleMessage: action,
removeByApp: action,
removeSingle: action,
clearAll: action,
refreshByApp: action,
});
reaction(() => appStore.getItems(), this.createEmptyStatesForApps); reaction(() => appStore.getItems(), this.createEmptyStatesForApps);
} }
@ -39,7 +48,6 @@ export class MessagesStore {
public canLoadMore = (appId: number) => this.stateOf(appId, /*create*/ false).hasMore; public canLoadMore = (appId: number) => this.stateOf(appId, /*create*/ false).hasMore;
@action
public loadMore = async (appId: number) => { public loadMore = async (appId: number) => {
const state = this.stateOf(appId); const state = this.stateOf(appId);
if (!state.hasMore || this.loading) { if (!state.hasMore || this.loading) {
@ -59,7 +67,6 @@ export class MessagesStore {
return Promise.resolve(); return Promise.resolve();
}; };
@action
public publishSingleMessage = (message: IMessage) => { public publishSingleMessage = (message: IMessage) => {
if (this.exists(AllMessages)) { if (this.exists(AllMessages)) {
this.stateOf(AllMessages).messages.unshift(message); this.stateOf(AllMessages).messages.unshift(message);
@ -69,7 +76,6 @@ export class MessagesStore {
} }
}; };
@action
public removeByApp = async (appId: number) => { public removeByApp = async (appId: number) => {
if (appId === AllMessages) { if (appId === AllMessages) {
await axios.delete(config.get('url') + 'message'); await axios.delete(config.get('url') + 'message');
@ -84,7 +90,6 @@ export class MessagesStore {
await this.loadMore(appId); await this.loadMore(appId);
}; };
@action
public removeSingle = async (message: IMessage) => { public removeSingle = async (message: IMessage) => {
await axios.delete(config.get('url') + 'message/' + message.id); await axios.delete(config.get('url') + 'message/' + message.id);
if (this.exists(AllMessages)) { if (this.exists(AllMessages)) {
@ -96,13 +101,11 @@ export class MessagesStore {
this.snack('Message deleted'); this.snack('Message deleted');
}; };
@action
public clearAll = () => { public clearAll = () => {
this.state = {}; this.state = {};
this.createEmptyStatesForApps(this.appStore.getItems()); this.createEmptyStatesForApps(this.appStore.getItems());
}; };
@action
public refreshByApp = async (appId: number) => { public refreshByApp = async (appId: number) => {
this.clearAll(); this.clearAll();
this.loadMore(appId); this.loadMore(appId);

View File

@ -1,5 +1,5 @@
import axios from 'axios'; import axios from 'axios';
import {action} from 'mobx'; import {action, makeObservable} from 'mobx';
import {BaseStore} from '../common/BaseStore'; import {BaseStore} from '../common/BaseStore';
import * as config from '../config'; import * as config from '../config';
import {SnackReporter} from '../snack/SnackManager'; import {SnackReporter} from '../snack/SnackManager';
@ -10,6 +10,11 @@ export class PluginStore extends BaseStore<IPlugin> {
public constructor(private readonly snack: SnackReporter) { public constructor(private readonly snack: SnackReporter) {
super(); super();
makeObservable(this, {
changeConfig: action,
changeEnabledState: action,
});
} }
public requestConfig = (id: number): Promise<string> => public requestConfig = (id: number): Promise<string> =>
@ -31,7 +36,6 @@ export class PluginStore extends BaseStore<IPlugin> {
return id === -1 ? 'All Plugins' : plugin !== undefined ? plugin.name : 'unknown'; return id === -1 ? 'All Plugins' : plugin !== undefined ? plugin.name : 'unknown';
}; };
@action
public changeConfig = async (id: number, newConfig: string): Promise<void> => { public changeConfig = async (id: number, newConfig: string): Promise<void> => {
await axios.post(`${config.get('url')}plugin/${id}/config`, newConfig, { await axios.post(`${config.get('url')}plugin/${id}/config`, newConfig, {
headers: {'content-type': 'application/x-yaml'}, headers: {'content-type': 'application/x-yaml'},
@ -40,7 +44,6 @@ export class PluginStore extends BaseStore<IPlugin> {
await this.refresh(); await this.refresh();
}; };
@action
public changeEnabledState = async (id: number, enabled: boolean): Promise<void> => { public changeEnabledState = async (id: number, enabled: boolean): Promise<void> => {
await axios.post(`${config.get('url')}plugin/${id}/${enabled ? 'enable' : 'disable'}`); await axios.post(`${config.get('url')}plugin/${id}/${enabled ? 'enable' : 'disable'}`);
this.snack(`Plugin ${enabled ? 'enabled' : 'disabled'}`); this.snack(`Plugin ${enabled ? 'enabled' : 'disabled'}`);

View File

@ -1,13 +1,18 @@
import {BaseStore} from '../common/BaseStore'; import {BaseStore} from '../common/BaseStore';
import axios from 'axios'; import axios from 'axios';
import * as config from '../config'; import * as config from '../config';
import {action} from 'mobx'; import {action, makeObservable} from 'mobx';
import {SnackReporter} from '../snack/SnackManager'; import {SnackReporter} from '../snack/SnackManager';
import {IUser} from '../types'; import {IUser} from '../types';
export class UserStore extends BaseStore<IUser> { export class UserStore extends BaseStore<IUser> {
constructor(private readonly snack: SnackReporter) { constructor(private readonly snack: SnackReporter) {
super(); super();
makeObservable(this, {
create: action,
update: action,
});
} }
protected requestItems = (): Promise<IUser[]> => protected requestItems = (): Promise<IUser[]> =>
@ -19,14 +24,12 @@ export class UserStore extends BaseStore<IUser> {
.then(() => this.snack('User deleted')); .then(() => this.snack('User deleted'));
} }
@action
public create = async (name: string, pass: string, admin: boolean) => { public create = async (name: string, pass: string, admin: boolean) => {
await axios.post(`${config.get('url')}user`, {name, pass, admin}); await axios.post(`${config.get('url')}user`, {name, pass, admin});
await this.refresh(); await this.refresh();
this.snack('User created'); this.snack('User created');
}; };
@action
public update = async (id: number, name: string, pass: string | null, admin: boolean) => { public update = async (id: number, name: string, pass: string | null, admin: boolean) => {
await axios.post(config.get('url') + 'user/' + id, {name, pass, admin}); await axios.post(config.get('url') + 'user/' + id, {name, pass, admin});
await this.refresh(); await this.refresh();

View File

@ -16,7 +16,6 @@
"strictNullChecks": true, "strictNullChecks": true,
"noUnusedLocals": true, "noUnusedLocals": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"skipLibCheck": true, "skipLibCheck": true,
"esModuleInterop": true, "esModuleInterop": true,
"strict": true, "strict": true,

View File

@ -10,15 +10,7 @@ export default defineConfig({
sourcemap: false, sourcemap: false,
assetsDir: 'static', assetsDir: 'static',
}, },
plugins: [ plugins: [react()],
react({
babel: {
parserOpts: {
plugins: ['decorators-legacy'],
},
},
}),
],
define: { define: {
// Some libraries use the global object, even though it doesn't exist in the browser. // Some libraries use the global object, even though it doesn't exist in the browser.
// Alternatively, we could add `<script>window.global = window;</script>` to index.html. // Alternatively, we could add `<script>window.global = window;</script>` to index.html.

View File

@ -3613,27 +3613,29 @@ mitt@^3.0.1:
resolved "https://registry.yarnpkg.com/mitt/-/mitt-3.0.1.tgz#ea36cf0cc30403601ae074c8f77b7092cdab36d1" resolved "https://registry.yarnpkg.com/mitt/-/mitt-3.0.1.tgz#ea36cf0cc30403601ae074c8f77b7092cdab36d1"
integrity sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw== integrity sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw==
mobx-react-lite@^2.2.0: mobx-react-lite@^4.1.0:
version "2.2.2" version "4.1.0"
resolved "https://registry.yarnpkg.com/mobx-react-lite/-/mobx-react-lite-2.2.2.tgz#87c217dc72b4e47b22493daf155daf3759f868a6" resolved "https://registry.yarnpkg.com/mobx-react-lite/-/mobx-react-lite-4.1.0.tgz#6a03ed2d94150848213cfebd7d172e123528a972"
integrity sha512-2SlXALHIkyUPDsV4VTKVR9DW7K3Ksh1aaIv3NrNJygTbhXe2A9GrcKHZ2ovIiOp/BXilOcTYemfHHZubP431dg== integrity sha512-QEP10dpHHBeQNv1pks3WnHRCem2Zp636lq54M2nKO2Sarr13pL4u6diQXf65yzXUn0mkk18SyIDCm9UOJYTi1w==
mobx-react@^6.3.0:
version "6.3.1"
resolved "https://registry.yarnpkg.com/mobx-react/-/mobx-react-6.3.1.tgz#204f9756e42e19d91cb6598837063b7e7de87c52"
integrity sha512-IOxdJGnRSNSJrL2uGpWO5w9JH5q5HoxEqwOF4gye1gmZYdjoYkkMzSGMDnRCUpN/BNzZcFoMdHXrjvkwO7KgaQ==
dependencies: dependencies:
mobx-react-lite "^2.2.0" use-sync-external-store "^1.4.0"
mobx-utils@^5.6.1: mobx-react@^9.2.0:
version "5.6.2" version "9.2.0"
resolved "https://registry.yarnpkg.com/mobx-utils/-/mobx-utils-5.6.2.tgz#4858acbdb03f0470e260854f87e8c2ba916ebaec" resolved "https://registry.yarnpkg.com/mobx-react/-/mobx-react-9.2.0.tgz#c1e4d1ed406f6664d9de0787c948bac3a7ed5893"
integrity sha512-a/WlXyGkp6F12b01sTarENpxbmlRgPHFyR1Xv2bsSjQBm5dcOtd16ONb40/vOqck8L99NHpI+C9MXQ+SZ8f+yw== integrity sha512-dkGWCx+S0/1mfiuFfHRH8D9cplmwhxOV5CkXMp38u6rQGG2Pv3FWYztS0M7ncR6TyPRQKaTG/pnitInoYE9Vrw==
dependencies:
mobx-react-lite "^4.1.0"
mobx@^5.15.6: mobx-utils@^6.1.1:
version "5.15.7" version "6.1.1"
resolved "https://registry.yarnpkg.com/mobx/-/mobx-5.15.7.tgz#b9a5f2b6251f5d96980d13c78e9b5d8d4ce22665" resolved "https://registry.yarnpkg.com/mobx-utils/-/mobx-utils-6.1.1.tgz#61c66563e7646fb75462c189f4110a76d2e35768"
integrity sha512-wyM3FghTkhmC+hQjyPGGFdpehrcX1KOXsDuERhfK2YbJemkUhEB+6wzEN639T21onxlfYBmriA1PFnvxTUhcKw== integrity sha512-ZR4tOKucWAHOdMjqElRl2BEvrzK7duuDdKmsbEbt2kzgVpuLuoYLiDCjc3QwWQl8CmOlxPgaZQpZ7emwNqPkIg==
mobx@^6.13.7:
version "6.13.7"
resolved "https://registry.yarnpkg.com/mobx/-/mobx-6.13.7.tgz#70e5dda7a45da947f773b3cd3b065dfe7c8a75de"
integrity sha512-aChaVU/DO5aRPmk1GX8L+whocagUUpBQqoPtJk+cm7UOXUk87J4PeWCh6nNmTTIfEhiR9DI/+FnA8dln/hTK7g==
ms@^2.1.3: ms@^2.1.3:
version "2.1.3" version "2.1.3"
@ -4543,6 +4545,11 @@ uri-js@^4.2.2:
dependencies: dependencies:
punycode "^2.1.0" punycode "^2.1.0"
use-sync-external-store@^1.4.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.5.0.tgz#55122e2a3edd2a6c106174c27485e0fd59bcfca0"
integrity sha512-Rb46I4cGGVBmjamjphe8L/UnvJD+uPPtTkNvX5mZgqdbavhI4EbgIWJiIHXJ8bc/i9EQGPRh4DwEURJ552Do0A==
vfile-message@^4.0.0: vfile-message@^4.0.0:
version "4.0.3" version "4.0.3"
resolved "https://registry.yarnpkg.com/vfile-message/-/vfile-message-4.0.3.tgz#87b44dddd7b70f0641c2e3ed0864ba73e2ea8df4" resolved "https://registry.yarnpkg.com/vfile-message/-/vfile-message-4.0.3.tgz#87b44dddd7b70f0641c2e3ed0864ba73e2ea8df4"