2024-10-29 11:59:41 -04:00
|
|
|
import Component from "@glimmer/component";
|
|
|
|
import { concat, fn } from "@ember/helper";
|
|
|
|
import { action } from "@ember/object";
|
|
|
|
import { service } from "@ember/service";
|
|
|
|
import DButton from "discourse/components/d-button";
|
|
|
|
import DropdownMenu from "discourse/components/dropdown-menu";
|
2024-11-19 15:33:34 -05:00
|
|
|
import bodyClass from "discourse/helpers/body-class";
|
2024-10-29 11:59:41 -04:00
|
|
|
import icon from "discourse-common/helpers/d-icon";
|
|
|
|
import i18n from "discourse-common/helpers/i18n";
|
|
|
|
import DMenu from "float-kit/components/d-menu";
|
2024-11-19 15:33:34 -05:00
|
|
|
import eq from "truth-helpers/helpers/eq";
|
2024-10-29 11:59:41 -04:00
|
|
|
|
|
|
|
export default class AiGistToggle extends Component {
|
2024-11-19 15:33:34 -05:00
|
|
|
@service gists;
|
2024-10-29 11:59:41 -04:00
|
|
|
|
|
|
|
get buttons() {
|
|
|
|
return [
|
|
|
|
{
|
2024-11-19 15:33:34 -05:00
|
|
|
id: "table",
|
|
|
|
label: "discourse_ai.summarization.topic_list_layout.button.compact",
|
|
|
|
icon: "discourse-table",
|
2024-10-29 11:59:41 -04:00
|
|
|
},
|
|
|
|
{
|
2024-11-19 15:33:34 -05:00
|
|
|
id: "table-ai",
|
|
|
|
label: "discourse_ai.summarization.topic_list_layout.button.expanded",
|
|
|
|
icon: "discourse-table-sparkles",
|
|
|
|
description:
|
|
|
|
"discourse_ai.summarization.topic_list_layout.button.expanded_description",
|
2024-10-29 11:59:41 -04:00
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2024-11-19 15:33:34 -05:00
|
|
|
get selectedOptionId() {
|
|
|
|
return this.gists.get("preference");
|
|
|
|
}
|
|
|
|
|
|
|
|
get currentButton() {
|
|
|
|
const buttonPreference = this.buttons.find(
|
|
|
|
(button) => button.id === this.selectedOptionId
|
|
|
|
);
|
|
|
|
return buttonPreference || this.buttons[0];
|
|
|
|
}
|
|
|
|
|
2024-10-29 11:59:41 -04:00
|
|
|
@action
|
|
|
|
onRegisterApi(api) {
|
|
|
|
this.dMenu = api;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
onSelect(optionId) {
|
2024-11-19 15:33:34 -05:00
|
|
|
this.gists.setPreference(optionId);
|
2024-10-29 11:59:41 -04:00
|
|
|
this.dMenu.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
<template>
|
2024-11-19 15:33:34 -05:00
|
|
|
{{#if this.gists.shouldShow}}
|
|
|
|
{{bodyClass (concat "topic-list-layout-" this.gists.preference)}}
|
2024-10-29 11:59:41 -04:00
|
|
|
<DMenu
|
|
|
|
@modalForMobile={{true}}
|
|
|
|
@autofocus={{true}}
|
2024-11-19 15:33:34 -05:00
|
|
|
@identifier="topic-list-layout"
|
2024-10-29 11:59:41 -04:00
|
|
|
@onRegisterApi={{this.onRegisterApi}}
|
2024-11-19 15:33:34 -05:00
|
|
|
@triggerClass="btn-default btn-icon"
|
2024-10-29 11:59:41 -04:00
|
|
|
>
|
|
|
|
<:trigger>
|
2024-11-19 15:33:34 -05:00
|
|
|
{{icon this.currentButton.icon}}
|
2024-10-29 11:59:41 -04:00
|
|
|
</:trigger>
|
|
|
|
<:content>
|
|
|
|
<DropdownMenu as |dropdown|>
|
|
|
|
{{#each this.buttons as |button|}}
|
|
|
|
<dropdown.item>
|
|
|
|
<DButton
|
|
|
|
@label={{button.label}}
|
|
|
|
@icon={{button.icon}}
|
2024-11-19 15:33:34 -05:00
|
|
|
class="btn-transparent
|
|
|
|
{{if button.description '--with-description'}}
|
|
|
|
{{if (eq this.currentButton.id button.id) '--active'}}"
|
2024-10-29 11:59:41 -04:00
|
|
|
@action={{fn this.onSelect button.id}}
|
2024-11-19 15:33:34 -05:00
|
|
|
>
|
|
|
|
{{#if button.description}}
|
|
|
|
<div class="btn__description">
|
|
|
|
{{i18n button.description}}
|
|
|
|
</div>
|
|
|
|
{{/if}}
|
|
|
|
</DButton>
|
2024-10-29 11:59:41 -04:00
|
|
|
</dropdown.item>
|
|
|
|
{{/each}}
|
|
|
|
</DropdownMenu>
|
|
|
|
</:content>
|
|
|
|
</DMenu>
|
|
|
|
{{/if}}
|
|
|
|
</template>
|
|
|
|
}
|