From 5b01d3e60e6fb5c30aba1129d9001323ef2ff1e2 Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Mon, 21 Oct 2024 01:52:29 +0545 Subject: [PATCH] feat: add option to hide seconds on calendar (#343) --- modules/menus/calendar/time/index.ts | 61 +++++++++++---------- options.ts | 1 + widget/settings/pages/config/menus/clock.ts | 1 + 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/modules/menus/calendar/time/index.ts b/modules/menus/calendar/time/index.ts index 0812a61..2cbb279 100644 --- a/modules/menus/calendar/time/index.ts +++ b/modules/menus/calendar/time/index.ts @@ -1,7 +1,7 @@ import { BoxWidget } from 'lib/types/widget'; import options from 'options'; -const { military } = options.menus.clock.time; +const { military, hideSeconds } = options.menus.clock.time; const time = Variable('', { poll: [1000, 'date "+%I:%M:%S"'], @@ -26,43 +26,48 @@ const TimeWidget = (): BoxWidget => { vpack: 'center', hpack: 'center', class_name: 'clock-content-items', - children: military.bind('value').as((is24hr) => { - if (!is24hr) { + children: Utils.merge( + [military.bind('value'), hideSeconds.bind('value')], + (is24hr: boolean, hideSeconds: boolean) => { + if (!is24hr) { + return [ + Widget.Box({ + hpack: 'center', + children: [ + Widget.Label({ + class_name: 'clock-content-time', + label: hideSeconds ? time.bind().as((str) => str.slice(0, -3)) : time.bind(), + }), + ], + }), + Widget.Box({ + hpack: 'center', + children: [ + Widget.Label({ + vpack: 'end', + class_name: 'clock-content-period', + label: period.bind(), + }), + ], + }), + ]; + } + return [ Widget.Box({ hpack: 'center', children: [ Widget.Label({ class_name: 'clock-content-time', - label: time.bind(), - }), - ], - }), - Widget.Box({ - hpack: 'center', - children: [ - Widget.Label({ - vpack: 'end', - class_name: 'clock-content-period', - label: period.bind(), + label: hideSeconds + ? militaryTime.bind().as((str) => str.slice(0, -3)) + : militaryTime.bind(), }), ], }), ]; - } - - return [ - Widget.Box({ - hpack: 'center', - children: [ - Widget.Label({ - class_name: 'clock-content-time', - label: militaryTime.bind(), - }), - ], - }), - ]; - }), + }, + ), }), }); }; diff --git a/options.ts b/options.ts index 805a180..98b202a 100644 --- a/options.ts +++ b/options.ts @@ -1137,6 +1137,7 @@ const options = mkOptions(OPTIONS, { clock: { time: { military: opt(false), + hideSeconds: opt(false), }, weather: { enabled: opt(true), diff --git a/widget/settings/pages/config/menus/clock.ts b/widget/settings/pages/config/menus/clock.ts index 7f71120..71d8e18 100644 --- a/widget/settings/pages/config/menus/clock.ts +++ b/widget/settings/pages/config/menus/clock.ts @@ -14,6 +14,7 @@ export const ClockMenuSettings = (): Scrollable => { children: [ Header('Time'), Option({ opt: options.menus.clock.time.military, title: 'Use 24hr time', type: 'boolean' }), + Option({ opt: options.menus.clock.time.hideSeconds, title: 'Hide seconds', type: 'boolean' }), Header('Weather'), Option({ opt: options.menus.clock.weather.enabled, title: 'Enabled', type: 'boolean' }),