-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
103 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.thumbnail { | ||
.checkbox { | ||
align-self: self-start; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import {useContext, useRef, useEffect, useState} from "react" | ||
import {useDispatch} from "react-redux" | ||
import {Stack, Checkbox} from "@mantine/core" | ||
import PanelContext from "@/contexts/PanelContext" | ||
|
||
import {useProtectedJpg} from "@/hooks/protected_image" | ||
import {setCurrentPage} from "@/slices/dualPanel/dualPanel" | ||
import type {PanelMode, PageType} from "@/types" | ||
|
||
import classes from "./Thumbnail.module.scss" | ||
|
||
const BORDERLINE_TOP = "borderline-top" | ||
const BORDERLINE_BOTTOM = "borderline-bottom" | ||
|
||
type Args = { | ||
page: PageType | ||
} | ||
|
||
export default function Thumbnail({page}: Args) { | ||
const dispatch = useDispatch() | ||
const protectedImage = useProtectedJpg(page.jpg_url) | ||
const mode: PanelMode = useContext(PanelContext) | ||
const ref = useRef<HTMLDivElement>(null) | ||
const [cssClassNames, setCssClassNames] = useState<Array<string>>([]) | ||
|
||
const onClick = () => { | ||
dispatch(setCurrentPage({mode, page: page.number})) | ||
} | ||
|
||
const onLocalDragOver = (event: React.DragEvent<HTMLDivElement>) => { | ||
const y = event.clientY | ||
|
||
event.preventDefault() | ||
|
||
if (ref?.current) { | ||
const rect = ref?.current.getBoundingClientRect() | ||
const half = (rect.bottom - rect.top) / 2 | ||
|
||
if (y >= rect.top && y < rect.top + half) { | ||
// remove borderline_bottom and add borderline_top | ||
const new_array = cssClassNames.filter(i => i != BORDERLINE_BOTTOM) | ||
|
||
if (new_array.indexOf(BORDERLINE_TOP) < 0) { | ||
setCssClassNames([...new_array, BORDERLINE_TOP]) | ||
} | ||
} else if (y >= rect.top + half && y < rect.bottom) { | ||
// remove borderline_top and add borderline_bottom | ||
const new_array = cssClassNames.filter(i => i != BORDERLINE_TOP) | ||
|
||
if (new_array.indexOf(BORDERLINE_BOTTOM) < 0) { | ||
setCssClassNames([...new_array, BORDERLINE_BOTTOM]) | ||
} | ||
} | ||
} // if (ref?.current) | ||
} // end of onLocalDragOver | ||
|
||
const onLocalDragLeave = () => { | ||
// remove both borderline_bottom and borderline_top | ||
const new_array = cssClassNames.filter( | ||
i => i != BORDERLINE_BOTTOM && i != BORDERLINE_TOP | ||
) | ||
setCssClassNames(new_array) | ||
} | ||
|
||
const onLocalDragEnter = (event: React.DragEvent<HTMLDivElement>) => { | ||
event.preventDefault() | ||
} | ||
|
||
return ( | ||
<Stack | ||
ref={ref} | ||
className={`${classes.thumbnail} ${cssClassNames.join(" ")}`} | ||
align="center" | ||
gap={"xs"} | ||
onClick={onClick} | ||
draggable | ||
onDragOver={onLocalDragOver} | ||
onDragLeave={onLocalDragLeave} | ||
onDragEnter={onLocalDragEnter} | ||
> | ||
<Checkbox className={classes.checkbox} /> | ||
<img src={protectedImage.data || ""} /> | ||
{page.number} | ||
</Stack> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Thumbnail from "./Thumbnail" | ||
|
||
export default Thumbnail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters