functioning profiles
This commit is contained in:
1 parent
8985312dd2
commit
d890c1aa64
17 files changed
+136
-78
No files matched your search
@@ -23,10 +23,16 @@ export const useAPIService = (
|
||||
|
||||
// initial load of autos
|
||||
useEffect(() => {
|
||||
autoManager.reload();
|
||||
userProfileManager.reload();
|
||||
// eslint-disable-next-line
|
||||
}, []);
|
||||
if (state.automations.ready === undefined) {
|
||||
autoManager.reload();
|
||||
}
|
||||
}, [state.automations.ready, autoManager]);
|
||||
// initial load of profile
|
||||
useEffect(() => {
|
||||
if (state.userProfile.ready === undefined) {
|
||||
userProfileManager.reload();
|
||||
}
|
||||
}, [state.userProfile.ready, userProfileManager]);
|
||||
|
||||
return {
|
||||
state: {
|
||||
|
||||
@@ -15,7 +15,7 @@ const baseURL = new URL(
|
||||
);
|
||||
export const wsURL = baseURL + "socket";
|
||||
export const remoteAutoAPI = makeRemoteAPI(baseURL + "automations");
|
||||
export const detailsAPI = makeRemoteAPI(baseURL + "details/");
|
||||
export const detailsAPI = makeRemoteAPI(baseURL + "details");
|
||||
export const useConnectedApiService = () =>
|
||||
useAPIService(makeAutomationAPI(remoteAutoAPI), makeProfileAPI(detailsAPI));
|
||||
export const useMockApiService = (
|
||||
|
||||
@@ -19,7 +19,8 @@ export type APIResponse<D> =
|
||||
ok: false;
|
||||
error: string;
|
||||
};
|
||||
export type Errorable<D> =
|
||||
export type Waitable<D> =
|
||||
| { ready: undefined }
|
||||
| ({ ready: true } & APIResponse<D>)
|
||||
| {
|
||||
ready: false;
|
||||
@@ -31,8 +32,8 @@ export interface ListData<D> {
|
||||
}
|
||||
|
||||
export interface ApiState {
|
||||
automations: Errorable<ListData<AutomationData>>;
|
||||
userProfile: Errorable<UserProfile>;
|
||||
automations: Waitable<ListData<AutomationData>>;
|
||||
userProfile: Waitable<UserProfile>;
|
||||
}
|
||||
|
||||
export type UserProfile = {
|
||||
|
||||
@@ -6,8 +6,8 @@ import { UserProfile } from "apiService/types";
|
||||
|
||||
export const useDefaultApiState = () =>
|
||||
useState<ApiState>({
|
||||
automations: { ready: false },
|
||||
userProfile: { ready: false },
|
||||
automations: { ready: undefined },
|
||||
userProfile: { ready: undefined },
|
||||
});
|
||||
|
||||
export const makeReloadAutomations = (
|
||||
@@ -76,6 +76,15 @@ export const makeProfileManager = (
|
||||
userProfileAPI
|
||||
.update(data)
|
||||
.then(() => reload())
|
||||
.catch(() => reload()),
|
||||
.catch((err) =>
|
||||
setState({
|
||||
...state,
|
||||
userProfile: {
|
||||
ok: false,
|
||||
error: String(err),
|
||||
ready: true,
|
||||
},
|
||||
})
|
||||
),
|
||||
};
|
||||
};
|
||||
@@ -9,12 +9,15 @@ import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
|
||||
import SelectIcon from "@mui/icons-material/HighlightAltSharp";
|
||||
import RunIcon from "@mui/icons-material/RunCircleOutlined";
|
||||
|
||||
import Tooltip from "@mui/material/Tooltip";
|
||||
import Box from "@mui/material/Box";
|
||||
import Chip from "@mui/material/Chip";
|
||||
|
||||
import { InputTextView } from "components/Inputs/InputTextView";
|
||||
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||
import { AutomationManagerAuto } from "../types";
|
||||
import { Tags } from "./Tags";
|
||||
import { TagDB } from "../TagDB";
|
||||
import { Chip, Tooltip } from "@mui/material";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type MetadataBoxProps = AutomationManagerAuto & {
|
||||
@@ -34,7 +37,7 @@ export const MetadataBox: FC<MetadataBoxProps> = (props) => {
|
||||
? langStore.get(`AUTOMATION_STATE_${props.state}`)
|
||||
: props.state;
|
||||
return (
|
||||
<div
|
||||
<Box
|
||||
className={[
|
||||
"automation-manager--metadatabox",
|
||||
props.isSelected ? "selected" : "",
|
||||
@@ -79,15 +82,18 @@ export const MetadataBox: FC<MetadataBoxProps> = (props) => {
|
||||
/>
|
||||
</Tooltip>
|
||||
</span>
|
||||
<Tooltip title={`ID=${props.id}, EntityID=${props.entityId}`}>
|
||||
<InputTextView
|
||||
className="title"
|
||||
placeholder={langStore.get("TITLE")}
|
||||
value={props.title}
|
||||
onChange={props.onTitleUpdate}
|
||||
disabled={props.isNew}
|
||||
/>
|
||||
</Tooltip>
|
||||
<InputTextView
|
||||
titleSlug="AUTOMATION_METADATA_TOOLTIP_SIMPLE"
|
||||
titleParams={{
|
||||
id: props.id,
|
||||
entityId: props.entityId,
|
||||
}}
|
||||
className="title"
|
||||
placeholder={langStore.get("TITLE")}
|
||||
value={props.title}
|
||||
onChange={props.onTitleUpdate}
|
||||
disabled={props.isNew}
|
||||
/>
|
||||
<InputTextView
|
||||
className="description"
|
||||
placeholder={langStore.get("DESCRIPTION")}
|
||||
@@ -106,24 +112,24 @@ export const MetadataBox: FC<MetadataBoxProps> = (props) => {
|
||||
</div>
|
||||
<div className="buttons">
|
||||
<ButtonIcon
|
||||
titleSlug="SELECT_AUTOMATION"
|
||||
className="select"
|
||||
icon={<SelectIcon />}
|
||||
onClick={props.onSelect}
|
||||
title={langStore.get("SELECT_AUTOMATION")}
|
||||
/>
|
||||
<ButtonIcon
|
||||
titleSlug="TRIGGER_AUTOMATION"
|
||||
className="run"
|
||||
icon={<RunIcon />}
|
||||
onClick={props.onRun}
|
||||
title={langStore.get("TRIGGER_AUTOMATION")}
|
||||
/>
|
||||
<ButtonIcon
|
||||
titleSlug="DELETE_AUTOMATION"
|
||||
className="delete"
|
||||
icon={<DeleteForeverIcon />}
|
||||
onClick={props.onDelete}
|
||||
title={langStore.get("DELETE_AUTOMATION")}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -40,4 +40,11 @@
|
||||
.bottom-bar .settings svg {
|
||||
height: 0.5em;
|
||||
width: 0.5em;
|
||||
}
|
||||
|
||||
.user-profile {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-width: 10em;
|
||||
min-height: 10em;
|
||||
}
|
||||
@@ -34,7 +34,7 @@ export const BottomBar: FC<BottomBarProps> = ({ api }) => {
|
||||
<span>version: {version}</span>
|
||||
<Button className="settings" onClick={() => setOpen(!isOpen)}>
|
||||
<SettingsSuggestOutlinedIcon />
|
||||
settings
|
||||
{lang.get("USER_PRERENCES")}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import "./ButtonIcons.css";
|
||||
import Tooltip from "@mui/material/Tooltip";
|
||||
import { FC, ReactNode } from "react";
|
||||
import MuiIconButton, { IconButtonTypeMap } from "@mui/material/IconButton";
|
||||
import IconButton, { IconButtonTypeMap } from "@mui/material/IconButton";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type ButtonIconProps = {
|
||||
icon: ReactNode;
|
||||
@@ -10,21 +12,31 @@ export type ButtonIconProps = {
|
||||
disabled?: boolean;
|
||||
color?: IconButtonTypeMap["props"]["color"];
|
||||
borderless?: boolean;
|
||||
titleSlug?: string;
|
||||
titleParams?: Record<string, string>;
|
||||
};
|
||||
export const ButtonIcon: FC<ButtonIconProps> = (props) => {
|
||||
const langStore = useLang();
|
||||
return (
|
||||
<MuiIconButton
|
||||
className={[
|
||||
"icon-button",
|
||||
props.className ?? "",
|
||||
props.borderless ? "borderless" : "",
|
||||
].join(" ")}
|
||||
onClick={props.onClick}
|
||||
title={props.title}
|
||||
color={props.color}
|
||||
disabled={props.disabled}
|
||||
<Tooltip
|
||||
title={
|
||||
props.titleSlug ? langStore.get(props.titleSlug, props.titleParams) : ""
|
||||
}
|
||||
describeChild
|
||||
>
|
||||
{props.icon}
|
||||
</MuiIconButton>
|
||||
<IconButton
|
||||
className={[
|
||||
"icon-button",
|
||||
props.className ?? "",
|
||||
props.borderless ? "borderless" : "",
|
||||
].join(" ")}
|
||||
onClick={props.onClick}
|
||||
title={props.title}
|
||||
color={props.color}
|
||||
disabled={props.disabled}
|
||||
>
|
||||
{props.icon}
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
@@ -4,6 +4,8 @@ import { FC, PropsWithChildren, useState } from "react";
|
||||
import CheckCircleOutlineOutlinedIcon from "@mui/icons-material/CheckCircleOutlineOutlined";
|
||||
import ModeEditOutlineOutlinedIcon from "@mui/icons-material/ModeEditOutlineOutlined";
|
||||
import TextField from "@mui/material/TextField";
|
||||
import Tooltip from "@mui/material/Tooltip";
|
||||
import { useLang } from "lang";
|
||||
|
||||
export type InputTextViewProps = {
|
||||
className?: string;
|
||||
@@ -12,11 +14,15 @@ export type InputTextViewProps = {
|
||||
initialViewMode?: boolean;
|
||||
placeholder?: string;
|
||||
disabled?: boolean;
|
||||
borderless?: boolean;
|
||||
titleSlug?: string;
|
||||
titleParams?: Record<string, string>;
|
||||
};
|
||||
|
||||
export const InputTextView: FC<PropsWithChildren<InputTextViewProps>> = (
|
||||
props
|
||||
) => {
|
||||
const langStore = useLang();
|
||||
const [viewMode, setViewMode] = useState(props.initialViewMode ?? true);
|
||||
const [text, setText] = useState(props.value);
|
||||
const className = [
|
||||
@@ -27,24 +33,33 @@ export const InputTextView: FC<PropsWithChildren<InputTextViewProps>> = (
|
||||
|
||||
if (viewMode) {
|
||||
return (
|
||||
<div
|
||||
className={className}
|
||||
onClick={() => !props.disabled && setViewMode(false)}
|
||||
<Tooltip
|
||||
title={
|
||||
props.titleSlug
|
||||
? langStore.get(props.titleSlug, props.titleParams)
|
||||
: ""
|
||||
}
|
||||
describeChild
|
||||
>
|
||||
{!!props.value ? (
|
||||
<div className="input-text-view--text text-ellipsis">
|
||||
<span>{props.value}</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="input-text-view--text input-text-view--placeholder text-ellipsis">
|
||||
<span>{props.placeholder}</span>
|
||||
</div>
|
||||
)}
|
||||
{!props.disabled && (
|
||||
<ModeEditOutlineOutlinedIcon className="input-text-view--edit" />
|
||||
)}
|
||||
{props.children}
|
||||
</div>
|
||||
<div
|
||||
className={className}
|
||||
onClick={() => !props.disabled && setViewMode(false)}
|
||||
>
|
||||
{!!props.value ? (
|
||||
<div className="input-text-view--text text-ellipsis">
|
||||
<span>{props.value}</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="input-text-view--text input-text-view--placeholder text-ellipsis">
|
||||
<span>{props.placeholder}</span>
|
||||
</div>
|
||||
)}
|
||||
{!props.disabled && (
|
||||
<ModeEditOutlineOutlinedIcon className="input-text-view--edit" />
|
||||
)}
|
||||
{props.children}
|
||||
</div>
|
||||
</Tooltip>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
|
||||
+5
-11
@@ -1,24 +1,18 @@
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import "./styles/root.css";
|
||||
import App from "./App";
|
||||
import reportWebVitals from "./reportWebVitals";
|
||||
|
||||
ReactDOM.render(
|
||||
import { createRoot } from "react-dom/client";
|
||||
const container = document.getElementById("root");
|
||||
const root = createRoot(container!);
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
document.getElementById("root")
|
||||
</React.StrictMode>
|
||||
);
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
// to log results (for example: reportWebVitals(console.info))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
reportWebVitals(console.info);
|
||||
|
||||
// import { createRoot } from 'react-dom/client';
|
||||
// const container = document.getElementById('root');
|
||||
// const root = createRoot(container!);
|
||||
// root.render(<React.StrictMode>
|
||||
// <App />
|
||||
// </React.StrictMode>);
|
||||
@@ -77,6 +77,8 @@
|
||||
"THEME": "Theme",
|
||||
"LANGUAGE": "Language",
|
||||
|
||||
"USER_PRERENCES": "Settings",
|
||||
|
||||
"SELECT_AUTOMATION": "Select automation",
|
||||
"TRIGGER_AUTOMATION": "Trigger automation",
|
||||
"DELETE_AUTOMATION": "Delete automation",
|
||||
@@ -91,6 +93,7 @@
|
||||
"MISSING_TEXT": "MISSING TEXT -- {{langId}}",
|
||||
|
||||
"AUTOMATION_METADATA_TOOLTIP_TEXT": "This automation is located in the file {{source_file}}. It's currently '{{state}}', it's entity id is '{{entityId}}' and it's automation id is '{{id}}'",
|
||||
"AUTOMATION_METADATA_TOOLTIP_SIMPLE": "ID={{id}}, EntityID={{entityId}}",
|
||||
|
||||
"ERROR_FAILED_TO_SAVE": "Failed to save automation \"{{aid}}\" contents - {{contents}} -- not found in `/config`",
|
||||
"ERROR_INVALID_AUTOMATION_STATE": "Invalid state",
|
||||
|
||||
@@ -80,6 +80,8 @@
|
||||
"THEME": "Thème",
|
||||
"LANGUAGE": "Langue",
|
||||
|
||||
"USER_PRERENCES": "Préférences de l'utilisateur",
|
||||
|
||||
"SELECT_AUTOMATION": "Sélectionnez l'automatisation",
|
||||
"TRIGGER_AUTOMATION": "Déclencher l'automatisation",
|
||||
"DELETE_AUTOMATION": "Supprimer l'automatisation",
|
||||
|
||||
Reference in new issue
Block a user