From 1e4774d6e36f1391c9a402d8c7f54efc948c6051 Mon Sep 17 00:00:00 2001 From: Matt Isenhower Date: Wed, 14 Dec 2022 09:58:52 -0800 Subject: [PATCH 1/4] Make it easier to test the website in a local dev environment --- .env.example | 3 +++ src/stores/data.mjs | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 649dec7..90a3ffa 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,9 @@ # Site Config SITE_URL=https://splatoon3.ink +# Load data from Splatoon3.ink during development +VITE_DATA_FROM=https://splatoon3.ink + # Nintendo API NINTENDO_TOKEN= diff --git a/src/stores/data.mjs b/src/stores/data.mjs index b467998..98032aa 100644 --- a/src/stores/data.mjs +++ b/src/stores/data.mjs @@ -11,7 +11,8 @@ function defineEndpointStore(id, endpoint, transform = null) { isUpdating.value = true; try { - let response = await fetch(endpoint); + let baseUrl = import.meta.env.VITE_DATA_FROM || ''; + let response = await fetch(baseUrl + endpoint); if (!response.ok) { console.error(response); From b2eef88acb827247fc74b0abee898ce543906cef Mon Sep 17 00:00:00 2001 From: Matt Isenhower Date: Fri, 23 Dec 2022 14:57:58 -0800 Subject: [PATCH 2/4] Add Splatfest tweet --- app/social/generators/SplatfestStatus.mjs | 91 +++++++++++++++++++++++ app/social/index.mjs | 2 + src/views/screenshots/SplatfestView.vue | 6 +- 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 app/social/generators/SplatfestStatus.mjs diff --git a/app/social/generators/SplatfestStatus.mjs b/app/social/generators/SplatfestStatus.mjs new file mode 100644 index 0000000..84df832 --- /dev/null +++ b/app/social/generators/SplatfestStatus.mjs @@ -0,0 +1,91 @@ +import StatusGenerator from "./StatusGenerator.mjs"; +import Media from "../Media.mjs"; +import { useUSSplatfestsStore, STATUS_ACTIVE, STATUS_PAST } from '../../../src/stores/splatfests.mjs'; +import { useTimeStore } from "../../../src/stores/time.mjs"; + +export default class SplatfestStatus extends StatusGenerator +{ + key = 'splatfest'; + name = 'Splatfest'; + + async getFestival() { + await this.preparePinia(); + let store = useUSSplatfestsStore(); + + return store.upcomingFestival + || store.activeFestival + || store.recentFestival; + } + + async getState() { + let festival = await this.getFestival(); + + let startTime = Date.parse(festival?.startTime); + let now = useTimeStore().now; + let hoursAway = (startTime - now) / (1000 * 60 * 60); + + switch (true) { + case !festival: + return null; + case festival.status === STATUS_PAST: + return 'ended'; + case festival.status === STATUS_ACTIVE: + return 'active'; + case hoursAway <= 24: + return 'upcoming:1d'; + case hoursAway <= 72: + return 'upcoming:3d'; + default: + return 'upcoming'; + } + } + + async getDataTime() { + let festival = await this.getFestival(); + let state = await this.getState(); + + if (!festival || !state) { + return null; + } + + return `${festival}:${state}`; + } + + async shouldPost(client) { + let currentId = await this.getDataTime(); + + let cachedId = await this.lastPostCache(client).getData(); + + return currentId && currentId !== cachedId; + } + + async _getStatus() { + let festival = await this.getFestival(); + let state = await this.getState(); + + if (!festival || !state) { + return false; + } + + switch (state) { + case 'upcoming': + return `You can now vote in the next global Splatfest: ${festival.title} #splatfest #splatoon3`; + case 'upcoming:3d': + return `Reminder: The next global Splatfest starts in 3 DAYS! ${festival.title} #splatfest #splatoon3` + case 'upcoming:1d': + return `Reminder: The next global Splatfest starts in 24 HOURS! ${festival.title} #splatfest #splatoon3` + case 'active': + return `The global Splatfest is NOW OPEN! ${festival.title} #splatfest #splatoon3` + case 'ended': + return `The global Splatfest is now closed. Results are usually posted within 2 hours! #splatfest #splatoon3` + } + } + + /** @param {ScreenshotHelper} screenshotHelper */ + async _getMedia(screenshotHelper) { + let media = new Media; + media.file = await screenshotHelper.capture('splatfest'); + + return media; + } +} diff --git a/app/social/index.mjs b/app/social/index.mjs index 01ed7bc..5ef6e11 100644 --- a/app/social/index.mjs +++ b/app/social/index.mjs @@ -6,6 +6,7 @@ import RegularGearStatus from "./generators/RegularGearStatus.mjs"; import SalmonRunGearStatus from "./generators/SalmonRunGearStatus.mjs"; import SalmonRunStatus from "./generators/SalmonRunStatus.mjs"; import SchedulesStatus from "./generators/SchedulesStatus.mjs"; +import SplatfestStatus from "./generators/SplatfestStatus.mjs"; import SplatfestResultsStatus from "./generators/SplatfestResultsStatus.mjs"; import StatusGeneratorManager from "./StatusGeneratorManager.mjs" @@ -16,6 +17,7 @@ function defaultStatusGenerators() { new RegularGearStatus, new SalmonRunStatus, new SalmonRunGearStatus, + new SplatfestStatus, new SplatfestResultsStatus, ]; } diff --git a/src/views/screenshots/SplatfestView.vue b/src/views/screenshots/SplatfestView.vue index 4fa7c72..9dbaecd 100644 --- a/src/views/screenshots/SplatfestView.vue +++ b/src/views/screenshots/SplatfestView.vue @@ -23,5 +23,9 @@ import SplatfestResultsBox from '@/components/SplatfestResultsBox.vue'; import { computed } from 'vue'; const usSplatfests = useUSSplatfestsStore(); -const festival = computed(() => usSplatfests.activeFestival ?? usSplatfests.recentFestival); +const festival = computed(() => + usSplatfests.upcomingFestival + ?? usSplatfests.activeFestival + ?? usSplatfests.recentFestival +); From 37b74d86890f3f2a8d784b27883b9bafa1cb8152 Mon Sep 17 00:00:00 2001 From: Matt Isenhower Date: Fri, 23 Dec 2022 15:01:50 -0800 Subject: [PATCH 3/4] Add Fediverse handle to screenshot layout --- src/layouts/ScreenshotLayout.vue | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/layouts/ScreenshotLayout.vue b/src/layouts/ScreenshotLayout.vue index 8991634..b5e8679 100644 --- a/src/layouts/ScreenshotLayout.vue +++ b/src/layouts/ScreenshotLayout.vue @@ -18,6 +18,10 @@ @splatoon3ink +
+ + @splatoon3ink@splatoon3.ink +
splatoon3.ink
From 2e7845cd03df4fdc69c3645eb40f84997c601b7d Mon Sep 17 00:00:00 2001 From: Matt Isenhower Date: Fri, 23 Dec 2022 15:11:10 -0800 Subject: [PATCH 4/4] Fix a mistake --- app/social/generators/SplatfestStatus.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/social/generators/SplatfestStatus.mjs b/app/social/generators/SplatfestStatus.mjs index 84df832..531e941 100644 --- a/app/social/generators/SplatfestStatus.mjs +++ b/app/social/generators/SplatfestStatus.mjs @@ -48,7 +48,7 @@ export default class SplatfestStatus extends StatusGenerator return null; } - return `${festival}:${state}`; + return `${festival.id}:${state}`; } async shouldPost(client) {