Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/Apps/Settings/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from "react";
import { useAppDispatch, useAppSelector } from "../../../app/hooks.ts";
import { setAppBarWidth, setInfoBarHeight } from "../../../features/personalisation/PersonalisationSlice.ts";
import { setAppBarWidth, setInfoBarHeight, setInfoBarTimeFormat } from "../../../features/personalisation/PersonalisationSlice.ts";


function Settings() {
Expand All @@ -24,6 +24,12 @@ function Settings() {
value={useAppSelector((state) => state.personalisation.infoBarHeight)}
onChange={(e) => dispatch(setInfoBarHeight(e.target.valueAsNumber))}
/>
<p>InfoBarTimeFormat (use <a target={"_blank"} href="https://day.js.org/docs/en/display/format">this format</a>)</p>
<input
type="text"
value={useAppSelector((state) => state.personalisation.infoBarTimeFormat)}
onChange={(e) => dispatch(setInfoBarTimeFormat(e.target.value))}
/>
</>
);
}
Expand Down
13 changes: 10 additions & 3 deletions src/components/InfoBar/InfoBar.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import "./InfoBar.css";
import { useEffect, useState } from "react";
import { useEffect, useRef, useState } from "react";
import dayjs from "dayjs";
import { useAppSelector } from "../../app/hooks.ts";

function InfoBar() {
const infoBarHeight = useAppSelector(
(state) => state.personalisation.infoBarHeight
);
const infoBarTimeFormat = useAppSelector(
(state) => state.personalisation.infoBarTimeFormat
);
const intervalId = useRef<null | number>(null)

const [time, setTime] = useState(dayjs().format("DD MMM HH:mm"));

useEffect(() => {
setInterval(() => setTime(dayjs().format("DD MMM HH:mm")), 3000);
}, []);
if (intervalId.current){
clearInterval(intervalId.current)
}
intervalId.current = setInterval(() => setTime(dayjs().format(infoBarTimeFormat)), 1000);
}, [infoBarTimeFormat]);

return (
<header id={"infoBar"} style={{ height: infoBarHeight }}>
Expand Down
7 changes: 6 additions & 1 deletion src/features/personalisation/PersonalisationSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import ThemeType from "./ThemeType.ts";
interface PersonalisationState {
appBarWidth: number;
infoBarHeight: number;
infoBarTimeFormat: string;
theme: ThemeType;
}

const initialState: PersonalisationState = {
appBarWidth: 70,
infoBarHeight: 23,
infoBarTimeFormat: "DD MMM HH:mm",
theme: {
fontColor: "#FFF",
firstColor: "#2c2c2c",
Expand All @@ -28,12 +30,15 @@ const personalisationSlice = createSlice({
setInfoBarHeight: (state, action: PayloadAction<number>) => {
state.infoBarHeight = action.payload;
},
setInfoBarTimeFormat: (state, action: PayloadAction<string>) => {
state.infoBarTimeFormat = action.payload;
},
setTheme: (state, action: PayloadAction<ThemeType>) => {
state.theme = action.payload;
},
},
});
export const { setAppBarWidth, setInfoBarHeight, setTheme } =
export const { setAppBarWidth, setInfoBarHeight, setTheme, setInfoBarTimeFormat } =
personalisationSlice.actions;

export default personalisationSlice.reducer;