-
-
Notifications
You must be signed in to change notification settings - Fork 574
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* master: chore: Update MC promo link remove toSorted chore: Tweak start and end dates feat: Add Holiday2023 banner
- Loading branch information
Showing
3 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<a | ||
href="https://www.mermaidchart.com/app/user/billing/checkout?coupon=HOLIDAYS2023" | ||
target="_blank" | ||
class="tracking-wide flex-grow"> | ||
Get AI, team collaboration, storage, and more with | ||
<span class="font-bold underline">Mermaid Chart Pro. Start free trial today & get 25% off.</span> | ||
</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { writable, type Writable, get } from 'svelte/store'; | ||
import { persist, localStorage } from '../persist'; | ||
import Holiday2023 from './Holiday2023.svelte'; | ||
|
||
interface Promotion { | ||
id: string; | ||
startDate: Date; | ||
endDate: Date; | ||
component: ConstructorOfATypedSvelteComponent; | ||
} | ||
|
||
const promotions: Promotion[] = [ | ||
{ | ||
id: 'holiday-2023', | ||
startDate: new Date('2023-11-27'), | ||
endDate: new Date('2024-01-01'), | ||
component: Holiday2023 | ||
} | ||
]; | ||
|
||
export const dismissPromotion = (id?: string): void => { | ||
if (!id) { | ||
return; | ||
} | ||
dismissedPromotionsStore.update((dismissedIDs: string[]) => { | ||
dismissedIDs.push(id); | ||
return dismissedIDs; | ||
}); | ||
}; | ||
|
||
const dismissedPromotionsStore: Writable<string[]> = persist( | ||
writable([]), | ||
localStorage(), | ||
'dismissedPromotions' | ||
); | ||
|
||
export const getActivePromotion = (): Promotion | undefined => { | ||
const dismissedPromotions = get(dismissedPromotionsStore); | ||
const now = new Date(); | ||
return promotions | ||
.filter( | ||
(p: Promotion) => | ||
p.startDate <= now && p.endDate >= now && !dismissedPromotions.includes(p.id) | ||
) | ||
.sort((a: Promotion, b: Promotion) => b.endDate.getTime() - a.endDate.getTime()) | ||
.pop(); | ||
}; |