From 510072baa344ff5b27d3d5c76d75df08072d6992 Mon Sep 17 00:00:00 2001 From: Mauro Balades Date: Fri, 16 Aug 2024 11:30:45 +0200 Subject: [PATCH] chore: Update dependencies and remove sync-fetch from theme API --- package.json | 1 - src/app/themes/[theme]/page.tsx | 4 ++-- src/components/marketplace.tsx | 2 +- src/components/theme-page.tsx | 8 ++++---- src/lib/themes.ts | 17 ++++++++--------- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index eb2b7bd..ce846ce 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "react-markdown": "^9.0.1", "react-spring": "^9.7.4", "styled-components": "^6.1.12", - "sync-fetch": "^0.5.2", "tailwind-merge": "^2.5.1", "tailwindcss-animate": "^1.0.7", "zod": "^3.23.8" diff --git a/src/app/themes/[theme]/page.tsx b/src/app/themes/[theme]/page.tsx index 2487886..bb2d5c2 100644 --- a/src/app/themes/[theme]/page.tsx +++ b/src/app/themes/[theme]/page.tsx @@ -5,11 +5,11 @@ import ThemePage from "@/components/theme-page"; import { getThemeFromId } from "@/lib/themes"; import { useParams } from "next/navigation"; -export default function ThemeInfoPage() { +export default async function ThemeInfoPage() { const params = useParams<{ theme: string }>(); const { theme: themeID } = params; - const theme = getThemeFromId(themeID); + const theme = await getThemeFromId(themeID); if (!theme) { return
Theme not found
; } diff --git a/src/components/marketplace.tsx b/src/components/marketplace.tsx index 4e9348a..90175c4 100644 --- a/src/components/marketplace.tsx +++ b/src/components/marketplace.tsx @@ -9,7 +9,7 @@ export default function MarketplacePage() { const [themes, setThemes] = React.useState([]); React.useEffect(() => { - setThemes(getAllThemes()); + getAllThemes().then(setThemes); }, []); return ( diff --git a/src/components/theme-page.tsx b/src/components/theme-page.tsx index 091caf9..8e3b00a 100644 --- a/src/components/theme-page.tsx +++ b/src/components/theme-page.tsx @@ -8,7 +8,7 @@ import { ChevronLeft, MoveLeftIcon } from "lucide-react"; export default function ThemePage({ theme }: { theme: ZenTheme }) { const [readme, setReadme] = useState(null); useEffect(() => { - setReadme(getThemeMarkdown(theme)); + getThemeMarkdown(theme).then(setReadme); }, []); return ( @@ -35,10 +35,10 @@ export default function ThemePage({ theme }: { theme: ZenTheme }) {

You need to have Zen Browser installed to install this theme. Download now!


-
+
window.history.back()}> - -

Go back

+ +

Go back

{`${readme}`} diff --git a/src/lib/themes.ts b/src/lib/themes.ts index 3a17b32..ba73811 100644 --- a/src/lib/themes.ts +++ b/src/lib/themes.ts @@ -1,4 +1,3 @@ -import fetch from "sync-fetch"; export interface ZenTheme { name: string @@ -15,12 +14,12 @@ export interface ZenTheme { } const THEME_API = "https://zen-browser.github.io/theme-store/themes.json"; -const CACHE_OPTIONS = {}; +const CACHE_OPTIONS = { cache: "force-cache" } as RequestInit; -export function getAllThemes(): ZenTheme[] { +export async function getAllThemes() { // Fetch from the API - const response = fetch(THEME_API, CACHE_OPTIONS); - const themes = response.json(); + const response = await fetch(THEME_API, CACHE_OPTIONS); + const themes = await response.json(); // transform in to a ZenTheme[] as it is currently an object let themesArray: ZenTheme[] = []; for (let key in themes) { @@ -33,12 +32,12 @@ export function getThemesFromSearch(themes: ZenTheme[], query: string): ZenTheme return themes.filter((theme) => theme.name.toLowerCase().includes(query.toLowerCase())); } -export function getThemeFromId(id: string): ZenTheme | undefined { - return getAllThemes().find((theme) => theme.id === id); +export async function getThemeFromId(id: string) { + return (await getAllThemes()).find((theme) => theme.id === id); } -export function getThemeMarkdown(theme: ZenTheme): string { - return fetch(theme.readme, CACHE_OPTIONS).text(); +export async function getThemeMarkdown(theme: ZenTheme) { + return (await fetch(theme.readme, CACHE_OPTIONS)).text(); } export function getThemeAuthorLink(theme: ZenTheme): string {