Globally storing some data, other minor fixes

This commit is contained in:
mrfry 2021-01-10 11:15:54 +01:00
parent 820adec2d0
commit 0876761a0f
7 changed files with 111 additions and 61 deletions

View file

@ -17,8 +17,11 @@ const renderSnow = () => {
export default function Layout(props) {
let href = props.route
const [sidebarOpen, setSidebarOpen] = useState(true)
const [userId, setUserId] = useState(null)
const [windowSize, setWindowSize] = useState([100, 200])
const userId = props.globalData.userId
const userSpecificMotd = props.globalData.userSpecificMotd
console.log(userSpecificMotd)
if (href === '/' || href === '') {
href = 'index'
@ -32,20 +35,6 @@ export default function Layout(props) {
}
}
useEffect(() => {
fetch(`${constants.apiUrl}infos`, {
credentials: 'include',
Accept: 'application/json',
'Content-Type': 'application/json',
})
.then((resp) => {
return resp.json()
})
.then((data) => {
setUserId(data.uid)
})
}, [])
useEffect(() => {
closeSideBar()
setWindowSize([window.innerWidth, window.innerHeight])
@ -108,7 +97,23 @@ export default function Layout(props) {
</a>
</Link>
</div>
<div className="userInfo">User #{userId}</div>
<div className="userStatus">
{userSpecificMotd ? (
<div
onClick={() => {
// TODO: modal
alert(userSpecificMotd)
}}
style={{ cursor: 'pointer' }}
title={"You've got Mail!"}
>
📬
</div>
) : (
<div>📭</div>
)}
<div>User #{userId || '...'}</div>
</div>
</>
) : null}
</div>