Skip to content

Commit

Permalink
Merge branch 'experiments' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Nov 21, 2023
2 parents e3c77e9 + bada1cf commit c897036
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
18 changes: 9 additions & 9 deletions client/src/plus/ai-help/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
--plus-link: var(--ai-help-link);
}

.button.action.has-icon {
// Reduce button icon contrast to make it less prominent.
--button-color: var(--icon-secondary);

&:hover {
--button-color: var(--icon-primary);
}
}

> .ai-help-main {
--ai-top: calc(var(--top-nav-height) + 1px + 1rem);
column-gap: 1rem;
Expand Down Expand Up @@ -494,13 +503,4 @@
margin: 0.5rem 0;
}
}

.button.action.has-icon {
// Reduce button icon contrast to make it less prominent.
--button-color: var(--icon-secondary);

&:hover {
--button-color: var(--icon-primary);
}
}
}
2 changes: 1 addition & 1 deletion client/src/plus/ai-help/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,12 @@ export function AIHelpInner() {
<section className="ai-help-feedback">
<GleanThumbs
feature="ai-help-answer"
featureKey={message.messageId}
question={"Was this answer useful?"}
upLabel={"Yes, this answer was useful."}
downLabel={
"No, this answer was not useful."
}
permanent={true}
callback={async (value) => {
user?.experiments?.active &&
message.messageId &&
Expand Down
50 changes: 34 additions & 16 deletions client/src/ui/atoms/thumbs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,48 @@ function getPreviouslySubmitted() {
}
}

function isPreviouslySubmitted(feature: string): boolean {
function isPreviouslySubmitted(feature: string, key?: string): boolean {
try {
return feature in getPreviouslySubmitted();
const db = getPreviouslySubmitted();
if (key) {
return key in db[feature];
} else {
return feature in db;
}
} catch (e) {
return false;
}
}

function markPreviouslySubmitted(feature: string, value: boolean) {
function markPreviouslySubmitted(
feature: string,
value: boolean,
key?: string
) {
try {
window?.localStorage?.setItem(
LOCAL_STORAGE_KEY,
JSON.stringify({
...getPreviouslySubmitted(),
[feature]: {
submitted_at: Date.now(),
value,
},
})
);
const db = getPreviouslySubmitted();

const state = {
submitted_at: Date.now(),
value,
};

db[feature] = key
? {
...db[feature],
[key]: state,
}
: state;

window?.localStorage?.setItem(LOCAL_STORAGE_KEY, JSON.stringify(db));
} catch (e) {
console.warn("Unable to write thumbs state to localStorage", e);
}
}

export function GleanThumbs({
feature,
featureKey = undefined,
question = "Is this feature useful?",
confirmation = "Thank you for your feedback! ❤️",
upLabel = "This feature is useful.",
Expand All @@ -51,6 +66,7 @@ export function GleanThumbs({
callback,
}: {
feature: string;
featureKey?: string;
question?: string;
confirmation?: string;
upLabel?: string;
Expand All @@ -63,15 +79,17 @@ export function GleanThumbs({
const gleanClick = useGleanClick();

useEffect(() => {
setPreviouslySubmitted(!permanent && isPreviouslySubmitted(feature));
}, [feature, permanent, setPreviouslySubmitted]);
setPreviouslySubmitted(
!permanent && isPreviouslySubmitted(feature, featureKey)
);
}, [feature, featureKey, permanent, setPreviouslySubmitted]);

const handleThumbs = async (value: "up" | "down") => {
gleanClick(`${THUMBS}: ${feature} -> ${value === "up" ? 1 : 0}`);
await callback?.(value);
setSubmitted(true);
if (!permanent) {
markPreviouslySubmitted(feature, value === "up");
markPreviouslySubmitted(feature, value === "up", featureKey);
}
};

Expand Down

0 comments on commit c897036

Please sign in to comment.