update notice

This commit is contained in:
ari committed 2022-09-06 20:38:07 -04:00
1 parent df95265af0
commit 2dca59fa3f
9 files changed
+174 -46

No files matched your search

+4 -3
View File
@@ -21,10 +21,11 @@ export type APIResponse<D> =
};
export type Waitable<D> =
| { ready: undefined }
| ({ ready: true } & APIResponse<D>)
| ({ ready: true } & D)
| {
ready: false;
};
export type ApiWaitable<D> = Waitable<APIResponse<D>>;
export interface ListData<D> {
params: ListParams;
totalItems: number;
@@ -32,8 +33,8 @@ export interface ListData<D> {
}
export interface ApiState {
automations: Waitable<ListData<AutomationData>>;
userProfile: Waitable<UserProfile>;
automations: ApiWaitable<ListData<AutomationData>>;
userProfile: ApiWaitable<UserProfile>;
}
export type UserProfile = {
+4
View File
@@ -19,6 +19,7 @@
"TEMPLATE": "Template",
"MODE": "Mode",
"CLOSE": "Close",
"CONFIRM": "Confirm",
"DESCRIPTION": "Description",
"TRIGGER": "Trigger",
"CONDITION": "Condition",
@@ -43,6 +44,9 @@
"YES": "Yes",
"NO": "No",
"NEW_VERSION_AVAILABLE": "New Version is Available!",
"NEW_VERSION_AVAILABLE_BODY": "Installed version: {{current}}\nLatest version: {{latest}}",
"SERVICE": "Service",
"REPEAT": "Repeat",
"WAIT": "Wait",
+4
View File
@@ -20,6 +20,7 @@
"TEMPLATE": "Modèle",
"MODE": "Mode",
"CLOSE": "Fermer",
"CONFIRM": "Confirmer",
"DESCRIPTION": "Description",
"TRIGGER": "Déclencheur",
"TRIGGERS": "Déclencheurs",
@@ -46,6 +47,9 @@
"YES": "Oui",
"NO": "Non",
"NEW_VERSION_AVAILABLE": "Une nouvelle version est disponible!",
"NEW_VERSION_AVAILABLE_BODY": "Version installée : {{current}}\nDernière version : {{latest}}",
"SERVICE": "Service",
"REPEAT": "Répéter",
"WAIT": "Attendre",
@@ -1,11 +1,39 @@
import { useApiState } from "services/api";
import { useEffect, useState } from "react";
import {
FC,
useEffect,
useState,
createContext,
PropsWithChildren,
useContext,
} from "react";
import { Waitable } from "../api/types";
const MISSING_TEXT = "<<MISSING TEXT -- {{langId}}>>";
const LOADING_TEXT = "...";
export type LangStore = ReturnType<typeof useLang>;
export const useLang = () => {
export type LangStore = {
get(langId: string, replacements?: Record<string, string>): string;
};
const LangContext = createContext<Waitable<LangStore>>({
ready: false,
});
export const useLang = (): LangStore & { ready: boolean } => {
const langState = useContext(LangContext);
if (langState.ready) {
return langState;
}
return {
ready: false,
get() {
return LOADING_TEXT;
},
};
};
export const LangProvider: FC<PropsWithChildren> = ({ children }) => {
const apiState = useApiState();
const [langStore, setLangStore] =
useState<Record<string, string> | null>(null);
@@ -37,7 +65,7 @@ export const useLang = () => {
return text;
};
return {
const methods = {
get: (langId: string, replacements: Record<string, string> = {}) => {
let out = LOADING_TEXT;
if (langStore !== null) {
@@ -54,4 +82,14 @@ export const useLang = () => {
return updateParams(out, { ...replacements, langId });
},
};
const value: Waitable<LangStore> =
langStore === null && langEngStore === null
? { ready: false }
: {
ready: true,
...methods,
};
return <LangContext.Provider value={value}>{children}</LangContext.Provider>;
};
+4
View File
@@ -19,6 +19,7 @@
"TEMPLATE": "Modello",
"MODE": "Modalità",
"CLOSE": "Chiudi",
"CONFIRM": "Confermare",
"DESCRIPTION": "Descrizione",
"TRIGGER": "Attivazione",
"CONDITION": "Condizione",
@@ -43,6 +44,9 @@
"YES": "Sì",
"NO": "No",
"NEW_VERSION_AVAILABLE": "È disponibile una nuova versione!",
"NEW_VERSION_AVAILABLE_BODY": "Versione installata: {{current}}\nUltima versione: {{latest}}",
"SERVICE": "Chiama Servizio",
"REPEAT": "Ripeti",
"WAIT": "Attesa",
@@ -0,0 +1,56 @@
import { parseVersion, Version } from ".";
import { VersionComp, compareVersions } from "./index";
for (const [verStr, expectedVer] of [
[
"1.2.3",
{
main: 1,
minor: 2,
patch: 3,
extra: "",
},
],
[
"20.1.10",
{
main: 20,
minor: 1,
patch: 10,
extra: "",
},
],
[
"20.1.10-g1234",
{
main: 20,
minor: 1,
patch: 10,
extra: "g1234",
},
],
["x.1.10-g1234", null],
["2.x1.10-g1234", null],
["2.123x.10-g1234", null],
["2.123.10g1234", null],
] as [string, Version | null][]) {
test(`parse version - ${verStr} to be ${JSON.stringify(expectedVer)}`, () => {
const version = parseVersion(verStr);
expect(version).toEqual(expectedVer);
});
}
for (const [lh, rh, comp] of [
[parseVersion("1.1.0"), parseVersion("1.1.0"), null],
[null, null, null],
[parseVersion("1.1.0"), parseVersion("1.1.0"), null],
[parseVersion("1.2.0"), parseVersion("1.1.0"), "left"],
[parseVersion("1.2.0"), parseVersion("1.3.0"), "right"],
[parseVersion("1.2.0"), parseVersion("2.2.0"), "right"],
[parseVersion("1.2.0"), parseVersion("1.2.1"), "right"],
[parseVersion("3.2.1"), parseVersion("1.2.1"), "right"],
[parseVersion("1.3.1"), parseVersion("1.2.1"), "right"],
[parseVersion("1.2.2"), parseVersion("1.2.1"), "right"],
] as Array<[Version | null, Version | null, VersionComp]>)
test(`compare versions ${lh} ? ${rh} = ${comp}`, () => {
expect(compareVersions(lh, rh) === comp);
});