Skip to content

Commit 2ab560a

Browse files
authored
Merge pull request #8 from devklick/dev
Dev
2 parents a79e01a + 3546c68 commit 2ab560a

5 files changed

Lines changed: 61 additions & 15 deletions

File tree

src/components/BorderedApp/BorderedApp.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ function BorderedApp({
9999
<StyledWindowMenus className="drag-to-move">
100100
{menus?.map((m) => (
101101
<BorderedAppMenu
102+
appRef={appRef}
102103
title={m.title}
103104
items={m.items ?? []}
104105
key={m.title}

src/components/BorderedApp/BorderedAppMenu/BorderedAppMenu.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useRef, useState } from "react";
1+
import React, { useEffect, useRef, useState } from "react";
22
import useDetectMouseDownOutside from "../../../hooks/useDetectMouseDownOutside";
33
import MenuItems, { MenuItemProps } from "../../MenuItems";
44

@@ -7,18 +7,24 @@ import { StyledAppMenu } from "./styles";
77
export interface BorderedAppMenuProps {
88
title: string;
99
items: Array<MenuItemProps>;
10+
appRef: React.RefObject<HTMLDivElement>;
1011
}
1112

12-
function BorderedAppMenu({ title, items }: BorderedAppMenuProps) {
13+
function BorderedAppMenu({ title, appRef, items }: BorderedAppMenuProps) {
1314
const [open, setOpen] = useState<boolean>(false);
1415
const elementRef = useRef<HTMLDivElement>(null);
1516
const position = useRef<{ x: number; y: number }>({ x: 0, y: 0 });
1617

1718
useEffect(() => {
1819
const rect = elementRef.current?.getBoundingClientRect();
19-
// TODO: Look into where this -10 comes from
20-
position.current = { x: (rect?.left ?? 0) - 10, y: rect?.height ?? 0 };
21-
}, [elementRef]);
20+
const appRect = appRef.current?.getBoundingClientRect();
21+
if (!rect || !appRect) return;
22+
23+
position.current = {
24+
x: (rect?.left ?? 0) - appRect.left,
25+
y: rect?.height ?? 0,
26+
};
27+
}, [appRef, elementRef]);
2228

2329
// Close the menu if an outside click occurs
2430
useDetectMouseDownOutside({

src/programs/Settings/Settings.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
StyledSections,
1414
StyledSettings,
1515
} from "./styles";
16+
import Button from "../../components/Button";
1617

1718
interface SettingsSectionProps {
1819
title: string;
@@ -37,6 +38,8 @@ function SettingsSection(section: SettingsSectionProps) {
3738
return "color";
3839
case "url":
3940
return "url";
41+
case "button":
42+
return "button";
4043
default:
4144
return "text";
4245
}
@@ -62,15 +65,26 @@ function SettingsSection(section: SettingsSectionProps) {
6265
}, 1000);
6366
}
6467

65-
return (
66-
<StyledSection>
67-
<StyledSectionTitle>{section.title}</StyledSectionTitle>
68-
<StyledSectionDescription>{section.description}</StyledSectionDescription>
68+
function getInputField() {
69+
const type = getInputType(section.type);
70+
if (type === "button")
71+
return (
72+
<Button name="Restore" onClick={() => section.onValueChanged("")} />
73+
);
74+
return (
6975
<StyledSectionValue
7076
type={getInputType(section.type)}
7177
value={String(value)}
7278
onChange={handleChange}
73-
></StyledSectionValue>
79+
/>
80+
);
81+
}
82+
83+
return (
84+
<StyledSection>
85+
<StyledSectionTitle>{section.title}</StyledSectionTitle>
86+
<StyledSectionDescription>{section.description}</StyledSectionDescription>
87+
{getInputField()}
7488
</StyledSection>
7589
);
7690
}

src/programs/Settings/settingsPageConfig.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ export function getPages(
7676
systemsSettings.setIconColor(value);
7777
},
7878
},
79+
{
80+
title: "Restore Default Theme",
81+
description: "Revert to the default theme",
82+
type: "button",
83+
onValueChanged: () => systemsSettings.restoreDefaultTheme(),
84+
currentValue: undefined,
85+
},
7986
],
8087
},
8188
};

src/stores/systemSettingsStore.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
import { create } from "zustand";
22
import { persist } from "zustand/middleware";
33

4+
type FunctionPropertyNames<T> = {
5+
// eslint-disable-next-line @typescript-eslint/ban-types
6+
[K in keyof T]: T[K] extends Function ? K : never;
7+
}[keyof T];
8+
9+
type Theme = Omit<
10+
SystemSettingState,
11+
FunctionPropertyNames<SystemSettingState>
12+
>;
13+
14+
const defaultTheme: Theme = {
15+
mainColor: "#2e3440",
16+
accentColor: "#454e60",
17+
fontColor: "#ffffff",
18+
iconColor: "#9298b9",
19+
background: "https://regolith-linux.org/images/releases/nord-dark.png",
20+
};
21+
422
export interface SystemSettingState {
523
mainColor: string;
624
accentColor: string;
@@ -12,16 +30,13 @@ export interface SystemSettingState {
1230
setFontColor: (color: string) => void;
1331
setIconColor: (color: string) => void;
1432
setBackground: (url: string) => void;
33+
restoreDefaultTheme: () => void;
1534
}
1635

1736
export const useSystemSettings = create<SystemSettingState>()(
1837
persist(
1938
(set) => ({
20-
mainColor: "#2e3440",
21-
accentColor: "#454e60",
22-
fontColor: "#ffffff",
23-
iconColor: "#9298b9",
24-
background: "https://regolith-linux.org/images/releases/nord-dark.png",
39+
...defaultTheme,
2540
setAccentColor(accentColor) {
2641
set({ accentColor });
2742
},
@@ -37,6 +52,9 @@ export const useSystemSettings = create<SystemSettingState>()(
3752
setBackground(background) {
3853
set({ background });
3954
},
55+
restoreDefaultTheme() {
56+
set({ ...defaultTheme });
57+
},
4058
}),
4159
{
4260
name: "system-settings",

0 commit comments

Comments
 (0)