chore: Update dependencies and remove sync-fetch from theme API

This commit is contained in:
Mauro Balades
2024-08-16 11:30:45 +02:00
parent 3fe12d8227
commit 510072baa3
5 changed files with 15 additions and 17 deletions

View File

@@ -36,7 +36,6 @@
"react-markdown": "^9.0.1", "react-markdown": "^9.0.1",
"react-spring": "^9.7.4", "react-spring": "^9.7.4",
"styled-components": "^6.1.12", "styled-components": "^6.1.12",
"sync-fetch": "^0.5.2",
"tailwind-merge": "^2.5.1", "tailwind-merge": "^2.5.1",
"tailwindcss-animate": "^1.0.7", "tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8" "zod": "^3.23.8"

View File

@@ -5,11 +5,11 @@ import ThemePage from "@/components/theme-page";
import { getThemeFromId } from "@/lib/themes"; import { getThemeFromId } from "@/lib/themes";
import { useParams } from "next/navigation"; import { useParams } from "next/navigation";
export default function ThemeInfoPage() { export default async function ThemeInfoPage() {
const params = useParams<{ theme: string }>(); const params = useParams<{ theme: string }>();
const { theme: themeID } = params; const { theme: themeID } = params;
const theme = getThemeFromId(themeID); const theme = await getThemeFromId(themeID);
if (!theme) { if (!theme) {
return <div>Theme not found</div>; return <div>Theme not found</div>;
} }

View File

@@ -9,7 +9,7 @@ export default function MarketplacePage() {
const [themes, setThemes] = React.useState<ZenTheme[]>([]); const [themes, setThemes] = React.useState<ZenTheme[]>([]);
React.useEffect(() => { React.useEffect(() => {
setThemes(getAllThemes()); getAllThemes().then(setThemes);
}, []); }, []);
return ( return (

View File

@@ -8,7 +8,7 @@ import { ChevronLeft, MoveLeftIcon } from "lucide-react";
export default function ThemePage({ theme }: { theme: ZenTheme }) { export default function ThemePage({ theme }: { theme: ZenTheme }) {
const [readme, setReadme] = useState<string | null>(null); const [readme, setReadme] = useState<string | null>(null);
useEffect(() => { useEffect(() => {
setReadme(getThemeMarkdown(theme)); getThemeMarkdown(theme).then(setReadme);
}, []); }, []);
return ( return (
@@ -35,10 +35,10 @@ export default function ThemePage({ theme }: { theme: ZenTheme }) {
<p id="install-theme-error" className="text-muted-foreground text-sm mt-2">You need to have Zen Browser installed to install this theme. <a href="/download" className="text-blue-500">Download now!</a></p> <p id="install-theme-error" className="text-muted-foreground text-sm mt-2">You need to have Zen Browser installed to install this theme. <a href="/download" className="text-blue-500">Download now!</a></p>
</div> </div>
<hr className="block my-4 lg:hidden" /> <hr className="block my-4 lg:hidden" />
<div className="flex flex-col p-5 !pt-0 max-w-xl w-full"> <div className="flex flex-col p-5 !pt-0 max-w-xl min-w-xl w-full">
<div className="flex my-2 items-center cursor-pointer opacity-70" onClick={() => window.history.back()}> <div className="flex my-2 items-center cursor-pointer opacity-70" onClick={() => window.history.back()}>
<ChevronLeft className="w-6 h-6 mr-1" /> <ChevronLeft className="w-4 h-4 mr-1" />
<h3 className="text-lg font-bold">Go back</h3> <h3 className="text-md">Go back</h3>
</div> </div>
<div id="policy"> <div id="policy">
<Markdown>{`${readme}`}</Markdown> <Markdown>{`${readme}`}</Markdown>

View File

@@ -1,4 +1,3 @@
import fetch from "sync-fetch";
export interface ZenTheme { export interface ZenTheme {
name: string name: string
@@ -15,12 +14,12 @@ export interface ZenTheme {
} }
const THEME_API = "https://zen-browser.github.io/theme-store/themes.json"; 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 // Fetch from the API
const response = fetch(THEME_API, CACHE_OPTIONS); const response = await fetch(THEME_API, CACHE_OPTIONS);
const themes = response.json(); const themes = await response.json();
// transform in to a ZenTheme[] as it is currently an object // transform in to a ZenTheme[] as it is currently an object
let themesArray: ZenTheme[] = []; let themesArray: ZenTheme[] = [];
for (let key in themes) { 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())); return themes.filter((theme) => theme.name.toLowerCase().includes(query.toLowerCase()));
} }
export function getThemeFromId(id: string): ZenTheme | undefined { export async function getThemeFromId(id: string) {
return getAllThemes().find((theme) => theme.id === id); return (await getAllThemes()).find((theme) => theme.id === id);
} }
export function getThemeMarkdown(theme: ZenTheme): string { export async function getThemeMarkdown(theme: ZenTheme) {
return fetch(theme.readme, CACHE_OPTIONS).text(); return (await fetch(theme.readme, CACHE_OPTIONS)).text();
} }
export function getThemeAuthorLink(theme: ZenTheme): string { export function getThemeAuthorLink(theme: ZenTheme): string {