Skip to content

Commit d9ae2fc

Browse files
committed
Based on: Disable user-select on widgets joelshepherd#696
This might be the worst react code ever (I've never used react before 💀). I have no other idea on how to do this. Somebody else please fix it. It does work great though, adds a setting to enable/disable highlighting of the widgets as some people might want this and others hate it. DEFAULT is TRUE
1 parent 3fdba86 commit d9ae2fc

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

src/db/state.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ export interface State {
1717
locale: string;
1818
/** Time zone selected, if any */
1919
timeZone: string | null;
20+
/** Whether highlighting is enabled */
21+
highlightingEnabled: boolean;
2022
}
2123

24+
2225
export interface BackgroundState {
2326
id: string;
2427
key: string;
@@ -87,8 +90,10 @@ const initData: State = {
8790
focus: false,
8891
locale: defaultLocale,
8992
timeZone: null,
93+
highlightingEnabled: true, // Initialize as true
9094
};
9195

96+
9297
// Database storage
9398
export const db = DB.init<State>(initData);
9499

src/views/App.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ import { Dashboard } from "./dashboard";
99
import { Settings } from "./settings";
1010
import Errors from "./shared/Errors";
1111
import StoreError from "./shared/StoreError";
12+
import { db } from "../db/state";
13+
14+
function setHighlighting(){
15+
const checked = db.cache.get('highlightingEnabled');
16+
console.log(checked);
17+
const element = document.querySelector(".Widgets") as HTMLElement;
18+
if (element) {
19+
if (checked || checked === undefined) {
20+
element.style.userSelect = "auto";
21+
} else{
22+
element.style.userSelect = "none";
23+
}
24+
}
25+
}
1226

1327
const messages = defineMessages({
1428
pageTitle: {
@@ -80,6 +94,9 @@ const Root: React.FC = () => {
8094
subscriptions.then(() => {
8195
setReady(true);
8296
migrate();
97+
setTimeout(() => {
98+
setHighlighting();
99+
}, 1);
83100
});
84101

85102
return () => {

src/views/settings/System.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ import TimeZoneInput from "../shared/timeZone/TimeZoneInput";
77
const System: React.FC = () => {
88
const [locale, setLocale] = useKey(db, "locale");
99
const [timeZone, setTimeZone] = useKey(db, "timeZone");
10+
const [highlightingEnabled, setHighlightingEnabled] = useKey(db, "highlightingEnabled");
11+
12+
function setHighlighting(checked: boolean){
13+
setHighlightingEnabled(checked);
14+
const element = document.querySelector(".Widgets") as HTMLElement;
15+
if (element) {
16+
if (checked) {
17+
element.style.userSelect = "auto";
18+
} else{
19+
element.style.userSelect = "none";
20+
}
21+
}
22+
}
1023

1124
return (
1225
<div>
@@ -184,6 +197,24 @@ const System: React.FC = () => {
184197
Time Zone
185198
<TimeZoneInput timeZone={timeZone} onChange={setTimeZone} />
186199
</label>
200+
201+
<label
202+
style={{
203+
alignItems: "center",
204+
display: "grid",
205+
gridGap: "0 0.5rem",
206+
gridTemplateColumns: "1fr 2fr",
207+
width: "100%",
208+
margin: 0,
209+
}}
210+
>
211+
<span>Allow Highlighting</span>
212+
<input
213+
type="checkbox"
214+
checked={highlightingEnabled}
215+
onChange={(e) => setHighlighting(e.target.checked)}
216+
/>
217+
</label>
187218
</div>
188219
);
189220
};

0 commit comments

Comments
 (0)