|
1 | 1 | <template>
|
2 | 2 | <v-alert
|
3 |
| - v-if="isNewVisit" |
4 |
| - type="success" |
| 3 | + v-if="isBannerVisible" |
| 4 | + :type="alertType" |
5 | 5 | border="start"
|
6 | 6 | variant="tonal"
|
7 | 7 | closable
|
8 | 8 | close-label="Close Alert"
|
9 |
| - :title="title" |
| 9 | + :title="alertTitle" |
10 | 10 | style="min-height: 90px;"
|
11 | 11 | >
|
12 |
| - {{ subtitle }} |
| 12 | + {{ alertSubtitle }} |
13 | 13 | <template v-slot:append>
|
14 | 14 | <v-btn
|
15 | 15 | variant="tonal"
|
16 | 16 | style="position: absolute; bottom: 10px; right: 10px;"
|
17 |
| - @click="handleClick(url)" |
| 17 | + @click="handleClick(alertUrl)" |
18 | 18 | >
|
19 |
| - Open |
| 19 | + {{ buttonText }} |
20 | 20 | </v-btn>
|
21 | 21 | </template>
|
22 | 22 | </v-alert>
|
23 | 23 | </template>
|
24 |
| -<script> |
25 | 24 |
|
| 25 | +<script> |
26 | 26 | import browser from "webextension-polyfill";
|
27 | 27 | import { useSettingStore } from "/src/stores/setting.js";
|
28 | 28 | import { mapState } from "pinia";
|
| 29 | +import {getReviewUrl} from "/src/util/review_util.js"; |
| 30 | +
|
29 | 31 |
|
30 | 32 | export default {
|
31 | 33 | name: "CommentBanner",
|
32 | 34 | emits: ["click"],
|
33 |
| - // props: ["title"], |
34 | 35 | data() {
|
35 | 36 | return {
|
36 |
| - title: browser.i18n.getMessage("Support_this_extension"), |
37 |
| - subtitle: browser.i18n.getMessage("Feed_a_coffee_to_the_extension_devs"), |
38 |
| - url: "https://buymeacoffee.com/ttop324", |
| 37 | + messages: { |
| 38 | + title: browser.i18n.getMessage("Support_this_extension"), |
| 39 | + subtitle: browser.i18n.getMessage("Feed_a_coffee_to_the_extension_devs"), |
| 40 | + url: "https://buymeacoffee.com/ttop324", |
| 41 | + reviewTitle: browser.i18n.getMessage("Review_this"), |
| 42 | + reviewSubtitle: browser.i18n.getMessage("Developer_love_criticism"), |
| 43 | + reviewUrl: getReviewUrl(), |
| 44 | + }, |
| 45 | + coffeeCount: 0, |
| 46 | + isBannerVisible: false, |
| 47 | + alertType: "", |
| 48 | + alertTitle: "", |
| 49 | + alertSubtitle: "", |
| 50 | + alertUrl: "", |
| 51 | + buttonText: "", |
39 | 52 | };
|
40 | 53 | },
|
41 | 54 | async mounted() {
|
42 | 55 | await this.waitSettingLoad();
|
43 |
| - this.increasePopupCount(); |
| 56 | + this.updateCoffeeCount(); |
| 57 | + this.updateBannerProperties(); |
44 | 58 | },
|
45 | 59 | computed: {
|
46 | 60 | ...mapState(useSettingStore, ["setting", "waitSettingLoad"]),
|
47 |
| - isNewVisit() { |
48 |
| - var count = Number(this.setting?.["coffeeCount"]); |
49 |
| - return 1 < count && count < 15; |
| 61 | + coffeeCount() { |
| 62 | + return Number(this.setting?.["coffeeCount"]); |
50 | 63 | },
|
51 | 64 | },
|
52 | 65 | methods: {
|
53 |
| - openUrl(newURL) { |
54 |
| - window.open(newURL); |
55 |
| - }, |
56 |
| - handleClick(newURL) { |
57 |
| - this.openUrl(newURL); |
58 |
| - this.finishPopupCount(); |
| 66 | + handleClick(url) { |
| 67 | + window.open(url); |
| 68 | + this.updateCoffeeCount(10); |
| 69 | + this.updateBannerProperties(); |
59 | 70 | this.$emit("click");
|
60 | 71 | },
|
61 |
| - increasePopupCount(inc = 1) { |
62 |
| - var count = Number(this.setting["coffeeCount"]); |
63 |
| - if (count < 17) { |
64 |
| - this.setting["coffeeCount"] = count + inc; |
65 |
| - } |
| 72 | + updateCoffeeCount(increment = 1) { |
| 73 | + const count = Number(this.setting["coffeeCount"]); |
| 74 | + this.setting["coffeeCount"] = Math.min(count + increment, 17); |
| 75 | + this.coffeeCount = this.setting["coffeeCount"]; |
66 | 76 | },
|
67 |
| - finishPopupCount() { |
68 |
| - this.increasePopupCount(100); |
| 77 | + updateBannerProperties() { |
| 78 | + this.isBannerVisible = this.coffeeCount < 15; |
| 79 | + this.alertType = this.coffeeCount < 5 ? "info" : "success"; |
| 80 | + this.alertTitle = this.coffeeCount < 5 ? this.messages.reviewTitle : this.messages.title; |
| 81 | + this.alertSubtitle = this.coffeeCount < 5 ? this.messages.reviewSubtitle : this.messages.subtitle; |
| 82 | + this.alertUrl = this.coffeeCount < 5 ? this.messages.reviewUrl : this.messages.url; |
| 83 | + this.buttonText = this.coffeeCount < 5 ? "Review" : "Open"; |
69 | 84 | },
|
70 | 85 | },
|
71 | 86 | };
|
|
0 commit comments