-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from tgxn/develop
Develop
- Loading branch information
Showing
12 changed files
with
291 additions
and
90 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,111 @@ | ||
import React, { useState, useEffect, useRef } from "react"; | ||
|
||
import { useImage } from "react-image"; | ||
|
||
import Box from "@mui/joy/Box"; | ||
import Modal from "@mui/joy/Modal"; | ||
import CircularProgress from "@mui/joy/CircularProgress"; | ||
|
||
const ContentSkeleton = React.memo(function ({ radius = "4px" }) { | ||
return ( | ||
<Box | ||
sx={(theme) => ({ | ||
...theme.typography.body2, | ||
color: theme.palette.text.secondary, | ||
|
||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
|
||
height: "100%", | ||
textAlign: "center", | ||
})} | ||
> | ||
<CircularProgress | ||
variant={"soft"} | ||
color="neutral" | ||
sx={{ | ||
marginBottom: "5px", | ||
}} | ||
/> | ||
</Box> | ||
); | ||
}); | ||
|
||
const ContentError = React.memo(function ({ message = false, bgcolor = "#ff55551c" }) { | ||
return ( | ||
<Box | ||
component="div" | ||
sx={(theme) => ({ | ||
...theme.typography.body2, | ||
|
||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
|
||
background: bgcolor, | ||
// color: "white", | ||
|
||
// flexGrow: 1, | ||
|
||
height: "100%", | ||
textAlign: "center", | ||
})} | ||
> | ||
<> | ||
😭 | ||
<br /> {message ? message : "Content Error"} | ||
</> | ||
</Box> | ||
); | ||
}); | ||
|
||
export const Image = React.memo(({ imageSrc, nsfw, onClick }) => { | ||
const { src, isLoading, error } = useImage({ | ||
srcList: imageSrc, | ||
useSuspense: false, | ||
}); | ||
|
||
const [open, setOpen] = useState(false); | ||
// const [image, setImage] = useState("false"); | ||
|
||
const handleClose = () => { | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
height: "200px", | ||
width: "200px", | ||
cursor: "pointer", | ||
}} | ||
onClick={onClick} | ||
> | ||
{!imageSrc && <ContentError message={"No Banner"} bgcolor={"#ff55fc21"} />} | ||
{imageSrc && ( | ||
<React.Fragment> | ||
{isLoading && <ContentSkeleton />} | ||
{error && <ContentError />} | ||
<img | ||
src={src} | ||
loading="lazy" | ||
width={"100%"} | ||
height={"100%"} | ||
// alt={"Banner"} | ||
//scaling | ||
style={{ | ||
filter: nsfw ? "blur(8px)" : null, // TODO this should use user setting | ||
// consdytr | ||
objectFit: "contain", | ||
objectPosition: "center center", | ||
// aligh | ||
}} | ||
/> | ||
</React.Fragment> | ||
)} | ||
</Box> | ||
); | ||
}); |
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,114 @@ | ||
import React, { useState, useEffect, useRef } from "react"; | ||
|
||
import Tooltip from "@mui/joy/Tooltip"; | ||
import AspectRatio from "@mui/joy/AspectRatio"; | ||
import Typography from "@mui/joy/Typography"; | ||
|
||
import Box from "@mui/joy/Box"; | ||
import Modal from "@mui/joy/Modal"; | ||
import CircularProgress from "@mui/joy/CircularProgress"; | ||
|
||
import LaunchIcon from "@mui/icons-material/Launch"; | ||
|
||
import { SanitizedLink } from "../Display.jsx"; | ||
import { Image } from "./Image.jsx"; | ||
|
||
function ThumbWrapper({ width = 200, tooltip, modal = null, children }) { | ||
return ( | ||
<> | ||
<Tooltip disableInteractive arrow title={tooltip} placement="top" variant="outlined"> | ||
<AspectRatio | ||
// objectFit="contain" | ||
sx={{ width: width, cursor: "hand", ml: 2 }} | ||
ratio="1/1" | ||
> | ||
{children} | ||
</AspectRatio> | ||
</Tooltip> | ||
{modal} | ||
</> | ||
); | ||
} | ||
|
||
export default function PostThumb({ width = 200, post }) { | ||
/** | ||
* look for these in `post` | ||
* | ||
* - url | ||
* - thumbnail_url | ||
* - nsfw | ||
* - embed_title | ||
* - embed_description | ||
*/ | ||
|
||
const { url, thumbnail_url, nsfw, embed_title, embed_description } = post; | ||
|
||
const isImage = url.match(/\.(jpeg|jpg|gif|png)$/) != null; | ||
const isPlayableMedia = url.match(/\.(mp4|vp9)$/) != null; | ||
|
||
const [open, setOpen] = useState(false); | ||
// const [image, setImage] = useState("false"); | ||
|
||
const handleClose = () => { | ||
setOpen(false); | ||
}; | ||
// return image content thumb | ||
if (isImage) { | ||
return ( | ||
<ThumbWrapper | ||
// tooltip="Expand Image" | ||
modal={ | ||
<Modal | ||
sx={{ | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
// "&:hover": { | ||
// backgroundcolor: "red", | ||
// }, | ||
}} | ||
open={open} | ||
onClose={handleClose} | ||
// hideBackdrop | ||
// closeAfterTransition | ||
// BackdropComponent={Backdrop} | ||
// BackdropProps={{ | ||
// timeout: 500, | ||
// }} | ||
// disablePortal | ||
> | ||
<Box | ||
sx={{ | ||
outline: "none", | ||
}} | ||
// TODO should clicking the popup open new tab? | ||
// onClick={() => window.open(url, "_new")} | ||
onClick={() => setOpen(false)} | ||
> | ||
<img src={url} style={{ maxHeight: "90%", maxWidth: "90%" }} /> | ||
</Box> | ||
</Modal> | ||
} | ||
> | ||
<Image | ||
imageSrc={url} | ||
nsfw={nsfw} | ||
onClick={() => { | ||
setOpen(true); | ||
}} | ||
/> | ||
</ThumbWrapper> | ||
); | ||
} | ||
|
||
// return unknown content thumbnail | ||
return ( | ||
<ThumbWrapper tooltip={url}> | ||
<SanitizedLink underline={"none"} href={url} target="_new"> | ||
<Typography component="div" sx={{ fontSize: "25px" }}> | ||
<LaunchIcon color="neutral" /> | ||
</Typography> | ||
</SanitizedLink> | ||
</ThumbWrapper> | ||
); | ||
} |
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
Oops, something went wrong.