feat(call_to_action): allow dismissal

This commit is contained in:
Elian Doran 2025-08-12 19:37:32 +03:00
parent b2db87db4e
commit bac048f60f
No known key found for this signature in database
5 changed files with 32 additions and 6 deletions

View File

@ -2,7 +2,7 @@ import { useState } from "preact/hooks";
import Button from "../react/Button"; import Button from "../react/Button";
import Modal from "../react/Modal"; import Modal from "../react/Modal";
import ReactBasicWidget from "../react/ReactBasicWidget"; import ReactBasicWidget from "../react/ReactBasicWidget";
import { CallToAction, getCallToActions } from "./call_to_action_definitions"; import { CallToAction, dismissCallToAction, getCallToActions } from "./call_to_action_definitions";
function CallToActionDialogComponent({ activeCallToActions }: { activeCallToActions: CallToAction[] }) { function CallToActionDialogComponent({ activeCallToActions }: { activeCallToActions: CallToAction[] }) {
const [ activeIndex, setActiveIndex ] = useState(0); const [ activeIndex, setActiveIndex ] = useState(0);
@ -30,9 +30,13 @@ function CallToActionDialogComponent({ activeCallToActions }: { activeCallToActi
onHidden={() => setShown(false)} onHidden={() => setShown(false)}
footerAlignment="between" footerAlignment="between"
footer={<> footer={<>
<Button text="Dismiss" onClick={goToNext} /> <Button text="Dismiss" onClick={async () => {
await dismissCallToAction(activeItem.id);
goToNext();
}} />
{activeItem.buttons.map((button) => {activeItem.buttons.map((button) =>
<Button text={button.text} onClick={async () => { <Button text={button.text} onClick={async () => {
await dismissCallToAction(activeItem.id);
await button.onClick(); await button.onClick();
goToNext(); goToNext();
}}/> }}/>

View File

@ -52,5 +52,26 @@ const CALL_TO_ACTIONS: CallToAction[] = [
]; ];
export function getCallToActions() { export function getCallToActions() {
return CALL_TO_ACTIONS.filter((callToAction) => callToAction.enabled()); const seenCallToActions = new Set(getSeenCallToActions());
return CALL_TO_ACTIONS.filter((callToAction) =>
!seenCallToActions.has(callToAction.id) && callToAction.enabled());
}
export async function dismissCallToAction(id: string) {
const seenCallToActions = getSeenCallToActions();
if (seenCallToActions.find(seenId => seenId === id)) {
return;
}
seenCallToActions.push(id);
await options.save("seenCallToActions", JSON.stringify(seenCallToActions));
}
function getSeenCallToActions() {
try {
return JSON.parse(options.get("seenCallToActions")) as string[];
} catch (e) {
return [];
}
} }

View File

@ -93,6 +93,7 @@ const ALLOWED_OPTIONS = new Set<OptionNames>([
"redirectBareDomain", "redirectBareDomain",
"showLoginInShareTheme", "showLoginInShareTheme",
"splitEditorOrientation", "splitEditorOrientation",
"seenCallToActions",
// AI/LLM integration options // AI/LLM integration options
"aiEnabled", "aiEnabled",

View File

@ -206,11 +206,11 @@ const defaultOptions: DefaultOption[] = [
{ name: "ollamaEnabled", value: "false", isSynced: true }, { name: "ollamaEnabled", value: "false", isSynced: true },
{ name: "ollamaDefaultModel", value: "", isSynced: true }, { name: "ollamaDefaultModel", value: "", isSynced: true },
{ name: "ollamaBaseUrl", value: "http://localhost:11434", isSynced: true }, { name: "ollamaBaseUrl", value: "http://localhost:11434", isSynced: true },
// Adding missing AI options
{ name: "aiTemperature", value: "0.7", isSynced: true }, { name: "aiTemperature", value: "0.7", isSynced: true },
{ name: "aiSystemPrompt", value: "", isSynced: true }, { name: "aiSystemPrompt", value: "", isSynced: true },
{ name: "aiSelectedProvider", value: "openai", isSynced: true }, { name: "aiSelectedProvider", value: "openai", isSynced: true },
{ name: "seenCallToActions", value: "[]", isSynced: true }
]; ];
/** /**

View File

@ -145,7 +145,7 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi
ollamaDefaultModel: string; ollamaDefaultModel: string;
codeOpenAiModel: string; codeOpenAiModel: string;
aiSelectedProvider: string; aiSelectedProvider: string;
seenCallToActions: string;
} }
export type OptionNames = keyof OptionDefinitions; export type OptionNames = keyof OptionDefinitions;