Skip to content

Commit

Permalink
Added config for first day in week for calendar widget (#2080)
Browse files Browse the repository at this point in the history
  • Loading branch information
denispapec authored Sep 28, 2023
1 parent 92bef4a commit 605042f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/utils/config/service-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ export function cleanServiceGroups(groups) {
mappings, // customapi widget
refreshInterval,
integrations, // calendar widget
firstDayInWeek,
} = cleanedService.widget;

let fieldsList = fields;
Expand Down Expand Up @@ -443,6 +444,7 @@ export function cleanServiceGroups(groups) {
}
if (type === "calendar") {
if (integrations) cleanedService.widget.integrations = integrations;
if (firstDayInWeek) cleanedService.widget.firstDayInWeek = firstDayInWeek;
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/widgets/calendar/monthly-view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,23 @@ export default function MonthlyView({ service }) {

const dayNames = Info.weekdays("short", { locale: i18n.language });

const firstDayInCalendar = widget?.firstDayInCalendar ? widget?.firstDayInCalendar?.toLowerCase() : "monday";
for (let i = 1; i < dayInWeekId[firstDayInCalendar]; i+=1) {
const firstDayInWeekCalendar = widget?.firstDayInWeek ? widget?.firstDayInWeek?.toLowerCase() : "monday";
for (let i = 1; i < dayInWeekId[firstDayInWeekCalendar]; i+=1) {
dayNames.push(dayNames.shift());
}

const daysInWeek = useMemo(() => [ ...Array(7).keys() ].map( i => i + dayInWeekId[firstDayInCalendar]
), [(firstDayInCalendar)]);
const daysInWeek = useMemo(() => [ ...Array(7).keys() ].map( i => i + dayInWeekId[firstDayInWeekCalendar]
), [firstDayInWeekCalendar]);

if (!showDate) {
return <div className="w-full text-center" />;
}

const firstWeek = DateTime.local(showDate.year, showDate.month, 1).setLocale(i18n.language);

const weekIncrementChange = dayInWeekId[firstDayInWeekCalendar] > firstWeek.weekday ? -1 : 0;
let weekNumbers = [ ...Array(Math.ceil(5) + 1).keys() ]
.map(i => firstWeek.weekNumber+i);
.map(i => firstWeek.weekNumber + weekIncrementChange + i);

if (weekNumbers.includes(55)) {
// if we went too far with the weeks, it's the beginning of the year
Expand Down

0 comments on commit 605042f

Please sign in to comment.