Skip to content

Commit 1477f45

Browse files
committed
feat(mahol): add monthly reward notification
1 parent fbb5aed commit 1477f45

File tree

12 files changed

+110
-5
lines changed

12 files changed

+110
-5
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dependencies": {
1212
"@vueuse/core": "^8.2.3",
1313
"core-js": "^3.8.3",
14+
"date-fns": "^2.28.0",
1415
"flat": "^5.0.2",
1516
"pinia": "^2.0.13",
1617
"pinia-plugin-persistedstate": "^1.5.1",

src/router/index.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import {
1313
Job,
1414
QuestsMenu,
1515
Carriage,
16+
MonthlyReward,
17+
Verification,
1618
} from "@/views"
1719
import NotFound from "./NotFound.vue"
18-
import { Verification } from "@/views/Verification"
1920

2021
const routes: Array<RouteRecordRaw> = [
2122
{
@@ -70,6 +71,11 @@ const routes: Array<RouteRecordRaw> = [
7071
name: "dailyReward",
7172
component: DailyReward,
7273
},
74+
{
75+
path: "/monthlyreward",
76+
name: "monthlyReward",
77+
component: MonthlyReward,
78+
},
7379
{
7480
path: "/safemode",
7581
name: "safemode",

src/views/Mahol/Daily/DailyReward.vue

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { storeToRefs } from "pinia"
55
import { onMounted } from "vue"
66
77
const notificationStore = useMaholDailyStore()
8-
const { shouldRemindDailyReward, lastRewardClaimTimestamp, isSafeModeNotificationDismissed } =
9-
storeToRefs(notificationStore)
8+
const { shouldRemindDailyReward, lastRewardClaimTimestamp } = storeToRefs(notificationStore)
109
1110
onMounted(() => {
1211
const claimButton = document.querySelector<HTMLButtonElement>(".mt-8.flex.justify-center button")
@@ -20,7 +19,6 @@ onMounted(() => {
2019
2120
confirmButton.addEventListener("click", () => {
2221
lastRewardClaimTimestamp.value = new Date().toISOString()
23-
isSafeModeNotificationDismissed.value = false
2422
})
2523
})
2624
})

src/views/Mahol/Monthly/Monthly.vue

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<script setup lang="ts">
2+
import { Controls, Checkbox } from "@/components"
3+
import { useMaholMonthlyStore } from "./store"
4+
import { storeToRefs } from "pinia"
5+
import { onMounted } from "vue"
6+
7+
const monthlyStore = useMaholMonthlyStore()
8+
const { shouldRemindMonthlyReward, lastRewardClaimTimestamp } = storeToRefs(monthlyStore)
9+
10+
onMounted(() => {
11+
const claimButton = document.querySelector<HTMLButtonElement>(".mt-8.flex.justify-center button")
12+
if (!claimButton) return
13+
14+
claimButton.addEventListener("click", () => {
15+
/** let native script hydrate dom */
16+
setTimeout(() => {
17+
const confirmButton = document.querySelector<HTMLButtonElement>(".swal2-actions button")
18+
if (!confirmButton) return
19+
20+
confirmButton.addEventListener("click", () => {
21+
lastRewardClaimTimestamp.value = new Date().toISOString()
22+
})
23+
})
24+
})
25+
})
26+
</script>
27+
28+
<template>
29+
<Controls to=".max-w-7xl.mx-auto.text-center.py-12.px-4">
30+
<Checkbox v-model="shouldRemindMonthlyReward">
31+
<template #default> Remind about daily rewards </template>
32+
<template #subtitle> Miss them daily rewards never more </template>
33+
</Checkbox>
34+
</Controls>
35+
</template>

src/views/Mahol/Monthly/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as MonthlyReward } from "./Monthly.vue"

src/views/Mahol/Monthly/store.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { defineStore } from "pinia"
2+
import { computed, ref } from "vue"
3+
import { addMonths, getDay, isAfter, setDate, startOfDay } from "date-fns"
4+
import { MS_IN_DAY } from "@/consts"
5+
import { getLondonTime } from "@/utils"
6+
7+
export const useMaholMonthlyStore = defineStore(
8+
"maholMonthly",
9+
() => {
10+
const shouldRemindMonthlyReward = ref(false)
11+
12+
const lastRewardClaimTimestamp = ref(new Date().toISOString())
13+
14+
const isMonthlyRewardReady = computed(() => {
15+
const lastClaimDate = startOfDay(new Date(new Date(lastRewardClaimTimestamp.value).valueOf() - MS_IN_DAY / 2))
16+
17+
const nextClaimDate = (() => {
18+
const claimDay = getDay(lastClaimDate)
19+
if (claimDay < 28) return setDate(lastClaimDate, 28)
20+
return addMonths(setDate(lastClaimDate, 28), 1)
21+
})()
22+
23+
return isAfter(getLondonTime().valueOf() - MS_IN_DAY / 2, nextClaimDate)
24+
})
25+
26+
return {
27+
shouldRemindMonthlyReward,
28+
lastRewardClaimTimestamp,
29+
isMonthlyRewardReady,
30+
}
31+
},
32+
{
33+
persist: true,
34+
}
35+
)

src/views/Mahol/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from "./Daily"
2+
export * from "./Monthly"
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script setup lang="ts">
2+
import BaseItem from "./BaseItem.vue"
3+
4+
import { Button } from "@/components"
5+
import { storeToRefs } from "pinia"
6+
import { useMaholMonthlyStore } from "@/views/Mahol/Monthly/store"
7+
8+
const maholMonthlyStore = useMaholMonthlyStore()
9+
const { isMonthlyRewardReady, lastRewardClaimTimestamp } = storeToRefs(maholMonthlyStore)
10+
</script>
11+
12+
<template>
13+
<BaseItem v-if="isMonthlyRewardReady" @dismiss="lastRewardClaimTimestamp = new Date().toISOString()">
14+
<template #title> Monthly reward available! </template>
15+
<template #text> Claim your monthly reward now! </template>
16+
<template #actions>
17+
<Button href="/monthlyreward"> Claim </Button>
18+
</template>
19+
</BaseItem>
20+
</template>

src/views/Notification/Items/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { default as Daily } from "./Daily.vue"
22
export { default as SafeMode } from "./SafeMode.vue"
3+
export { default as Monthly } from "./Monthly.vue"

src/views/Notification/Notification.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<script setup lang="ts">
2-
import { Daily, SafeMode } from "./Items"
2+
import { Daily, SafeMode, Monthly } from "./Items"
33
</script>
44

55
<template>
66
<Teleport to="main">
77
<div class="notificationWrapper">
88
<Daily />
9+
<Monthly />
910
<SafeMode />
1011
</div>
1112
</Teleport>

src/views/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export * from "./Mahol"
1212
export * from "./Settings"
1313
export * from "./Jobs"
1414
export * from "./Carriage"
15+
export * from "./Verification"

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -2799,6 +2799,11 @@ csstype@^2.6.8:
27992799
resolved "https://registry.npmmirror.com/csstype/-/csstype-2.6.20.tgz#9229c65ea0b260cf4d3d997cb06288e36a8d6dda"
28002800
integrity sha512-/WwNkdXfckNgw6S5R125rrW8ez139lBHWouiBvX8dfMFtcn6V81REDqnH7+CRpRipfYlyU1CmOnOxrmGcFOjeA==
28012801

2802+
date-fns@^2.28.0:
2803+
version "2.28.0"
2804+
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.28.0.tgz#9570d656f5fc13143e50c975a3b6bbeb46cd08b2"
2805+
integrity sha512-8d35hViGYx/QH0icHYCeLmsLmMUheMmTyV9Fcm6gvNwdw31yXXH+O85sOBJ+OLnLQMKZowvpKb6FgMIQjcpvQw==
2806+
28022807
debug@2.6.9:
28032808
version "2.6.9"
28042809
resolved "https://registry.npmmirror.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"

0 commit comments

Comments
 (0)