Skip to content

Commit

Permalink
Add initial group settings
Browse files Browse the repository at this point in the history
  • Loading branch information
amberstarlight committed Apr 20, 2024
1 parent 2803d99 commit a01484e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
22 changes: 22 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Groups from "./pages/Groups/Groups";
import Button from "./components/Button/Button";
import DeviceSettings from "./components/DeviceSettings/DeviceSettings";
import { type Device, type Group } from "../../types/zigbee_types";
import GroupSettings from "./components/GroupSettings/GroupSettings";

const Wrapper = styled.div`
padding: 2em;
Expand Down Expand Up @@ -93,6 +94,27 @@ function App() {
<Groups groups={groups} />
</Route>

<Route path={"/groups/:groupId"}>
{(params) => {
if (!groups) return <></>;

const group: Group = groups.find(
(group: Group) =>
group.id === parseInt(decodeURIComponent(params.groupId)),
);

if (!group)
return (
<StyledText>
Group with ID <code>{params.groupId}</code> does not exist on
this network.
</StyledText>
);

return <GroupSettings group={group} />;
}}
</Route>

<Route path={"/settings"}>
<Settings bridgeState={{}} />
</Route>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/GroupCard/GroupCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Card = styled.div`
function GroupCard(props: { group: Group; onClick: Function }) {
return (
<Card onClick={props.onClick}>
<StyledHeader>{props.group.friendly_name}</StyledHeader>
<StyledHeader>📂 {props.group.friendly_name}</StyledHeader>
<StyledText>{`${props.group.members.length} devices`}</StyledText>
</Card>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/GroupList/GroupList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function GroupList(props: { groups: Group[]; onClick?: Function }) {
<div>
{props.groups.map((group: Group) => (
<Link href={`/groups/${group.id}`} key={group.id}>
<GroupCard group={group} onClick={() => props.onClick} />
<GroupCard group={group} onClick={props.onClick} />
</Link>
))}
</div>
Expand Down
49 changes: 49 additions & 0 deletions frontend/src/components/GroupSettings/GroupSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-FileCopyrightText: © 2024 Amber Cronin <software@amber.vision>
// SPDX-License-Identifier: AGPL-3.0-or-later

import { useState, useEffect } from "react";

import LoadingSpinner from "../LoadingSpinner/LoadingSpinner";
import EditableText from "../EditableText/EditableText";

const backend = import.meta.env.VITE_API_URL ?? "";

function GroupSettings(props) {
const [groupSettingsState, setGroupSettingsState] = useState();
const [groupFriendlyNameState, setGroupFriendlyNameState] = useState(
props.group.friendly_name,
);

useEffect(() => {
fetch(`${backend}/api/groups/${props.group.id}/state`)
.then((res) => res.json())
.then((data) => setGroupSettingsState(data.data));
}, []);

if (!groupSettingsState) return <LoadingSpinner />;

return (
<>
<div>
<EditableText
text={groupFriendlyNameState}
fontSize={"2em"}
onChange={(event) => {
const newFriendlyName = event.target.value;
setGroupFriendlyNameState(newFriendlyName);
}}
// onEditFinish={() => {
// setGroupFriendlyName(
// props.group.friendly_name,
// groupFriendlyNameState,
// );
// }}
/>
</div>

<div>"todo"</div>
</>
);
}

export default GroupSettings;
1 change: 1 addition & 0 deletions frontend/src/pages/Groups/Groups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import LoadingSpinner from "../../components/LoadingSpinner/LoadingSpinner";
import GroupList from "../../components/GroupList/GroupList";
import GroupSettings from "../../components/GroupSettings/GroupSettings";

function Groups(props) {
const selectedGroup = props.selectedGroup;
Expand Down

0 comments on commit a01484e

Please sign in to comment.