From cd2e7d5436f947cd87fc64ac2039a33fdc3f7abb Mon Sep 17 00:00:00 2001 From: Andrei Prigorshnev Date: Tue, 1 Feb 2022 13:10:09 +0100 Subject: [PATCH] FEATURE: show the this weekend option on the bookmark modal (#15755) --- .../app/components/edit-topic-timer-form.js | 14 +------------- .../app/components/time-shortcut-picker.js | 5 +++++ .../javascripts/discourse/app/lib/time-shortcut.js | 11 +++++++++++ .../javascripts/discourse/app/lib/time-utils.js | 1 + .../components/time-shortcut-picker-test.js | 1 + 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/edit-topic-timer-form.js b/app/assets/javascripts/discourse/app/components/edit-topic-timer-form.js index aa98c28bb8..f7a726d848 100644 --- a/app/assets/javascripts/discourse/app/components/edit-topic-timer-form.js +++ b/app/assets/javascripts/discourse/app/components/edit-topic-timer-form.js @@ -14,12 +14,7 @@ import I18n from "I18n"; import { action } from "@ember/object"; import Component from "@ember/component"; import { isEmpty } from "@ember/utils"; -import { - MOMENT_MONDAY, - now, - startOfDay, - thisWeekend, -} from "discourse/lib/time-utils"; +import { MOMENT_MONDAY, now, startOfDay } from "discourse/lib/time-utils"; import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts"; import { TIME_SHORTCUT_TYPES } from "discourse/lib/time-shortcut"; import ItsATrap from "@discourse/itsatrap"; @@ -88,13 +83,6 @@ export default Component.extend({ @discourseComputed() customTimeShortcutOptions() { return [ - { - icon: "bed", - id: "this_weekend", - label: "time_shortcut.this_weekend", - time: thisWeekend(), - timeFormatKey: "dates.time_short_day", - }, { icon: "far-clock", id: "two_weeks", diff --git a/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js b/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js index caee171d91..10219e71fc 100644 --- a/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js +++ b/app/assets/javascripts/discourse/app/components/time-shortcut-picker.js @@ -1,5 +1,6 @@ import { LATER_TODAY_CUTOFF_HOUR, + MOMENT_FRIDAY, MOMENT_THURSDAY, START_OF_DAY_HOUR, laterToday, @@ -283,6 +284,10 @@ export default Component.extend({ if (now(this.userTimezone).day() >= MOMENT_THURSDAY) { this._hideOption(options, TIME_SHORTCUT_TYPES.LATER_THIS_WEEK); } + + if (now(this.userTimezone).day() >= MOMENT_FRIDAY) { + this._hideOption(options, TIME_SHORTCUT_TYPES.THIS_WEEKEND); + } }, _hideOption(options, optionId) { diff --git a/app/assets/javascripts/discourse/app/lib/time-shortcut.js b/app/assets/javascripts/discourse/app/lib/time-shortcut.js index 5d6349afef..7ee30b041c 100644 --- a/app/assets/javascripts/discourse/app/lib/time-shortcut.js +++ b/app/assets/javascripts/discourse/app/lib/time-shortcut.js @@ -6,6 +6,7 @@ import { nextBusinessWeekStart, nextMonth, now, + thisWeekend, tomorrow, } from "discourse/lib/time-utils"; import I18n from "I18n"; @@ -13,6 +14,7 @@ import I18n from "I18n"; export const TIME_SHORTCUT_TYPES = { LATER_TODAY: "later_today", TOMORROW: "tomorrow", + THIS_WEEKEND: "this_weekend", NEXT_MONTH: "next_month", CUSTOM: "custom", RELATIVE: "relative", @@ -48,6 +50,15 @@ export function defaultShortcutOptions(timezone) { I18n.t("dates.time_short_day") ), }, + { + icon: "bed", + id: TIME_SHORTCUT_TYPES.THIS_WEEKEND, + label: "time_shortcut.this_weekend", + time: thisWeekend(timezone), + timeFormatted: thisWeekend(timezone).format( + I18n.t("dates.time_short_day") + ), + }, { icon: "briefcase", id: TIME_SHORTCUT_TYPES.START_OF_NEXT_BUSINESS_WEEK, diff --git a/app/assets/javascripts/discourse/app/lib/time-utils.js b/app/assets/javascripts/discourse/app/lib/time-utils.js index 114b151af4..5266362e5b 100644 --- a/app/assets/javascripts/discourse/app/lib/time-utils.js +++ b/app/assets/javascripts/discourse/app/lib/time-utils.js @@ -6,6 +6,7 @@ export const LATER_TODAY_MAX_HOUR = 18; export const MOMENT_SUNDAY = 0; export const MOMENT_MONDAY = 1; export const MOMENT_THURSDAY = 4; +export const MOMENT_FRIDAY = 5; export const MOMENT_SATURDAY = 6; export function now(timezone) { diff --git a/app/assets/javascripts/discourse/tests/integration/components/time-shortcut-picker-test.js b/app/assets/javascripts/discourse/tests/integration/components/time-shortcut-picker-test.js index 66c4101ad5..443e886669 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/time-shortcut-picker-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/time-shortcut-picker-test.js @@ -47,6 +47,7 @@ discourseModule( I18n.t("time_shortcut.later_today"), I18n.t("time_shortcut.tomorrow"), I18n.t("time_shortcut.later_this_week"), + I18n.t("time_shortcut.this_weekend"), I18n.t("time_shortcut.start_of_next_business_week"), I18n.t("time_shortcut.next_month"), I18n.t("time_shortcut.custom"),