import React, { useState, useEffect } from 'react' import Link from 'next/link' import dynamic from 'next/dynamic' const Snowfall = dynamic(() => import('react-snowfall'), { ssr: false }) import Modal from './modal.js' import tabs from '../data/tabs.json' import constants from '../constants.json' import BB from './b.js' const renderSnow = () => { const date = new Date() // if its december, and date is more than 5 return date.getMonth() === 11 && date.getDate() > 5 } export default function Layout({ children, route, globalData, refetchGlobalData, }) { let href = route const [sidebarOpen, setSidebarOpen] = useState(true) const [windowSize, setWindowSize] = useState([100, 200]) const [showMotdModal, setShowMotdModal] = useState(false) const [showNewMsgModal, setShowNewMsgModal] = useState(true) const userId = globalData.userId const userSpecificMotd = globalData.userSpecificMotd if (href === '/' || href === '') { href = 'index' } const closeSideBar = () => { if (typeof window !== 'undefined') { if (window.innerWidth < constants.mobileWindowWidth) { setSidebarOpen(false) } } } useEffect(() => { closeSideBar() setWindowSize([window.innerWidth, window.innerHeight]) window.addEventListener('resize', () => { setWindowSize([window.innerWidth, window.innerHeight]) setSidebarOpen(window.innerWidth >= 700) }) }, []) const snowflakeCount = (windowSize[0] + windowSize[1]) / 26 return (
{renderSnow() && (
)}
{ setSidebarOpen(!sidebarOpen) }} className="menuicon" >
Frylabs
{sidebarOpen ? ( <>
{ if (!userSpecificMotd) { return } setShowMotdModal(true) if (userSpecificMotd.seen) { return } fetch(constants.apiUrl + 'infos', { method: 'POST', credentials: 'include', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, body: JSON.stringify({ userSpecificMotdSeen: true, }), }) .then((resp) => { return resp.json() }) .then(() => { refetchGlobalData() }) }} style={{ cursor: userSpecificMotd ? 'pointer' : 'default' }} title={ userSpecificMotd && !userSpecificMotd.seen ? "You've got Mail!" : '' } > {userSpecificMotd && !userSpecificMotd.seen ? '📬' : '📭'}
UID: {userId || '...'}
{ fetch(constants.apiUrl + 'logout', { method: 'GET', credentials: 'include', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, }) location.reload() }} > Logout
{showMotdModal ? ( { setShowMotdModal(false) }} >
Üzenet admintól:
) : null} ) : null}
{children}
{userSpecificMotd && !userSpecificMotd.seen && showNewMsgModal ? ( { setShowNewMsgModal(false) }} > Új üzeneted van, kattints 📬-ra bal alul megtekintéséhez! ) : null}
) }