Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit a9afa04

Browse files
authored
UX: update gist toggle styles (#926)
1 parent 530a795 commit a9afa04

File tree

12 files changed

+186
-164
lines changed

12 files changed

+186
-164
lines changed

assets/javascripts/discourse/components/ai-gist-toggle.gjs

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,66 @@ import { action } from "@ember/object";
44
import { service } from "@ember/service";
55
import DButton from "discourse/components/d-button";
66
import DropdownMenu from "discourse/components/dropdown-menu";
7+
import bodyClass from "discourse/helpers/body-class";
78
import icon from "discourse-common/helpers/d-icon";
89
import i18n from "discourse-common/helpers/i18n";
910
import DMenu from "float-kit/components/d-menu";
11+
import eq from "truth-helpers/helpers/eq";
1012

1113
export default class AiGistToggle extends Component {
12-
@service router;
13-
@service gistPreference;
14-
15-
get shouldShow() {
16-
return this.router.currentRoute.attributes?.list?.topics?.some(
17-
(topic) => topic.ai_topic_gist
18-
);
19-
}
14+
@service gists;
2015

2116
get buttons() {
2217
return [
2318
{
24-
id: "gists_enabled",
25-
label: "discourse_ai.summarization.gists_enabled_long",
26-
icon: "discourse-sparkles",
19+
id: "table",
20+
label: "discourse_ai.summarization.topic_list_layout.button.compact",
21+
icon: "discourse-table",
2722
},
2823
{
29-
id: "gists_disabled",
30-
label: "discourse_ai.summarization.gists_disabled",
31-
icon: "far-eye-slash",
24+
id: "table-ai",
25+
label: "discourse_ai.summarization.topic_list_layout.button.expanded",
26+
icon: "discourse-table-sparkles",
27+
description:
28+
"discourse_ai.summarization.topic_list_layout.button.expanded_description",
3229
},
3330
];
3431
}
3532

33+
get selectedOptionId() {
34+
return this.gists.get("preference");
35+
}
36+
37+
get currentButton() {
38+
const buttonPreference = this.buttons.find(
39+
(button) => button.id === this.selectedOptionId
40+
);
41+
return buttonPreference || this.buttons[0];
42+
}
43+
3644
@action
3745
onRegisterApi(api) {
3846
this.dMenu = api;
3947
}
4048

4149
@action
4250
onSelect(optionId) {
43-
this.gistPreference.setPreference(optionId);
51+
this.gists.setPreference(optionId);
4452
this.dMenu.close();
4553
}
4654

4755
<template>
48-
{{#if this.shouldShow}}
49-
56+
{{#if this.gists.shouldShow}}
57+
{{bodyClass (concat "topic-list-layout-" this.gists.preference)}}
5058
<DMenu
5159
@modalForMobile={{true}}
5260
@autofocus={{true}}
53-
@identifier="ai-gists-dropdown"
61+
@identifier="topic-list-layout"
5462
@onRegisterApi={{this.onRegisterApi}}
55-
@triggerClass="btn-transparent"
63+
@triggerClass="btn-default btn-icon"
5664
>
5765
<:trigger>
58-
<span class="d-button-label">
59-
{{i18n
60-
(concat
61-
"discourse_ai.summarization." this.gistPreference.preference
62-
)
63-
}}
64-
</span>
65-
{{icon "angle-down"}}
66+
{{icon this.currentButton.icon}}
6667
</:trigger>
6768
<:content>
6869
<DropdownMenu as |dropdown|>
@@ -71,9 +72,17 @@ export default class AiGistToggle extends Component {
7172
<DButton
7273
@label={{button.label}}
7374
@icon={{button.icon}}
74-
class="btn-transparent"
75+
class="btn-transparent
76+
{{if button.description '--with-description'}}
77+
{{if (eq this.currentButton.id button.id) '--active'}}"
7578
@action={{fn this.onSelect button.id}}
76-
/>
79+
>
80+
{{#if button.description}}
81+
<div class="btn__description">
82+
{{i18n button.description}}
83+
</div>
84+
{{/if}}
85+
</DButton>
7786
</dropdown.item>
7887
{{/each}}
7988
</DropdownMenu>
Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
import Component from "@glimmer/component";
22
import { service } from "@ember/service";
3-
import bodyClass from "discourse/helpers/body-class";
3+
import { htmlSafe } from "@ember/template";
4+
import { emojiUnescape, sanitize } from "discourse/lib/text";
45

56
export default class AiTopicGist extends Component {
6-
@service router;
7-
@service gistPreference;
7+
@service gists;
88

9-
get prefersGist() {
10-
return this.gistPreference.preference === "gists_enabled";
9+
get shouldShow() {
10+
return this.gists.preference === "table-ai" && this.gists.shouldShow;
1111
}
1212

13-
get showGist() {
14-
return (
15-
this.args.topic?.ai_topic_gist &&
16-
this.prefersGist &&
17-
!this.args.topic?.excerpt
18-
);
13+
get gistOrExcerpt() {
14+
const topic = this.args.topic;
15+
const gist = topic.get("ai_topic_gist");
16+
const excerpt = emojiUnescape(sanitize(topic.get("excerpt")));
17+
18+
return gist || excerpt;
1919
}
2020

2121
<template>
22-
{{#if this.showGist}}
23-
{{bodyClass "--topic-list-with-gist"}}
24-
<div class="ai-topic-gist">
25-
<div class="ai-topic-gist__text">
26-
{{@topic.ai_topic_gist}}
22+
{{#if this.shouldShow}}
23+
{{#if this.gistOrExcerpt}}
24+
<div class="excerpt">
25+
<div>{{htmlSafe this.gistOrExcerpt}}</div>
2726
</div>
28-
</div>
27+
{{/if}}
2928
{{/if}}
3029
</template>
3130
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Component from "@glimmer/component";
2+
import { service } from "@ember/service";
3+
import AiGistToggle from "../../components/ai-gist-toggle";
4+
5+
export default class AiTopicGist extends Component {
6+
@service topicThumbnails; // avoid Topic Thumbnails theme component
7+
8+
get shouldShow() {
9+
return !this.topicThumbnails?.enabledForRoute;
10+
}
11+
12+
<template>
13+
<AiGistToggle />
14+
</template>
15+
}

assets/javascripts/discourse/connectors/discovery-above/mobile-gist-toggle.gjs

Lines changed: 0 additions & 13 deletions
This file was deleted.

assets/javascripts/discourse/connectors/topic-list-heading-bottom/desktop-gist-toggle.gjs

Lines changed: 0 additions & 16 deletions
This file was deleted.

assets/javascripts/discourse/services/gist-preference.js

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { tracked } from "@glimmer/tracking";
2+
import Service, { service } from "@ember/service";
3+
4+
export default class Gists extends Service {
5+
@service router;
6+
7+
@tracked preference = localStorage.getItem("topicListLayout");
8+
9+
get shouldShow() {
10+
const currentRoute = this.router.currentRoute.name;
11+
const isDiscovery = currentRoute.includes("discovery");
12+
const isNotCategories = !currentRoute.includes("categories");
13+
const gistsAvailable =
14+
this.router.currentRoute.attributes?.list?.topics?.some(
15+
(topic) => topic.ai_topic_gist
16+
);
17+
18+
return isDiscovery && isNotCategories && gistsAvailable;
19+
}
20+
21+
setPreference(value) {
22+
this.preference = value;
23+
localStorage.setItem("topicListLayout", value);
24+
25+
if (this.preference === "table-ai") {
26+
localStorage.setItem("aiPreferred", true);
27+
}
28+
}
29+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
.topic-list-layout-content {
2+
.btn.--with-description {
3+
display: grid;
4+
grid-template-areas: "icon title" "icon description";
5+
grid-template-columns: auto 1fr;
6+
text-align: left;
7+
.btn__description {
8+
grid-area: description;
9+
width: 100%;
10+
font-size: var(--font-down-1);
11+
color: var(--primary-high);
12+
}
13+
}
14+
15+
.btn:focus {
16+
background: transparent;
17+
}
18+
19+
.btn:focus-visible {
20+
outline: 2px solid var(--tertiary);
21+
background: transparent;
22+
outline-offset: -2px;
23+
}
24+
25+
.btn.--active {
26+
background: var(--d-selected);
27+
}
28+
}
29+
30+
.topic-list-layout-table-ai {
31+
.topic-list-item {
32+
.link-bottom-line {
33+
font-size: var(--font-down-1);
34+
margin-top: 0.25em;
35+
line-height: var(--line-height-medium);
36+
}
37+
.excerpt {
38+
width: 100%;
39+
line-height: var(--line-height-large);
40+
margin-top: 0.15em;
41+
margin-bottom: 0.15em;
42+
max-width: 70ch;
43+
}
44+
&:not(.visited) {
45+
.excerpt {
46+
color: var(--primary-high);
47+
}
48+
}
49+
}
50+
.topic-excerpt {
51+
display: none;
52+
}
53+
54+
.mobile-view & {
55+
.topic-list-item .excerpt {
56+
margin-top: -0.25em;
57+
margin-bottom: 0.25em;
58+
}
59+
60+
.topic-item-stats .num.activity {
61+
align-self: end;
62+
margin-bottom: -0.15em; // vertical alignment
63+
}
64+
}
65+
}

assets/stylesheets/modules/summarization/common/ai-summary.scss

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -215,77 +215,3 @@
215215
opacity: 1;
216216
}
217217
}
218-
219-
.ai-topic-gist {
220-
width: 100%;
221-
.mobile-view & {
222-
position: relative;
223-
top: -0.33em;
224-
line-height: 1.4;
225-
width: 90%;
226-
}
227-
228-
&__text {
229-
color: var(--primary-high);
230-
text-wrap: pretty;
231-
word-wrap: break-word;
232-
font-size: var(--font-down-1);
233-
max-width: 65ch;
234-
.visited & {
235-
color: var(--primary-medium);
236-
}
237-
}
238-
}
239-
240-
.--topic-list-with-gist {
241-
.topic-list-item {
242-
.main-link {
243-
line-height: var(--line-height-medium);
244-
}
245-
.link-bottom-line {
246-
font-size: var(--font-down-1);
247-
margin-top: 0.25em;
248-
}
249-
.ai-topic-gist {
250-
font-size: var(--font-up-1);
251-
line-height: var(--line-height-large);
252-
margin-top: 0.25em;
253-
margin-bottom: 0.15em;
254-
}
255-
.topic-post-badges {
256-
font-size: var(--font-down-1);
257-
}
258-
}
259-
260-
.mobile-view & {
261-
.topic-list {
262-
.topic-list-item > .topic-list-data {
263-
padding: 1em 0;
264-
}
265-
.topic-item-stats .num.activity {
266-
align-self: end;
267-
margin-bottom: -0.15em; // vertical alignment
268-
}
269-
.pull-left {
270-
padding-top: 0.25em;
271-
}
272-
.right {
273-
margin-left: 3.75em;
274-
}
275-
}
276-
}
277-
}
278-
279-
.ai-gists-dropdown-trigger {
280-
font-size: var(--font-down-1);
281-
color: var(--primary-medium);
282-
padding-left: 0.25em;
283-
.mobile-view & {
284-
padding-left: 0;
285-
color: var(--primary-high);
286-
}
287-
.d-icon {
288-
color: var(--primary-low-mid);
289-
margin-left: 0.15em;
290-
}
291-
}

0 commit comments

Comments
 (0)