DEV: converts do-not-disturb to gjs (#29840)

This commit is contained in:
Joffrey JAFFEUX 2024-11-20 10:50:15 +01:00 committed by GitHub
parent 704a5f4cab
commit 67ce111861
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 84 additions and 76 deletions

View File

@ -0,0 +1,84 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
import DModal from "discourse/components/d-modal";
import TapTile from "discourse/components/tap-tile";
import TapTileGrid from "discourse/components/tap-tile-grid";
import { extractError } from "discourse/lib/ajax-error";
import { i18n } from "discourse-i18n";
export default class DoNotDisturb extends Component {
@service currentUser;
@service router;
@tracked flash;
@action
async saveDuration(duration) {
try {
await this.currentUser.enterDoNotDisturbFor(duration);
this.args.closeModal();
} catch (e) {
this.flash = extractError(e);
}
}
@action
navigateToNotificationSchedule() {
this.router.transitionTo("preferences.notifications", this.currentUser);
this.args.closeModal();
}
<template>
<DModal
@title={{i18n "pause_notifications.title"}}
@closeModal={{@closeModal}}
@flash={{this.flash}}
class="do-not-disturb-modal"
>
<:body>
<TapTileGrid as |grid|>
<TapTile
@tileId="30"
@activeTile={{grid.activeTile}}
@onChange={{this.saveDuration}}
class="do-not-disturb-tile"
>
{{i18n "pause_notifications.options.half_hour"}}
</TapTile>
<TapTile
@tileId="60"
@activeTile={{grid.activeTile}}
@onChange={{this.saveDuration}}
class="do-not-disturb-tile"
>
{{i18n "pause_notifications.options.one_hour"}}
</TapTile>
<TapTile
@tileId="120"
@activeTile={{grid.activeTile}}
@onChange={{this.saveDuration}}
class="do-not-disturb-tile"
>
{{i18n "pause_notifications.options.two_hours"}}
</TapTile>
<TapTile
@tileId="tomorrow"
@activeTile={{grid.activeTile}}
@onChange={{this.saveDuration}}
class="do-not-disturb-tile"
>
{{i18n "pause_notifications.options.tomorrow"}}
</TapTile>
</TapTileGrid>
<DButton
@action={{this.navigateToNotificationSchedule}}
@label="pause_notifications.set_schedule"
/>
</:body>
</DModal>
</template>
}

View File

@ -1,48 +0,0 @@
<DModal
@title={{i18n "pause_notifications.title"}}
@closeModal={{@closeModal}}
@flash={{this.flash}}
class="do-not-disturb-modal"
>
<:body>
<TapTileGrid as |grid|>
<TapTile
@tileId="30"
@activeTile={{grid.activeTile}}
@onChange={{this.saveDuration}}
class="do-not-disturb-tile"
>
{{i18n "pause_notifications.options.half_hour"}}
</TapTile>
<TapTile
@tileId="60"
@activeTile={{grid.activeTile}}
@onChange={{this.saveDuration}}
class="do-not-disturb-tile"
>
{{i18n "pause_notifications.options.one_hour"}}
</TapTile>
<TapTile
@tileId="120"
@activeTile={{grid.activeTile}}
@onChange={{this.saveDuration}}
class="do-not-disturb-tile"
>
{{i18n "pause_notifications.options.two_hours"}}
</TapTile>
<TapTile
@tileId="tomorrow"
@activeTile={{grid.activeTile}}
@onChange={{this.saveDuration}}
class="do-not-disturb-tile"
>
{{i18n "pause_notifications.options.tomorrow"}}
</TapTile>
</TapTileGrid>
<DButton
@action={{this.navigateToNotificationSchedule}}
@label="pause_notifications.set_schedule"
/>
</:body>
</DModal>

View File

@ -1,28 +0,0 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import { service } from "@ember/service";
import { extractError } from "discourse/lib/ajax-error";
export default class DoNotDisturb extends Component {
@service currentUser;
@service router;
@tracked flash;
@action
async saveDuration(duration) {
try {
await this.currentUser.enterDoNotDisturbFor(duration);
this.args.closeModal();
} catch (e) {
this.flash = extractError(e);
}
}
@action
navigateToNotificationSchedule() {
this.router.transitionTo("preferences.notifications", this.currentUser);
this.args.closeModal();
}
}