MCPcopy Create free account
hub / github.com/massCodeIO/massCode / useDonationTriggers

Function useDonationTriggers

src/renderer/composables/useDonationTriggers.ts:47–187  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

45let started = false
46
47export 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(

Callers

nothing calls this directly

Calls 8

useDonationsFunction · 0.90
getIntervalMilestoneFunction · 0.85
markCopyMilestoneShownFunction · 0.85
showToastFunction · 0.85
markSentMilestoneShownFunction · 0.85
getStreakMilestoneFunction · 0.85
markStreakMilestoneShownFunction · 0.85

Tested by

no test coverage detected