()
| 45 | let started = false |
| 46 | |
| 47 | export function useDonationTriggers() { |
| 48 | if (started) { |
| 49 | return |
| 50 | } |
| 51 | started = true |
| 52 | |
| 53 | const { |
| 54 | donations, |
| 55 | today, |
| 56 | markCopyMilestoneShown, |
| 57 | markCreatedMilestoneShown, |
| 58 | markSentMilestoneShown, |
| 59 | markStreakMilestoneShown, |
| 60 | setGreetingDay, |
| 61 | } = useDonations() |
| 62 | |
| 63 | function showToast(title: string) { |
| 64 | const { isSponsored } = useApp() |
| 65 | |
| 66 | if (isSponsored.value || isToastVisible.value) { |
| 67 | return |
| 68 | } |
| 69 | isToastVisible.value = true |
| 70 | |
| 71 | const todayKey = today() |
| 72 | const variant = donations.lastGreetingDay === todayKey ? 'short' : 'full' |
| 73 | if (variant === 'full') { |
| 74 | setGreetingDay(todayKey) |
| 75 | } |
| 76 | |
| 77 | toast.custom(markRaw(Donate), { |
| 78 | componentProps: { title, variant }, |
| 79 | duration: Infinity, |
| 80 | onDismiss: () => { |
| 81 | isToastVisible.value = false |
| 82 | }, |
| 83 | }) |
| 84 | } |
| 85 | |
| 86 | COPY_SPACES.forEach((space) => { |
| 87 | watch( |
| 88 | () => donations.copies[space], |
| 89 | (count) => { |
| 90 | const milestone = getIntervalMilestone(count, COPY_INTERVAL) |
| 91 | if ( |
| 92 | milestone === null |
| 93 | || milestone <= donations.lastShownCopyMilestones[space] |
| 94 | ) { |
| 95 | return |
| 96 | } |
| 97 | |
| 98 | markCopyMilestoneShown(space, milestone) |
| 99 | |
| 100 | if (isToastVisible.value) { |
| 101 | return |
| 102 | } |
| 103 | |
| 104 | showToast( |
nothing calls this directly
no test coverage detected