Skip to content

Commit

Permalink
refactor: Update data retrieval and caching in Genshin changelog pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dvaJi committed Sep 5, 2024
1 parent 16fa1ff commit eb03355
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
15 changes: 12 additions & 3 deletions app/[lang]/(genshin)/changelog/[version]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type {
} from "@interfaces/genshin";
import { AD_ARTICLE_SLOT } from "@lib/constants";
import { getGenshinData } from "@lib/dataApi";
import { getRemoteData } from "@lib/localData";
import { getAllMaterialsMap } from "@utils/materials";

import ChangelogVersion from "../view";
Expand Down Expand Up @@ -82,9 +81,19 @@ export default async function GenshinBannerWeapons({ params }: Props) {
"genshin",
"changelog"
);
const changelog = await getRemoteData<Changelog[]>("genshin", "changelog");
const changelog = await getGenshinData<Changelog[]>({
resource: "changelog",
language: langData,
select: ["version"],
});

const cl = changelog.find((c) => c.version === params.version);
const cl = await getGenshinData<Changelog>({
resource: "changelog",
language: langData,
filter: {
id: params.version,
},
});

if (!cl) {
return notFound();
Expand Down
12 changes: 8 additions & 4 deletions app/[lang]/(genshin)/changelog/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type {
} from "@interfaces/genshin";
import { AD_ARTICLE_SLOT } from "@lib/constants";
import { getGenshinData } from "@lib/dataApi";
import { getRemoteData } from "@lib/localData";
import { getAllMaterialsMap } from "@utils/materials";

import ChangelogVersion from "./view";
Expand Down Expand Up @@ -112,8 +111,12 @@ export default async function GenshinBannerWeapons({ params }: Props) {
});

const changelog = (
await getRemoteData<Changelog[]>("genshin", "changelog")
).filter((c) => !c.beta);
await getGenshinData<Changelog[]>({
resource: "changelog",
language: langData,
revalidate: 0,
})
).sort((a, b) => (b.version > a.version ? -1 : 1));

const materialsMap = await getAllMaterialsMap(langData);

Expand All @@ -123,7 +126,8 @@ export default async function GenshinBannerWeapons({ params }: Props) {
const foodMap: any = {};
const tcgMap: any = {};

const cl = changelog[changelog.length - 1];
const cl =
changelog.find((c) => c.current) ?? changelog[changelog.length - 1];

const item = cl.items;
item.avatar?.forEach((a: string) => {
Expand Down
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.

0 comments on commit eb03355

Please sign in to comment.