Skip to content

Commit

Permalink
refactor: Update data retrieval in Genshin character and teams pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dvaJi committed Sep 10, 2024
1 parent 4fe8512 commit 8fd4c29
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
8 changes: 6 additions & 2 deletions app/[lang]/(genshin)/builds/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { i18n } from "@i18n-config";
import type { Artifact, Character, Weapon } from "@interfaces/genshin";
import { AD_ARTICLE_SLOT } from "@lib/constants";
import { getGenshinData } from "@lib/dataApi";
import { getData, getRemoteData } from "@lib/localData";
import { getData } from "@lib/localData";
import { getBonusSet } from "@utils/bonus_sets";

import ElementsFilter from "./elements-filter";
Expand Down Expand Up @@ -72,7 +72,11 @@ export default async function GenshinCharacterPage({ params }: Props) {
language: langData as any,
select: ["id", "name", "rarity", "element"],
}),
getRemoteData<Record<string, Build>>("genshin", "builds"),
getGenshinData<Record<string, Build>>({
resource: "builds",
language: langData as any,
asMap: true,
}),
getGenshinData<Record<string, Weapon>>({
resource: "weapons",
language: langData as any,
Expand Down
12 changes: 9 additions & 3 deletions app/[lang]/(genshin)/character/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { Artifact, Character, Weapon } from "@interfaces/genshin";
import { AD_ARTICLE_SLOT } from "@lib/constants";
import { getGenshinData } from "@lib/dataApi";
import { getUrl } from "@lib/imgUrl";
import { getData, getRemoteData } from "@lib/localData";
import { getData } from "@lib/localData";
import { getBonusSet } from "@utils/bonus_sets";
import { localeToLang } from "@utils/locale-to-lang";
import {
Expand Down Expand Up @@ -139,7 +139,13 @@ export default async function GenshinCharacterPage({ params }: Props) {
artifactsList,
] = await Promise.all([
getData<Beta>("genshin", "beta"),
getRemoteData<Record<string, Build>>("genshin", "builds"),
getGenshinData<Build>({
resource: "builds",
language: langData as any,
filter: {
id: params.id,
},
}),
getGenshinData<MostUsedBuild>({
resource: "mostUsedBuilds",
language: langData as any,
Expand Down Expand Up @@ -193,7 +199,7 @@ export default async function GenshinCharacterPage({ params }: Props) {
return notFound();
}

const buildsOld = _buildsOld[character.id] || { builds: [] };
const buildsOld = _buildsOld || { builds: [] };

let weapons: Record<string, Weapon> = {};
let artifacts: Record<string, Artifact & { children?: Artifact[] }> = {};
Expand Down
1 change: 1 addition & 0 deletions interfaces/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type CharBuild = {
};

export interface Build {
id: string;
notes: string;
builds: CharBuild[];
}
Expand Down

0 comments on commit 8fd4c29

Please sign in to comment.