Skip to content

Commit 98387b7

Browse files
committed
fix(zen-mode): hide related questions
1 parent bdb12be commit 98387b7

File tree

4 files changed

+47
-49
lines changed

4 files changed

+47
-49
lines changed

src/data/plugins/command-menu/items.ts

+3-23
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {
1919
NavigationItem,
2020
SearchItem,
2121
} from "@/data/plugins/command-menu/types";
22-
import { ExtensionLocalStorageService } from "@/services/extension-local-storage";
22+
import { toggleZenMode } from "@/data/plugins/zen-mode/utils";
2323

2424
export const ZENMODE_ITEMS: ZenModeItem[] = [
2525
{
@@ -31,17 +31,7 @@ export const ZENMODE_ITEMS: ZenModeItem[] = [
3131
t("plugin-command-menu:commandMenu.keywords.zen"),
3232
t("plugin-command-menu:commandMenu.keywords.mode"),
3333
],
34-
action: () => {
35-
$("body").attr("data-cplx-zen-mode", "true");
36-
if (
37-
ExtensionLocalStorageService.getCachedSync()?.plugins["zenMode"]
38-
.persistent
39-
) {
40-
ExtensionLocalStorageService.set((draft) => {
41-
draft.plugins["zenMode"].lastState = true;
42-
});
43-
}
44-
},
34+
action: () => toggleZenMode(true),
4535
},
4636
{
4737
type: "disable",
@@ -52,17 +42,7 @@ export const ZENMODE_ITEMS: ZenModeItem[] = [
5242
t("plugin-command-menu:commandMenu.keywords.zen"),
5343
t("plugin-command-menu:commandMenu.keywords.mode"),
5444
],
55-
action: () => {
56-
$("body").attr("data-cplx-zen-mode", "false");
57-
if (
58-
ExtensionLocalStorageService.getCachedSync()?.plugins["zenMode"]
59-
.persistent
60-
) {
61-
ExtensionLocalStorageService.set((draft) => {
62-
draft.plugins["zenMode"].lastState = false;
63-
});
64-
}
65-
},
45+
action: () => toggleZenMode(false),
6646
},
6747
];
6848

src/data/plugins/zen-mode/utils.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { ExtensionLocalStorageService } from "@/services/extension-local-storage";
2+
3+
export function toggleZenMode(forceState?: boolean): boolean {
4+
const previousZenMode = $("body").attr("data-cplx-zen-mode");
5+
const newZenMode =
6+
forceState !== undefined
7+
? forceState
8+
? "true"
9+
: "false"
10+
: previousZenMode === "true"
11+
? "false"
12+
: "true";
13+
14+
$("body").attr("data-cplx-zen-mode", newZenMode);
15+
16+
if (
17+
ExtensionLocalStorageService.getCachedSync()?.plugins["zenMode"].persistent
18+
) {
19+
ExtensionLocalStorageService.set((draft) => {
20+
draft.plugins["zenMode"].lastState = newZenMode === "true";
21+
});
22+
}
23+
24+
setTimeout(() => {
25+
window.dispatchEvent(new Event("resize"));
26+
}, 300);
27+
28+
return newZenMode === "true";
29+
}

src/plugins/command-menu/hooks/useBindCommandMenuHotkeys.ts

+2-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
commandMenuStore,
66
useCommandMenuStore,
77
} from "@/data/plugins/command-menu/store";
8+
import { toggleZenMode } from "@/data/plugins/zen-mode/utils";
89
import { ExtensionLocalStorageService } from "@/services/extension-local-storage";
910
import { PluginsStatesService } from "@/services/plugins-states";
1011
import { keysToString } from "@/utils/utils";
@@ -81,17 +82,7 @@ export default function useBindCommandMenuHotkeys() {
8182
useHotkeys(
8283
keysToString(settings.plugins.zenMode.hotkey),
8384
() => {
84-
const previousZenMode = $("body").attr("data-cplx-zen-mode");
85-
const newZenMode = previousZenMode === "true" ? "false" : "true";
86-
$("body").attr("data-cplx-zen-mode", newZenMode);
87-
if (
88-
ExtensionLocalStorageService.getCachedSync()?.plugins["zenMode"]
89-
.persistent
90-
) {
91-
ExtensionLocalStorageService.set((draft) => {
92-
draft.plugins["zenMode"].lastState = newZenMode === "true";
93-
});
94-
}
85+
toggleZenMode();
9586
setOpen(false);
9687
},
9788
{

src/plugins/zen-mode/zen-mode.css

+13-15
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,23 @@ body[data-cplx-zen-mode="true"] {
3838

3939
[data-cplx-component="message-block"] {
4040
/* Related follow-ups section */
41-
[data-cplx-component="message-block-query"]
42-
+ div
43-
+ div:has(> div.mt-lg.border-t.pt-lg.duration-1000) {
41+
.pb-32 > :last-child > .mt-xs.pt-lg {
4442
display: none;
4543
}
44+
}
4645

47-
&:not(
48-
:has(
49-
.isolate.col-span-4[data-cplx-component="message-block-visual-col"]
50-
svg[data-icon="sources"]
51-
)
52-
) {
53-
.isolate.col-span-8[data-cplx-component="message-block-text-col"] {
54-
grid-column: span 12 / span 12;
55-
}
46+
[data-cplx-component="message-block"]:not(
47+
:has(
48+
.isolate.col-span-4[data-cplx-component="message-block-visual-col"]
49+
svg[data-icon="sources"]
50+
)
51+
) {
52+
.isolate.col-span-8[data-cplx-component="message-block-text-col"] {
53+
grid-column: span 12 / span 12;
54+
}
5655

57-
.isolate.col-span-4[data-cplx-component="message-block-visual-col"] {
58-
display: none;
59-
}
56+
.isolate.col-span-4[data-cplx-component="message-block-visual-col"] {
57+
display: none;
6058
}
6159
}
6260
}

0 commit comments

Comments
 (0)