switch to async storage for faster loading
All checks were successful
deploy / deploy (push) Successful in 1m55s

This commit is contained in:
Lee
2023-10-23 09:54:26 +01:00
parent 70ed248be7
commit a0aca8c9b1
10 changed files with 118 additions and 89 deletions

View File

@ -8,6 +8,7 @@ import { ScoresaberPlayer } from "@/schemas/scoresaber/player";
import { useSettingsStore } from "@/store/settingsStore";
import { SortType, SortTypes } from "@/types/SortTypes";
import { ScoreSaberAPI } from "@/utils/scoresaber/api";
import useStore from "@/utils/useStore";
import dynamic from "next/dynamic";
import { useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";
@ -27,6 +28,7 @@ type PlayerPageProps = {
const DEFAULT_SORT_TYPE = SortTypes.top;
export default function PlayerPage({ id }: PlayerPageProps) {
const settingsStore = useStore(useSettingsStore, (store) => store);
const searchParams = useSearchParams();
const [mounted, setMounted] = useState(false);
@ -49,8 +51,7 @@ export default function PlayerPage({ id }: PlayerPageProps) {
let sortType: SortType;
const sortTypeString = searchParams.get("sort");
if (sortTypeString == null) {
sortType =
useSettingsStore.getState().lastUsedSortType || DEFAULT_SORT_TYPE;
sortType = settingsStore?.lastUsedSortType || DEFAULT_SORT_TYPE;
} else {
sortType = SortTypes[sortTypeString] || DEFAULT_SORT_TYPE;
}