Skip to content

Commit

Permalink
feat: explicitly track Pro Search state
Browse files Browse the repository at this point in the history
  • Loading branch information
pnd280 committed Sep 22, 2024
1 parent ba9b4fa commit 472530f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Consider giving a star ⭐ on [Github](https://github.com/pnd280/complexity).

_Release date: 21th Sep, 2024_

- **NEW** | **EXPERIMENTAL**: Explicitly keep track of the Pro Search state (Prevent auto-toggling off).

- **FIX**: Fixed infinte initializing loop.
- **FIX**: Fixed the Rewrite dropdown (Thread Message Sticky Toolbar) - html structure changed.

Expand Down
2 changes: 2 additions & 0 deletions src/content-script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ function initUiUxTweaks() {
UiTweaks.applySettingsAsHTMLAttrs(location);

UxTweaks.dropFileWithinThread(location);

UxTweaks.trackProSearchState();
};

observe(window.location.href);
Expand Down
2 changes: 2 additions & 0 deletions src/cplx-user-settings/CplxUserSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class CplxUserSettings {
isFirstVisit: true,
customTheme: {},
defaultFocusMode: "internet",
defaultProSearchState: false,
generalSettings: {
queryBoxSelectors: {
focus: false,
Expand All @@ -34,6 +35,7 @@ export default class CplxUserSettings {
noFileCreationOnPaste: false,
fileDropableThreadWrapper: false,
autoGenerateThreadTitle: false,
trackProSearchState: false,
},
visualTweaks: {
collapseEmptyThreadVisualColumns: false,
Expand Down
9 changes: 9 additions & 0 deletions src/cplx-user-settings/GeneralSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ export default class GeneralSettings {
description: "Treat the whole page as a dropzone for file uploads.",
versionRelease: "0.0.1.0",
},
{
id: "track-pro-search-state",
label: "Track pro search state",
settingKey: "trackProSearchState",
description:
"Explicitly keep track of the Pro Search state (Prevent auto-toggling off).",
versionRelease: "0.0.4.0",
experimental: true,
},
];

static visualTweaks: PopupSetting<
Expand Down
2 changes: 2 additions & 0 deletions src/cplx-user-settings/types/cplx-user-settings.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const cplxUserSettingsSchema = z.object({
schemaVersion: z.literal(packageData.version),
isFirstVisit: z.boolean(),
defaultFocusMode: WebAccessFocusSchema.nullable(),
defaultProSearchState: z.boolean(),
generalSettings: z.object({
queryBoxSelectors: z.object({
focus: z.boolean(),
Expand All @@ -39,6 +40,7 @@ export const cplxUserSettingsSchema = z.object({
noFileCreationOnPaste: z.boolean(),
fileDropableThreadWrapper: z.boolean(),
autoGenerateThreadTitle: z.boolean(),
trackProSearchState: z.boolean(),
}),
visualTweaks: z.object({
collapseEmptyThreadVisualColumns: z.boolean(),
Expand Down
39 changes: 39 additions & 0 deletions src/utils/UxTweaks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { throttle } from "lodash-es";

import CplxUserSettings from "@/cplx-user-settings/CplxUserSettings";
import DomObserver from "@/utils/DomObserver/DomObserver";
import { DomSelectors } from "@/utils/DomSelectors";
import UiUtils from "@/utils/UiUtils";
import { whereAmI } from "@/utils/utils";

Expand Down Expand Up @@ -82,4 +84,41 @@ export default class UxTweaks {
$(window).on("resize", handler);
});
}

static trackProSearchState() {
if (!CplxUserSettings.get().generalSettings.qolTweaks.trackProSearchState)
return;

const defaultProSearchState = CplxUserSettings.get().defaultProSearchState
? "checked"
: "unchecked";

const currentState = $(DomSelectors.QUERY_BOX.PRO_SEARCH_TOGGLE).attr(
"data-state",
);

if (currentState !== defaultProSearchState) {
console.log("Overriding pro search state");
$(DomSelectors.QUERY_BOX.PRO_SEARCH_TOGGLE).trigger("click");
}

DomObserver.destroy("pro-search-state-tracker");

DomObserver.create("pro-search-state-tracker", {
target: $(DomSelectors.QUERY_BOX.PRO_SEARCH_TOGGLE)[0],
config: {
attributes: true,
attributeFilter: ["data-state"],
},
onAttrChange: (element) => {
const state = element.getAttribute("data-state");

if (state == null) return;

CplxUserSettings.set(
(draft) => (draft.defaultProSearchState = state === "checked"),
);
},
});
}
}

0 comments on commit 472530f

Please sign in to comment.