Skip to content

Commit

Permalink
css styling (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur authored Aug 8, 2024
1 parent 4145264 commit 076f507
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 25 deletions.
10 changes: 6 additions & 4 deletions ui2/src/app/App.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#root {
margin: 0 auto;
padding: 2rem;
text-align: center;
overflow: hidden;
margin: 0;
padding: 0;
}

main {
margin: 1rem;
}
3 changes: 1 addition & 2 deletions ui2/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ function App() {
width: navBarWidth,
breakpoint: 0
}}
padding="md"
>
<AppShell.Header>
<Header />
Expand All @@ -51,7 +50,7 @@ function App() {
<NavBar />
</AppShell.Navbar>

<AppShell.Main>
<AppShell.Main className="outlet">
<Outlet />
<Uploader />
</AppShell.Main>
Expand Down
7 changes: 4 additions & 3 deletions ui2/src/components/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import {equalUUIDs} from "@/utils"

type Args = {
onClick: (node: NType) => void
className?: string
}

export default function BreadcrumbsComponent({onClick}: Args) {
export default function BreadcrumbsComponent({onClick, className}: Args) {
const mode: PanelMode = useContext(PanelContext)
const nodesStatus = useSelector((state: RootState) =>
selectPanelNodesStatus(state, mode)
Expand Down Expand Up @@ -59,7 +60,7 @@ export default function BreadcrumbsComponent({onClick}: Args) {

if (items.length == 1) {
return (
<Group my={"lg"}>
<Group my={"lg"} className={className}>
<Breadcrumbs className={classes.breadcrumbs}>
<RootItem itemId={items[0][0]} onClick={onRootElementClick} />
</Breadcrumbs>
Expand All @@ -69,7 +70,7 @@ export default function BreadcrumbsComponent({onClick}: Args) {
}

return (
<Group my={"lg"}>
<Group my={"lg"} className={className}>
<Breadcrumbs className={classes.breadcrumbs}>
<RootItem itemId={items[0][0]} onClick={onRootElementClick} />
{links}
Expand Down
25 changes: 15 additions & 10 deletions ui2/src/components/Commander/Commander.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useContext} from "react"
import {Group} from "@mantine/core"
import {Group, Stack} from "@mantine/core"

import {useSelector, useDispatch} from "react-redux"
import {useNavigate} from "react-router-dom"
Expand All @@ -23,11 +23,14 @@ import type {NType, NodeType, PanelMode} from "@/types"
import Breadcrumbs from "@/components/Breadcrumbs"
import Pagination from "@/components/Pagination"
import PanelContext from "@/contexts/PanelContext"
import {useContentHeight} from "@/hooks/useContentHeight"

export default function Commander() {
const mode: PanelMode = useContext(PanelContext)
const height = useContentHeight(mode)
const dispatch = useDispatch()
const navigate = useNavigate()

const {data, status, error} = useSelector((state: RootState) =>
selectPanelNodes(state, mode)
)
Expand Down Expand Up @@ -130,22 +133,24 @@ export default function Commander() {
return (
<div>
<FolderNodeActions />
<Breadcrumbs onClick={onClick} />
<Group>{nodes}</Group>
<Pagination
pagination={pagination}
onPageNumberChange={onPageNumberChange}
onPageSizeChange={onPageSizeChange}
lastPageSize={lastPageSize}
/>
<Breadcrumbs className={`${mode}-breadcrumb`} onClick={onClick} />
<Stack justify={"space-between"} style={{height: `${height}px`}}>
<Group>{nodes}</Group>
<Pagination
pagination={pagination}
onPageNumberChange={onPageNumberChange}
onPageSizeChange={onPageSizeChange}
lastPageSize={lastPageSize}
/>
</Stack>
</div>
)
}

return (
<div>
<FolderNodeActions />
<Breadcrumbs onClick={onClick} />
<Breadcrumbs className={`${mode}-breadcrumb`} onClick={onClick} />
<Group>Empty</Group>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function FolderNodeActions() {
) as Array<string>

return (
<Group justify="space-between">
<Group className={`${mode}-action-panel`} justify="space-between">
<Group>
{selectedIds.length == 0 && <UploadButton />}
{selectedIds.length == 0 && <NewFolderButton />}
Expand Down
1 change: 1 addition & 0 deletions ui2/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function Header() {

return (
<header
className="top-header"
style={{
backgroundColor: theme.colors.pmg[9],
color: theme.colors.pmg[0]
Expand Down
8 changes: 7 additions & 1 deletion ui2/src/components/Viewer/ActionButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import {useContext} from "react"
import {Group} from "@mantine/core"
import ToggleSecondaryPanel from "@/components/DualPanel/ToggleSecondaryPanel"
import PanelContext from "@/contexts/PanelContext"
import EditTitleButton from "./EditTitleButton"

import type {PanelMode} from "@/types"

export default function ActionButtons() {
const mode: PanelMode = useContext(PanelContext)

return (
<Group justify="space-between">
<Group className={`${mode}-action-panel`} justify="space-between">
<Group>
<EditTitleButton />
</Group>
Expand Down
2 changes: 1 addition & 1 deletion ui2/src/components/Viewer/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function Page({page}: Args) {
useEffect(() => {
if (currentPage == page.number) {
if (targetRef.current) {
targetRef.current.scrollIntoView()
//targetRef.current.scrollIntoView()
}
}
}, [page.number, protectedImage.data])
Expand Down
2 changes: 1 addition & 1 deletion ui2/src/components/Viewer/Thumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function Thumbnail({page}: Args) {
useEffect(() => {
if (currentPage == page.number) {
if (targetRef.current) {
targetRef.current.scrollIntoView()
// targetRef.current.scrollIntoView()
}
}
}, [page.number, protectedImage.data])
Expand Down
6 changes: 4 additions & 2 deletions ui2/src/components/Viewer/Viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import type {RootState} from "@/app/types"
import type {PanelMode, NType} from "@/types"
import Breadcrumbs from "@/components/Breadcrumbs"
import PanelContext from "@/contexts/PanelContext"
import {useContentHeight} from "@/hooks/useContentHeight"
import ActionButtons from "./ActionButtons"
import Pages from "./Pages"
import Thumbnails from "./Thumbnails"

export default function Viewer() {
const mode: PanelMode = useContext(PanelContext)
const height = useContentHeight(mode)
const navigate = useNavigate()
const dispatch = useDispatch()
const lastPageSize = useSelector((state: RootState) =>
Expand Down Expand Up @@ -47,8 +49,8 @@ export default function Viewer() {
return (
<div>
<ActionButtons />
<Breadcrumbs onClick={onClick} />
<Flex style={{height: "740px"}}>
<Breadcrumbs className={`${mode}-breadcrumb`} onClick={onClick} />
<Flex style={{height: `${height}px`}}>
<Thumbnails />
<Pages />
</Flex>
Expand Down
147 changes: 147 additions & 0 deletions ui2/src/hooks/useContentHeight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import {useState, useEffect} from "react"
import {PanelMode} from "@/types"

const SMALL_BOTTOM_MARGIN = 3 /* pixles */

export const useContentHeight = (mode: PanelMode) => {
/**
* Calculate the height of the viewer/commander content
* using following formula. Content is everything in viewer
* commander but "action panel and breadcrumb":
*
* Content Height = W - B - H - O - S
*
* W = window height (same as viewport?)
* B = breadcrumb height (includes margins and padding)
* H = header height (includes margin and padding)
* O = outlet top margin plus top padding
* S = small adjustment value just to leave couple of pixels
* as bottom margin - it is just looks better.
* This value is subjective. When set to 0 it, the
* Content Height will perfectly alight with window's
* bottom.
*/
//The initial value is empty
const [height, setHeight] = useState(getHeight(mode))

useEffect(() => {
const resizeListener = () => {
// change width from the state object
setHeight(getHeight(mode))
}
// set resize listener
window.addEventListener("resize", resizeListener)

// clean up function
return () => {
// remove resize listener
window.removeEventListener("resize", resizeListener)
}
}, [])

return height
}

type ComputedHeightArgs = {
element_id?: string
element_class?: string
default_value: number
}

function getComputedHeight({
element_id,
element_class,
default_value
}: ComputedHeightArgs): number {
let el, styles, height

if (element_id) {
el = document.getElementById(element_id)
} else if (element_class) {
el = document.getElementsByClassName(element_class)[0]
}

if (!el) {
if (element_id) {
console.info(`Element with ID ${element_id} not found`)
}
if (element_class) {
console.info(`Element with class name ${element_class} not found`)
}
return default_value // blunt guess of element height
}

styles = window.getComputedStyle(el)

height = parseInt(styles.height)
height += parseInt(styles.marginTop)
height += parseInt(styles.marginBottom)

return height
}

function getOutletTopMarginAndPadding(): number {
/**
* main.outlet is the DOM element which holds the react router
* DOM outlet:
* https://reactrouter.com/en/main/components/outlet
* The outlet element is wrapped around
* <AppShell.Main className="outlet" />
*
* Important point is viewer's (or commander's)
* "action panel" and "breadcrumb" are pushed down by outlet's top
* margin and padding. Outlet itself is being aligned with top
* viewport.
*/
let value
const el = document.getElementsByClassName("outlet")[0]

if (!el) {
console.log("Outlet not found")
return 0
}

const styles = window.getComputedStyle(el)

value = parseInt(styles.marginTop)
value += parseInt(styles.paddingTop)

return value
}

function getBreadcrumbHeight(mode: PanelMode): number {
let result = getComputedHeight({
element_class: `${mode}-breadcrumb`,
default_value: 40
})

return result
}

function getActionPanelHeight(mode: PanelMode): number {
let result = getComputedHeight({
element_class: `${mode}-action-panel`,
default_value: 100
})

return result
}

function getHeight(mode: PanelMode): number {
/*
Returns height of viewer/commander's content.
The "viewer/commander" content is all what remains
in viewport after breadcrumb, action panel and area
ABOVE it is substracted.
*/
let height: number = window.innerHeight

height -= getOutletTopMarginAndPadding()
height -= getBreadcrumbHeight(mode)
height -= getActionPanelHeight(mode)

/* Let there be a small margin at the bottom of the viewport */
height -= SMALL_BOTTOM_MARGIN

return height
}

0 comments on commit 076f507

Please sign in to comment.