-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
141 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.toys-container { | ||
display: flex; | ||
justify-content: space-between; | ||
flex-direction: column; | ||
align-items: stretch; | ||
font-size: 1rem; | ||
min-width: 400px; | ||
border-radius: var(--container-border-radius); | ||
padding: 10px; | ||
margin: 20px; | ||
background-color: var(--toys-container); | ||
box-shadow: 5px 5px 5px var(--toys-container-shadow); | ||
} | ||
|
||
.toy-container { | ||
font-size: 2rem; | ||
min-height: 100px; | ||
border-radius: var(--container-border-radius); | ||
margin: 10px; | ||
background-color: var(--item); | ||
box-shadow: 5px 5px 10px var(--item-shadow); | ||
animation: enter-ani 250ms ease-out; | ||
} | ||
.toy { | ||
display: flex; | ||
justify-content: space-around; | ||
align-items: center; | ||
} | ||
.toy-container .accordion { | ||
padding-bottom: var(--container-border-radius); | ||
} | ||
.toy-container .accordion-body { | ||
max-width: 360px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Accordion, Badge } from "react-bootstrap"; | ||
import { useToys } from "../context/ToysContext"; | ||
import { percent } from "../utils"; | ||
import NameBadge from "./NameBadge"; | ||
import ToyFeatureForm from "./ToyFeatureForm"; | ||
import "./Toys.css"; | ||
|
||
export default function () { | ||
const { toys } = useToys(); | ||
|
||
return ( | ||
<div className="toys-container"> | ||
<h1 className="grad-text">Connected toys</h1> | ||
{toys.length == 0 ? ( | ||
<div>None</div> | ||
) : ( | ||
toys.map((toy) => ( | ||
<div className="toy-container" key={toy.toy_id}> | ||
<div className="toy"> | ||
<NameBadge name={toy.toy_name} /> | ||
<div | ||
style={{ | ||
color: `hsl(${toy.battery_level * 120}, 100%, 50%)`, | ||
}} | ||
> | ||
{percent.format(toy.battery_level)} | ||
</div> | ||
</div> | ||
<Accordion> | ||
{toy.features.map((feature) => ( | ||
<Accordion.Item | ||
eventKey={feature.feature_index.toString()} | ||
key={feature.feature_index} | ||
> | ||
<Accordion.Header> | ||
<Badge | ||
bg={feature.feature_enabled ? "success" : "danger"} | ||
>{`${feature.feature_type} ${feature.feature_index}`}</Badge> | ||
</Accordion.Header> | ||
<Accordion.Body> | ||
<ToyFeatureForm toyId={toy.toy_id} feature={feature} /> | ||
</Accordion.Body> | ||
</Accordion.Item> | ||
))} | ||
</Accordion> | ||
</div> | ||
)) | ||
)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { invoke } from "@tauri-apps/api"; | ||
import { createContext, ReactNode, useContext, useState } from "react"; | ||
import { FeVCToy } from "../../src-tauri/bindings/FeVCToy"; | ||
import { GET_TOYS } from "../data/constants"; | ||
|
||
const ToysContext = createContext<{ toys: FeVCToy[]; refetchToys: () => void }>( | ||
{ toys: [], refetchToys: () => null } | ||
); | ||
|
||
export function useToys() { | ||
return useContext(ToysContext); | ||
} | ||
|
||
export function ToysProvider({ children }: { children: ReactNode }) { | ||
const [toys, setToys] = useState<FeVCToy[]>([]); | ||
|
||
async function refetchToys() { | ||
await invoke<null | { [key: number]: FeVCToy }>(GET_TOYS).then((response) => | ||
setToys(response ? Object.values(response) : []) | ||
); | ||
} | ||
|
||
return ( | ||
<ToysContext.Provider value={{ toys, refetchToys }}> | ||
{children} | ||
</ToysContext.Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters