improve header behavior & fix missing children renders

This commit is contained in:
SrGooglo 2023-08-17 19:07:51 +00:00
parent 5deec49e64
commit 1eed6f7126
8 changed files with 136 additions and 95 deletions

View File

@ -19,7 +19,7 @@ export default (props) => {
component, component,
options options
}) })
} },
}) })
return <Motion return <Motion

View File

@ -1,4 +1,9 @@
.page_header_wrapper { .page_header_wrapper {
display: flex;
flex-direction: column;
gap: 10px;
position: sticky; position: sticky;
z-index: 100; z-index: 100;

View File

@ -4,7 +4,6 @@ import * as antd from "antd"
import "./index.less" import "./index.less"
export default (props) => { export default (props) => {
function handleClickItem(item) { function handleClickItem(item) {
if (item.children && Array.isArray(item.children)) { if (item.children && Array.isArray(item.children)) {
@ -14,7 +13,8 @@ export default (props) => {
return props.onClickItem(item.key) return props.onClickItem(item.key)
} }
return <div return <>
<div
className={classnames( className={classnames(
"navmenu_wrapper", "navmenu_wrapper",
)} )}
@ -61,8 +61,14 @@ export default (props) => {
"navmenu_item", "navmenu_item",
item.key === props.activeKey && "active", item.key === props.activeKey && "active",
)} )}
onClick={() => handleClickItem(item)} onClick={() => {
type="ghost" if (typeof item.props.onClick === "function") {
return item.props.onClick()
}
return handleClickItem(item)
}}
type={item.props.type ?? "ghost"}
disabled={item.disabled} disabled={item.disabled}
> >
<div className="icon"> <div className="icon">
@ -80,4 +86,9 @@ export default (props) => {
}) })
} }
</div> </div>
{
props.children
}
</>
} }

View File

@ -1,5 +1,22 @@
@import "theme/vars.less"; @import "theme/vars.less";
html {
&.mobile {
.navmenu_wrapper {
.navmenu_item {
&.active {
color: var(--colorPrimary) !important;
background-color: var(--background-color-primary);
}
.icon {
font-size: 1.5rem;
}
}
}
}
}
.navmenu_wrapper { .navmenu_wrapper {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
@ -8,8 +25,13 @@
width: 100%; width: 100%;
.ant-btn-primary:not(.ant-btn-dangerous) {
.label {
color: var(--background-color-primary);
}
}
.navmenu_item { .navmenu_item {
font-size: 0.7rem;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
@ -23,17 +45,21 @@
&.active { &.active {
color: var(--colorPrimary); color: var(--colorPrimary);
background-color: var(--background-color-primary);
} }
p { p {
margin: 0; margin: 0;
color: var(--text-color);
}
svg {
color: currentColor;
} }
.icon { .icon {
margin: 0; margin: 0;
line-height: 1rem; line-height: 1rem;
font-size: 1.5rem;
font-size: 1rem; font-size: 1rem;
} }

View File

@ -61,17 +61,16 @@ export class PagePanelWithNavMenu extends React.Component {
app.layout.page_panels = this.interface app.layout.page_panels = this.interface
if (app.isMobile) { if (app.isMobile) {
app.layout.top_bar.shouldUseTopBarSpacer(false) app.layout.top_bar.shouldUseTopBarSpacer(true)
app.layout.toggleCenteredContent(false)
} }
app.layout.toggleCenteredContent(true)
} }
componentWillUnmount() { componentWillUnmount() {
delete app.layout.page_panels delete app.layout.page_panels
if (app.isMobile) { if (app.isMobile) {
app.layout.top_bar.shouldUseTopBarSpacer(true) app.layout.top_bar.shouldUseTopBarSpacer(false)
} else { } else {
app.layout.header.render(null) app.layout.header.render(null)
} }
@ -179,15 +178,18 @@ export class PagePanelWithNavMenu extends React.Component {
return [] return []
} }
return items.map((item) => { items = items.map((item) => {
return { return {
key: item.key, key: item.key,
icon: createIconRender(item.icon), icon: createIconRender(item.icon),
label: item.label, label: item.label,
children: item.children && this.getItems(item.children), children: item.children && this.getItems(item.children),
disabled: item.disabled, disabled: item.disabled,
props: item.props ?? {},
} }
}) })
return items
} }
render() { render() {
@ -204,7 +206,7 @@ export class PagePanelWithNavMenu extends React.Component {
!app.isMobile && app.layout.header.render(<NavMenu !app.isMobile && app.layout.header.render(<NavMenu
header={this.props.navMenuHeader} header={this.props.navMenuHeader}
activeKey={this.state.activeTab} activeKey={this.state.activeTab}
items={this.getItems(this.props.tabs)} items={this.getItems([...this.props.tabs ?? [], ...this.props.extraItems ?? []])}
onClickItem={(key) => this.handleTabChange(key)} onClickItem={(key) => this.handleTabChange(key)}
renderNames renderNames
> >
@ -221,9 +223,13 @@ export class PagePanelWithNavMenu extends React.Component {
</NavMenu>) </NavMenu>)
} }
<div className="pagePanels">
<div className="panel">
{ {
this.renderActiveTab() this.renderActiveTab()
} }
</div>
</div>
</> </>
} }
} }

View File

@ -1,33 +1,25 @@
import React from "react" import React from "react"
import * as antd from "antd"
import { Translation } from "react-i18next" import { Translation } from "react-i18next"
import { PagePanelWithNavMenu } from "components/PagePanels" import { PagePanelWithNavMenu } from "components/PagePanels"
import { Icons } from "components/Icons"
import Tabs from "./home/tabs" import Tabs from "./home/tabs"
export default class Home extends React.Component { export default class Home extends React.Component {
render() { render() {
const navMenuHeader = <>
<h1>
<Icons.Home />
<Translation>{(t) => t("Timeline")}</Translation>
</h1>
<antd.Button
type="primary"
onClick={app.controls.openPostCreator}
>
<Icons.PlusCircle />
<Translation>{(t) => t("Create")}</Translation>
</antd.Button>
</>
return <PagePanelWithNavMenu return <PagePanelWithNavMenu
tabs={Tabs} tabs={Tabs}
navMenuHeader={navMenuHeader} extraItems={[
primaryPanelClassName="full" {
key: "create",
icon: "PlusCircle",
label: <Translation>{(t) => t("Create")}</Translation>,
props: {
type: "primary",
onClick: app.controls.openPostCreator
}
},
]}
onTabChange={() => { onTabChange={() => {
app.layout.scrollTo({ app.layout.scrollTo({
top: 0, top: 0,

View File

@ -24,6 +24,8 @@ export default (props) => {
React.useEffect(() => { React.useEffect(() => {
loadData() loadData()
app.layout.toggleCenteredContent(false)
}, []) }, [])
if (!playlist) { if (!playlist) {

View File

@ -88,7 +88,6 @@ const generateMenuItems = () => {
}) })
} }
export default () => { export default () => {
const [activeKey, setActiveKey] = useUrlQueryActiveKey({ const [activeKey, setActiveKey] = useUrlQueryActiveKey({
defaultKey: "general", defaultKey: "general",