Deduplicate versions

This commit is contained in:
beerpiss 2024-03-05 12:43:09 +07:00
parent 343675219e
commit 6ef52c88b1
3 changed files with 21 additions and 6 deletions

View File

@ -364,7 +364,7 @@ export const useFetchPlayerScoreLog = ({
try {
const user = await ApiFetch<{ body: { version: number; } }>("/SDHD/user");
// Check if the version in the response is the expected version
if (user.body.body.version !== 14) {
if (user.body.body.version !== ARTEMIS_CHUNITHM_VERSION) {
setError("Please update to the latest version")
setLoading(false)
return
@ -423,7 +423,7 @@ export const useFetchStaticMusic = ({
try {
const user = await ApiFetch<{ body: { version: number; } }>("/SDHD/user");
// Check if the version in the response is the expected version
if (user.body.body.version !== 14) {
if (user.body.body.version !== ARTEMIS_CHUNITHM_VERSION) {
setError("Please update to the latest version")
setLoading(false)
return

View File

@ -3,6 +3,7 @@
import React, { useState } from "react"
import Image from "next/image"
import { UsePlayerInfo } from "@/app/axios/useFetchApi"
import { ARTEMIS_CHUNITHM_LUMINOUS, SUPPORTED_VERSIONS } from "@/lib/constants"
interface CharacterImageProps {
characterId: number
@ -62,12 +63,12 @@ const CharacterCard = () => {
// Fetch player info using custom hook
UsePlayerInfo({ setPlayerInfo, setLoading, setError })
const isVersion14 = profileData.some(
(user) => user.version === 14 || user.version === 13,
const isSupportedVersion = profileData.some(
(user) => SUPPORTED_VERSIONS.includes(user.version),
)
if (!Array.isArray(profileData) || profileData.length === 0 || !isVersion14) {
return null // Don't render the card if version is not 14
if (!Array.isArray(profileData) || profileData.length === 0 || !isSupportedVersion) {
return null // Don't render the card if version is not supported
}
// get the highest version of a users profile

14
src/lib/constants.ts Normal file
View File

@ -0,0 +1,14 @@
export const ARTEMIS_CHUNITHM_SUN = 13;
export const ARTEMIS_CHUNITHM_SUN_PLUS = 14;
export const ARTEMIS_CHUNITHM_LUMINOUS = 15;
export const SUPPORTED_VERSIONS = [
ARTEMIS_CHUNITHM_SUN,
ARTEMIS_CHUNITHM_SUN_PLUS,
ARTEMIS_CHUNITHM_LUMINOUS,
];
/**
* This follows the version IDs set out by [ARTEMiS](https://gitea.tendokyu.moe/Hay1tsme/artemis/src/branch/master/docs/game_specific_info.md#chunithm).
*/
export const ARTEMIS_CHUNITHM_VERSION = ARTEMIS_CHUNITHM_SUN_PLUS;