import { newsAtom, showNewsModalAtom } from "@/atoms/news-atom"; import { translationAtom } from "@/atoms/translations-atom"; import matter, { GrayMatterFile } from "gray-matter"; import { useAtom, useAtomValue } from "jotai"; import React, { useEffect } from "react"; import Markdown from "react-markdown"; import remarkGfm from "remark-gfm"; export const NewsModal = () => { const t = useAtomValue(translationAtom); const [news, setNews] = useAtom(newsAtom); const [showNewsModal, setShowNewsModal] = useAtom(showNewsModalAtom); useEffect(() => { // TODO: ADD AN ABOUT TAB if (window && window.navigator.onLine === false) return; try { fetch("https://raw.githubusercontent.com/upscayl/upscayl/main/news.md", { cache: "no-cache", }) .then((res) => { return res.text(); }) .then((result) => { const newsData = result; if (!newsData) { console.log("📰 Could not fetch news data"); return; } const markdownData = matter(newsData); if (!markdownData) return; if (markdownData && markdownData.data.dontShow) { return; } if ( markdownData && news && markdownData?.data?.version === news?.data?.version ) { console.log("📰 News is up to date"); if (showNewsModal === false) { setShowNewsModal(false); } } else if (markdownData) { setNews(matter(newsData)); setShowNewsModal(true); } }); } catch (error) { console.log("Could not fetch Upscayl News"); } }, [news]); return (
{news && ( {news.content} )}
); };