Allow to hide individual holidays
This commit is contained in:
@@ -33,6 +33,8 @@
|
|||||||
let selectedStateCode = '';
|
let selectedStateCode = '';
|
||||||
let statesList = [];
|
let statesList = [];
|
||||||
|
|
||||||
|
let showHolidaysList = false; // State to toggle the visibility of the holidays list
|
||||||
|
|
||||||
function updateStatesList(countryCode) {
|
function updateStatesList(countryCode) {
|
||||||
const hd = new Holidays(countryCode);
|
const hd = new Holidays(countryCode);
|
||||||
statesList = hd.getStates(countryCode) || [];
|
statesList = hd.getStates(countryCode) || [];
|
||||||
@@ -68,10 +70,6 @@
|
|||||||
daysOff = storedDaysOff ? parseInt(storedDaysOff, 10) : defaultDaysOff;
|
daysOff = storedDaysOff ? parseInt(storedDaysOff, 10) : defaultDaysOff;
|
||||||
selectedState = storedState || '';
|
selectedState = storedState || '';
|
||||||
selectedStateCode = storedStateCode || '';
|
selectedStateCode = storedStateCode || '';
|
||||||
|
|
||||||
const countryCode = Object.keys(countriesList).find(code => countriesList[code] === selectedCountry);
|
|
||||||
updateStatesList(countryCode);
|
|
||||||
|
|
||||||
updateHolidays();
|
updateHolidays();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -114,9 +112,16 @@
|
|||||||
function updateHolidays() {
|
function updateHolidays() {
|
||||||
const countryCode = Object.keys(countriesList).find(code => countriesList[code] === selectedCountry);
|
const countryCode = Object.keys(countriesList).find(code => countriesList[code] === selectedCountry);
|
||||||
if (countryCode) {
|
if (countryCode) {
|
||||||
holidays = getHolidaysForYear(countryCode, year, selectedStateCode);
|
updateStatesList(countryCode);
|
||||||
optimizedDaysOff = optimizeDaysOff(holidays, year, daysOff);
|
let allHolidays = getHolidaysForYear(countryCode, year, selectedStateCode);
|
||||||
consecutiveDaysOff = calculateConsecutiveDaysOff(holidays, optimizedDaysOff, year);
|
holidays = allHolidays.map(holiday => ({
|
||||||
|
...holiday,
|
||||||
|
hidden: isHolidayHidden(holiday)
|
||||||
|
}));
|
||||||
|
// Filter out hidden holidays for calculations
|
||||||
|
const visibleHolidays = holidays.filter(h => !h.hidden);
|
||||||
|
optimizedDaysOff = optimizeDaysOff(visibleHolidays, year, daysOff);
|
||||||
|
consecutiveDaysOff = calculateConsecutiveDaysOff(visibleHolidays, optimizedDaysOff, year);
|
||||||
} else {
|
} else {
|
||||||
holidays = [];
|
holidays = [];
|
||||||
optimizedDaysOff = [];
|
optimizedDaysOff = [];
|
||||||
@@ -200,6 +205,50 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to toggle the visibility of a holiday
|
||||||
|
function toggleHolidayVisibility(holiday) {
|
||||||
|
const countryCode = Object.keys(countriesList).find(code => countriesList[code] === selectedCountry);
|
||||||
|
if (!countryCode) return;
|
||||||
|
|
||||||
|
const storageKey = `hiddenHolidays_${countryCode}`;
|
||||||
|
let hiddenHolidays = JSON.parse(localStorage.getItem(storageKey)) || {};
|
||||||
|
|
||||||
|
// Toggle the hidden state of the holiday
|
||||||
|
hiddenHolidays[holiday.date] = !hiddenHolidays[holiday.date];
|
||||||
|
localStorage.setItem(storageKey, JSON.stringify(hiddenHolidays));
|
||||||
|
|
||||||
|
// Update the holidays list to trigger reactivity
|
||||||
|
holidays = holidays.map(h => {
|
||||||
|
if (h.date === holiday.date) {
|
||||||
|
return { ...h, hidden: hiddenHolidays[h.date] };
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Recalculate holidays to ensure hidden ones are excluded
|
||||||
|
updateHolidays();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to check if a holiday is hidden
|
||||||
|
function isHolidayHidden(holiday) {
|
||||||
|
const countryCode = Object.keys(countriesList).find(code => countriesList[code] === selectedCountry);
|
||||||
|
if (!countryCode) return false;
|
||||||
|
|
||||||
|
const storageKey = `hiddenHolidays_${countryCode}`;
|
||||||
|
const hiddenHolidays = JSON.parse(localStorage.getItem(storageKey)) || {};
|
||||||
|
|
||||||
|
return hiddenHolidays[holiday.date] || false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to format the date
|
||||||
|
function formatDate(dateString) {
|
||||||
|
const options = { day: '2-digit', month: 'short', year: 'numeric' };
|
||||||
|
return new Date(dateString).toLocaleDateString('en-GB', options);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reactive statement to calculate the number of visible holidays
|
||||||
|
$: visibleHolidaysCount = holidays.filter(h => !h.hidden).length;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -439,7 +488,84 @@
|
|||||||
display: block;
|
display: block;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 0.9em;
|
font-size: 0.8em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-box.holiday {
|
||||||
|
background-color: #3b1e6e;
|
||||||
|
display: inline-block;
|
||||||
|
width: 15px;
|
||||||
|
height: 15px;
|
||||||
|
margin-right: 5px;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-box ul {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-box li {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-box button {
|
||||||
|
margin-left: 10px;
|
||||||
|
background-color: #444;
|
||||||
|
border: none;
|
||||||
|
color: #fff;
|
||||||
|
padding: 5px 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-box button:hover {
|
||||||
|
background-color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
.strikethrough {
|
||||||
|
text-decoration: line-through;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-link {
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.8em;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-link:hover {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.holidays-list {
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.holidays-list ul {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.holidays-list li {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.holidays-list button {
|
||||||
|
margin-left: 10px;
|
||||||
|
background-color: #444;
|
||||||
|
border: none;
|
||||||
|
color: #fff;
|
||||||
|
padding: 5px 25px;
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.holidays-list button:hover {
|
||||||
|
background-color: #555;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
@@ -454,8 +580,9 @@
|
|||||||
{selectedState},
|
{selectedState},
|
||||||
{/if}
|
{/if}
|
||||||
{selectedCountry}
|
{selectedCountry}
|
||||||
</strong>, there are <strong>{holidays.length}</strong> public holidays in <strong>{year}</strong>.
|
</strong>, there are <strong>{holidays.length}</strong> public holidays{#if visibleHolidaysCount < holidays.length} (<strong>{visibleHolidaysCount} selected</strong>){/if} in <strong>{year}</strong>.
|
||||||
<br />
|
</p>
|
||||||
|
<p>
|
||||||
Let's stretch your time off from <strong>{daysOff} days</strong> to <strong>{consecutiveDaysOff.reduce((total, group) => total + group.totalDays, 0)} days</strong> (<a href="#how-it-works" on:click={toggleHowItWorks}>how?</a>)
|
Let's stretch your time off from <strong>{daysOff} days</strong> to <strong>{consecutiveDaysOff.reduce((total, group) => total + group.totalDays, 0)} days</strong> (<a href="#how-it-works" on:click={toggleHowItWorks}>how?</a>)
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -488,7 +615,7 @@
|
|||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
{#if year !== defaultYear || selectedCountry !== defaultCountry || daysOff !== defaultDaysOff}
|
{#if year !== defaultYear || selectedCountry !== defaultCountry || daysOff !== defaultDaysOff}
|
||||||
<a href="#" on:click|preventDefault={resetToDefault} class="reset-link">Reset to default</a>
|
<a href="#" on:click|preventDefault={resetToDefault} class="reset-link">Reset to my country</a>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<datalist id="countries">
|
<datalist id="countries">
|
||||||
@@ -504,12 +631,37 @@
|
|||||||
<span class="color-box weekend"></span> Weekend
|
<span class="color-box weekend"></span> Weekend
|
||||||
</div>
|
</div>
|
||||||
<div class="key-item">
|
<div class="key-item">
|
||||||
<span class="color-box optimized"></span> Day Off
|
<span class="color-box optimized"></span> Day Off
|
||||||
</div>
|
</div>
|
||||||
<div class="key-item">
|
<div class="key-item">
|
||||||
<span class="color-box holiday"></span> Public Holiday
|
<span class="color-box holiday"></span> Public Holiday
|
||||||
</div>
|
</div>
|
||||||
|
{#if holidays.length > 0}
|
||||||
|
<a href="#" on:click|preventDefault={() => showHolidaysList = !showHolidaysList} class="edit-link">
|
||||||
|
(edit list)
|
||||||
|
</a>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if showHolidaysList}
|
||||||
|
<div class="holidays-list">
|
||||||
|
<h3>Public Holidays</h3>
|
||||||
|
<ul>
|
||||||
|
{#each holidays as holiday}
|
||||||
|
<li>
|
||||||
|
<span class="color-box holiday"></span>
|
||||||
|
<span class={holiday.hidden ? 'strikethrough' : ''}>
|
||||||
|
{formatDate(holiday.date)}: {holiday.name}
|
||||||
|
</span>
|
||||||
|
<button on:click={() => toggleHolidayVisibility(holiday)}>
|
||||||
|
{holiday.hidden ? 'Show' : 'Hide'}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="calendar-grid">
|
<div class="calendar-grid">
|
||||||
{#each months as month}
|
{#each months as month}
|
||||||
<div class="calendar-container">
|
<div class="calendar-container">
|
||||||
|
|||||||
Reference in New Issue
Block a user