Skip to content

Commit

Permalink
more render content
Browse files Browse the repository at this point in the history
  • Loading branch information
tgxn committed Nov 1, 2023
1 parent f0c1883 commit 5e85826
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lemmy-modder",
"version": "1.3.3",
"version": "1.3.4",
"description": "Lemmy Moderation App",
"author": "tgxn",
"license": "MIT",
Expand Down
43 changes: 43 additions & 0 deletions src/components/Content/Image.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,46 @@ export const Image = React.memo(({ imageSrc, nsfw, onClick }) => {
</Box>
);
});

export const Video = React.memo(({ imageSrc, nsfw, onClick }) => {
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 Content"} bgcolor={"#ff55fc21"} />}
{imageSrc && (
<React.Fragment>
{/* {isLoading && <ContentSkeleton />} */}
{/* {error && <ContentError />} */}
<video
src={imageSrc}
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>
);
});
64 changes: 51 additions & 13 deletions src/components/Content/PostThumb.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CircularProgress from "@mui/joy/CircularProgress";
import LaunchIcon from "@mui/icons-material/Launch";

import { SanitizedLink } from "../Display.jsx";
import { Image } from "./Image.jsx";
import { Image, Video } from "./Image.jsx";

function ThumbWrapper({ width = 200, tooltip, modal = null, children }) {
return (
Expand Down Expand Up @@ -43,8 +43,8 @@ export default function PostThumb({ width = 200, post }) {

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 isImage = url.match(/\.(jpeg|jpg|gif|png|webp)$/) != null;
const isVideo = url.match(/\.(mp4|vppppp)$/) != null;

const [open, setOpen] = useState(false);
// const [image, setImage] = useState("false");
Expand All @@ -56,30 +56,26 @@ export default function PostThumb({ width = 200, post }) {
if (isImage) {
return (
<ThumbWrapper
tooltip={url}
// 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={{
display: "flex",
alignItems: "center",
justifyContent: "center",
outline: "none",
width: "100%",
height: "90%",
}}
// TODO should clicking the popup open new tab?
// onClick={() => window.open(url, "_new")}
Expand All @@ -100,6 +96,48 @@ export default function PostThumb({ width = 200, post }) {
</ThumbWrapper>
);
}
if (isVideo) {
return (
<ThumbWrapper
tooltip={url}
modal={
<Modal
sx={{
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
open={open}
onClose={handleClose}
>
<Box
sx={{
display: "flex",
alignItems: "center",
justifyContent: "center",
outline: "none",
width: "100%",
height: "90%",
}}
// TODO should clicking the popup open new tab?
// onClick={() => window.open(url, "_new")}
onClick={() => setOpen(false)}
>
<video autoplay="false" src={url} style={{ maxHeight: "90%", maxWidth: "90%" }} controls />
</Box>
</Modal>
}
>
<Video
imageSrc={url}
nsfw={nsfw}
onClick={() => {
setOpen(true);
}}
/>
</ThumbWrapper>
);
}

// return unknown content thumbnail
return (
Expand Down

0 comments on commit 5e85826

Please sign in to comment.