-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBottomInformationContainer.tsx
More file actions
64 lines (58 loc) · 2.2 KB
/
BottomInformationContainer.tsx
File metadata and controls
64 lines (58 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { useCallback } from "react";
import usePIS from "@/hooks/PIS/usePIS";
import { useFavouriteLookupTable } from "@/hooks/favouriteLookupTable";
import type I_PIS from "@/objects/PIS/PIS.interface";
import { useAppState } from "@/stores/useAppState";
function BottomInformationContainer() {
const { currentAppState, setCurrentAppState } = useAppState();
const { battery, mbms, motor, mppt } = usePIS();
const dataArray = [battery, motor, mppt, mbms].filter(
(data) => data !== undefined,
) as I_PIS[];
const lookupTable = useFavouriteLookupTable(dataArray);
const favourites = currentAppState.favourites;
const handleRemoveFavourite = useCallback(
(favourite: string) => {
const newFavourites = favourites.filter((item) => item !== favourite);
setCurrentAppState((prev) => ({
...prev,
favourites: newFavourites,
}));
localStorage.setItem("favourites", JSON.stringify(newFavourites));
return;
},
[currentAppState, favourites],
);
const formatPathLabel = (path: string) =>
path
.split(".")
.map(
(segment) =>
segment
.replace(/([a-z])([A-Z])/g, "$1 $2") // lowerUpper → lower Upper
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2") // ABCDef → ABC Def
.replace(/([a-zA-Z])(\d)/g, "$1 $2"), // Unit3 → Unit 3
)
.join(" "); // use " " or " →" or " / " if preferred
return (
<div className="align-middle">
<div className="flex h-full flex-row flex-wrap justify-evenly gap-4 pt-1 text-center text-base md:gap-2 2xl:text-xl">
{favourites.map((favourite: string, index: number) => (
<div className="min-w-32 p-3" key={index}>
<div
className="text-xs hover:cursor-pointer 2xl:text-sm"
onClick={() => handleRemoveFavourite(favourite)}
>
{formatPathLabel(favourite)}
</div>
<div className="text-helios">
{/*Search for the value associated with the favourite name string in the lookupTable */
lookupTable[favourite]?.()}
</div>
</div>
))}
</div>
</div>
);
}
export default BottomInformationContainer;