Skip to content

Commit

Permalink
option to use only all-day events (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
idaho authored Oct 7, 2024
1 parent 425bce4 commit 2cc3283
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/cards/trash-card/formSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ const getSchema = (customLocalize: LocalizeFunc, currentValues: TrashCardConfig,
selector: {
text: {}
}
},
{
name: 'only_all_day_events',
label: customLocalize(`editor.form.only_all_day_events.title`),
helper: customLocalize(`editor.form.only_all_day_events.helper`),
selector: {
boolean: {}
}
}
];

Expand Down
3 changes: 2 additions & 1 deletion src/cards/trash-card/trash-card-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface TrashCardConfig {
view_layout?: any;
layout: any;
type: string;
only_all_day_events?: boolean;
}

type CardStyleConfig = Pick<TrashCardConfig, 'hide_time_range' | 'day_style' | 'day_style_format' | 'layout' | 'color_mode' | 'icon_size' | 'with_label'>;
Expand Down Expand Up @@ -95,7 +96,7 @@ const entityCardConfigStruct = assign(
debug: optional(boolean()),
icon_size: optional(integer()),
with_label: optional(boolean()),

only_all_day_events: optional(boolean()),
pattern: optional(array(
object({
color: optional(string()),
Expand Down
4 changes: 4 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"location": {
"title": "Location",
"helper": "Filter events by given location, if none is given all are used."
},
"only_all_day_events": {
"title": "Only all-day events",
"helper": "If you only want to use all-day entries, please activate this option, otherwise all entries will be used."
}
},
"card": {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/findActiveEvents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ describe(`findActiveEvents`, () => {
const result = findActiveEvents(data as CalendarEvent[], {
config: {
filter_events: false,
pattern: []
pattern: [],
only_all_day_events: false
},
dropAfter: false,
now: new Date('2024-03-29T12:09:08.879Z'),
Expand Down
7 changes: 7 additions & 0 deletions src/utils/findActiveEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface Config {
pattern: Required<TrashCardConfig>['pattern'];
// eslint-disable-next-line @typescript-eslint/naming-convention
filter_events: TrashCardConfig['filter_events'];
// eslint-disable-next-line @typescript-eslint/naming-convention
only_all_day_events: TrashCardConfig['only_all_day_events'];
}

interface Options {
Expand Down Expand Up @@ -47,9 +49,14 @@ const findActiveEvents = (items: CalendarEvent[], { config, now, dropAfter, filt
return false;
}

if (config.only_all_day_events && !item.isWholeDayEvent) {
return false;
}

if (item.isWholeDayEvent) {
return item.date.end > now;
}

if (item.date.end < now) {
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/getCalendarData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ const getCalendarData = async (
config: {
pattern: config.pattern!,
// eslint-disable-next-line @typescript-eslint/naming-convention
filter_events: config.filter_events
filter_events: config.filter_events,
// eslint-disable-next-line @typescript-eslint/naming-convention
only_all_day_events: config.only_all_day_events
},
dropAfter,
now,
Expand Down

0 comments on commit 2cc3283

Please sign in to comment.