1
Fork 0
mirror of https://github.com/Steffo99/todocolors.git synced 2024-11-22 08:14:18 +00:00

Refactor BoardHeader

This commit is contained in:
Steffo 2023-08-04 00:38:59 +02:00
parent cef77aea85
commit a280dbb6fd
Signed by: steffo
GPG key ID: 2A24051445686895
2 changed files with 134 additions and 41 deletions

View file

@ -27,7 +27,7 @@
} }
} }
.boardButtons { .buttonsArea {
width: auto; width: auto;
min-width: unset; min-width: unset;
@ -35,34 +35,24 @@
gap: 4px; gap: 4px;
} }
.boardButtonsLeft { .titleArea {
grid-area: left;
justify-self: start;
}
.boardButtonsRight {
grid-area: right;
justify-self: end;
}
.boardTitle {
grid-area: title; grid-area: title;
height: 80px; height: 80px;
} }
.boardTitle div { .titleDisplay {
padding-top: 0.125em; padding-top: 0.125em;
padding-right: 0.75ex; padding-right: 0.75ex;
padding-left: 0.75ex; padding-left: 0.75ex;
padding-bottom: calc(0.125em + 2px); padding-bottom: calc(0.125em + 2px);
} }
.boardTitle input { .titleInput {
text-align: center; text-align: center;
width: 100%; width: 100%;
} }
.boardButtons button { .buttonsArea button {
display: inline-flex; display: inline-flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
@ -77,3 +67,13 @@
width: 36px; width: 36px;
height: 36px; height: 36px;
} }
.leftButtonsArea {
grid-area: left;
justify-self: start;
}
.rightButtonsArea {
grid-area: right;
justify-self: end;
}

View file

@ -1,3 +1,5 @@
import {useRouter} from "next/navigation"
import {ReactNode, useCallback} from "react"
import style from "./BoardHeader.module.css" import style from "./BoardHeader.module.css"
import {useManagedBoard} from "@/app/board/[board]/BoardManager" import {useManagedBoard} from "@/app/board/[board]/BoardManager"
import {faArrowDownWideShort, faHouse, faPencil, faTableColumns} from "@fortawesome/free-solid-svg-icons" import {faArrowDownWideShort, faHouse, faPencil, faTableColumns} from "@fortawesome/free-solid-svg-icons"
@ -6,35 +8,126 @@ import cn from "classnames"
export function BoardHeader() { export function BoardHeader() {
const {title, isEditingTitle, editTitle, setEditTitle, toggleEditingTitle, nextGrouper, nextSorter, websocketState} = useManagedBoard(); const {isEditingTitle} = useManagedBoard();
const isReady = websocketState === WebSocket.OPEN
return ( return (
<header className={style.boardHeader}> <header className={style.boardHeader}>
<div className={cn(style.boardButtons, style.boardButtonsLeft)}> <TitleArea>
<button title={"Home"}> {isEditingTitle ? <TitleInput/> : <TitleDisplay/>}
<FontAwesomeIcon icon={faHouse}/> </TitleArea>
</button> <LeftButtonsArea>
<button className={cn({fade: !isReady})} disabled={!isReady} title={"Modifica titolo"} onClick={isReady ? toggleEditingTitle : undefined}> <HomeButton/>
<FontAwesomeIcon icon={faPencil}/> <EditTitleButton/>
</button> </LeftButtonsArea>
</div> <RightButtonsArea>
<h1 className={cn({fade: !isReady, [style.boardTitle]: true})}> <CycleGroupButton/>
{isEditingTitle ? <CycleSortButton/>
<input type={"text"} placeholder={"Titolo"} onChange={(e) => setEditTitle(e.target.value)} value={editTitle}/> </RightButtonsArea>
:
<div>{title}</div>
}
</h1>
<div className={cn(style.boardButtons, style.boardButtonsRight)}>
<button title={"Cambia raggruppamento orizzontale"} onClick={nextGrouper}>
<FontAwesomeIcon icon={faTableColumns}/>
</button>
<button title={"Cambia ordinamento verticale"} onClick={nextSorter}>
<FontAwesomeIcon icon={faArrowDownWideShort}/>
</button>
</div>
</header> </header>
) )
} }
function TitleArea({children}: {children: ReactNode}) {
return (
<h1 className={style.titleArea}>
{children}
</h1>
)
}
function TitleInput() {
const {editTitle, setEditTitle} = useManagedBoard()
return (
<input
className={style.titleInput}
type={"text"}
placeholder={"Titolo"}
onChange={(e) => setEditTitle(e.target.value)}
value={editTitle}
/>
)
}
function TitleDisplay() {
const {title} = useManagedBoard()
return (
<div
className={style.titleDisplay}
>
{title}
</div>
)
}
function LeftButtonsArea({children}: {children: ReactNode}) {
return (
<div
className={cn(style.buttonsArea, style.leftButtonsArea)}
>
{children}
</div>
)
}
function HomeButton() {
const router = useRouter()
const goHome = useCallback(() => router.push("/"), [router])
return (
<button title={"Pagina principale"} onClick={goHome}>
<FontAwesomeIcon icon={faHouse}/>
</button>
)
}
function EditTitleButton() {
const {websocketState, toggleEditingTitle} = useManagedBoard()
if(websocketState != WebSocket.OPEN) {
return null;
}
return (
<button title={"Modifica titolo"} onClick={toggleEditingTitle}>
<FontAwesomeIcon icon={faPencil}/>
</button>
)
}
function RightButtonsArea({children}: {children: ReactNode}) {
return (
<div className={cn(style.buttonsArea, style.rightButtonsArea)}>
{children}
</div>
)
}
function CycleGroupButton() {
const {websocketState, nextGrouper} = useManagedBoard()
if(websocketState != WebSocket.OPEN) {
return null;
}
return (
<button title={"Cambia raggruppamento"} onClick={nextGrouper}>
<FontAwesomeIcon icon={faTableColumns}/>
</button>
)
}
function CycleSortButton() {
const {websocketState, nextSorter} = useManagedBoard()
if(websocketState != WebSocket.OPEN) {
return null;
}
return (
<button title={"Cambia ordinamento"} onClick={nextSorter}>
<FontAwesomeIcon icon={faArrowDownWideShort}/>
</button>
)
}