import variables from "modules/variables"; import { PureComponent, createRef } from "react"; import { MdOutlineWifiOff } from "react-icons/md"; import Modal from "react-modal"; import Lightbox from "../../marketplace/Lightbox"; export default class Changelog extends PureComponent { constructor() { super(); this.state = { title: null, showLightbox: false, lightboxImg: null, }; this.offlineMode = localStorage.getItem("offlineMode") === "true"; this.controller = new AbortController(); this.changelog = createRef(); } async getUpdate() { const data = await ( await fetch(variables.constants.BLOG_POST + "/index.json", { signal: this.controller.signal, }) ).json(); if (this.controller.signal.aborted === true) { return; } let date = new Date(data.date.split(" ")[0]); date = date.toLocaleDateString(variables.languagecode.replace("_", "-"), { year: "numeric", month: "long", day: "numeric", }); this.setState({ title: data.title, date, image: data.featured_image || null, author: variables.language.getMessage( variables.languagecode, "modals.main.settings.sections.changelog.by", { author: data.authors.join(", "), } ), html: data.html, }); // lightbox etc const images = this.changelog.current.getElementsByTagName("img"); const links = this.changelog.current.getElementsByTagName("a"); for (const img of images) { img.draggable = false; img.onclick = () => { this.setState({ showLightbox: true, lightboxImg: img.src, }); }; } // open in new tab for (let link = 0; link < links.length; link++) { links[link].target = "_blank"; links[link].rel = "noopener noreferrer"; } } componentDidMount() { if (navigator.onLine === false || this.offlineMode) { return; } this.getUpdate(); } componentWillUnmount() { // stop making requests this.controller.abort(); } render() { const getMessage = (text) => variables.language.getMessage(variables.languagecode, text); const errorMessage = (msg) => { return (
{getMessage("modals.main.marketplace.offline.description")}
> ); } if (!this.state.title) { return errorMessage(