forked from mermaid-js/mermaid-live-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f64df7
commit 9ba2598
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/holiday-promo" | ||
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-28'), | ||
endDate: new Date('2023-12-31'), | ||
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) | ||
) | ||
.toSorted((a: Promotion, b: Promotion) => b.endDate.getTime() - a.endDate.getTime()) | ||
.pop(); | ||
}; |