0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-22 20:29:43 +00:00
Files
homebrewery/client/homebrew/pages/userPage/userPage.jsx
Víctor Losada Hernández 4bf485b2e2 lint client
2026-01-21 16:17:11 +01:00

65 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import React, { useState } from 'react';
import _ from 'lodash';
import ListPage from '../basePages/listPage/listPage.jsx';
import Nav from 'client/homebrew/navbar/nav.jsx';
import Navbar from 'client/homebrew/navbar/navbar.jsx';
import RecentNavItems from 'client/homebrew/navbar/recent.navitem.jsx';
const { both: RecentNavItem } = RecentNavItems;
import Account from 'client/homebrew/navbar/account.navitem.jsx';
import NewBrew from 'client/homebrew/navbar/newbrew.navitem.jsx';
import HelpNavItem from 'client/homebrew/navbar/help.navitem.jsx';
import ErrorNavItem from 'client/homebrew/navbar/error-navitem.jsx';
import VaultNavitem from 'client/homebrew/navbar/vault.navitem.jsx';
const UserPage = (props)=>{
props = {
username : '',
brews : [],
query : '',
...props
};
const [error, setError] = useState(null);
const usernameWithS = props.username + (props.username.endsWith('s') ? `` : `s`);
const groupedBrews = _.groupBy(props.brews, (brew)=>brew.published ? 'published' : 'private');
const brewCollection = [
{
title : `${usernameWithS} published brews`,
class : 'published',
brews : groupedBrews.published || []
},
...(props.username === global.account?.username ? [{
title : `${usernameWithS} unpublished brews`,
class : 'unpublished',
brews : groupedBrews.private || []
}] : [])
];
const clearError = ()=>{
setError(null);
};
const navItems = (
<Navbar>
<Nav.section>
{error && (<ErrorNavItem error={error} clearError={clearError}></ErrorNavItem>)}
<NewBrew />
<HelpNavItem />
<VaultNavitem />
<RecentNavItem />
<Account />
</Nav.section>
</Navbar>
);
return (
<ListPage brewCollection={brewCollection} navItems={navItems} query={props.query} reportError={(err)=>setError(err)} />
);
};
export default UserPage;