Skip to content

Commit

Permalink
Merge pull request #100 from tgxn/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tgxn authored Nov 4, 2023
2 parents d051dd7 + f4dafa9 commit 68c203c
Show file tree
Hide file tree
Showing 22 changed files with 1,243 additions and 722 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.5",
"version": "1.3.7",
"description": "Lemmy Moderation App",
"author": "tgxn",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/components/ApprovalsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ReportIcon from "@mui/icons-material/Report";

import { MomentAdjustedTimeAgo, SquareChip } from "./Display.jsx";

import { PersonMetaLine, ReportDetails } from "./ListItem/Common.jsx";
import { PersonMetaLine } from "./Shared/ActorMeta.jsx";

import { ApproveButton, DenyButton } from "./Actions/RegistrationButtons.jsx";

Expand Down
18 changes: 5 additions & 13 deletions src/components/Content/Image.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { useState, useEffect, useRef } from "react";
import React, { useState } 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" }) {
Expand Down Expand Up @@ -62,19 +61,12 @@ const ContentError = React.memo(function ({ message = false, bgcolor = "#ff55551
);
});

export const Image = React.memo(({ imageSrc, nsfw, onClick }) => {
export const Image = React.memo(({ imageSrc, blurPreview, 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={{
Expand All @@ -97,7 +89,7 @@ export const Image = React.memo(({ imageSrc, nsfw, onClick }) => {
// alt={"Banner"}
//scaling
style={{
filter: nsfw ? "blur(8px)" : null, // TODO this should use user setting
filter: blurPreview ? "blur(8px)" : null, // TODO this should use user setting
// consdytr
objectFit: "contain",
objectPosition: "center center",
Expand All @@ -110,7 +102,7 @@ export const Image = React.memo(({ imageSrc, nsfw, onClick }) => {
);
});

export const Video = React.memo(({ imageSrc, nsfw, onClick }) => {
export const Video = React.memo(({ imageSrc, blurPreview, onClick }) => {
const [open, setOpen] = useState(false);
// const [image, setImage] = useState("false");

Expand Down Expand Up @@ -140,7 +132,7 @@ export const Video = React.memo(({ imageSrc, nsfw, onClick }) => {
// alt={"Banner"}
//scaling
style={{
filter: nsfw ? "blur(8px)" : null, // TODO this should use user setting
filter: blurPreview ? "blur(8px)" : null, // TODO this should use user setting
// consdytr
objectFit: "contain",
objectPosition: "center center",
Expand Down
28 changes: 26 additions & 2 deletions src/components/Content/PostThumb.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { useState, useEffect, useRef } from "react";

import { useDispatch, useSelector } from "react-redux";

import Tooltip from "@mui/joy/Tooltip";
import AspectRatio from "@mui/joy/AspectRatio";
import Typography from "@mui/joy/Typography";
Expand All @@ -13,6 +15,14 @@ import LaunchIcon from "@mui/icons-material/Launch";
import { SanitizedLink } from "../Display.jsx";
import { Image, Video } from "./Image.jsx";

import {
setConfigItem,
setConfigItemJson,
selectBlurNsfw,
selectShowAvatars,
selectNsfwWords,
} from "../../reducers/configReducer";

function ThumbWrapper({ width = 200, tooltip, modal = null, children }) {
return (
<>
Expand All @@ -30,7 +40,7 @@ function ThumbWrapper({ width = 200, tooltip, modal = null, children }) {
);
}

export default function PostThumb({ width = 200, post }) {
export default function PostThumb({ width = 200, post, report }) {
/**
* look for these in `post`
*
Expand All @@ -41,6 +51,13 @@ export default function PostThumb({ width = 200, post }) {
* - embed_description
*/

const reportReason = report.reason.toLowerCase() || null;

console.log("report", reportReason);

const blurNsfw = useSelector(selectBlurNsfw);
const nsfwWords = useSelector(selectNsfwWords);

const { url, thumbnail_url, nsfw, embed_title, embed_description } = post;

const isImage = url.match(/\.(jpeg|jpg|gif|png|webp)$/) != null;
Expand All @@ -52,6 +69,13 @@ export default function PostThumb({ width = 200, post }) {
const handleClose = () => {
setOpen(false);
};

let shouldBlurPreview = false;
if (blurNsfw && nsfw) shouldBlurPreview = true;
if (blurNsfw && nsfwWords.some((word) => reportReason.includes(word))) {
shouldBlurPreview = true;
}

// return image content thumb
if (isImage) {
return (
Expand Down Expand Up @@ -88,7 +112,7 @@ export default function PostThumb({ width = 200, post }) {
>
<Image
imageSrc={url}
nsfw={nsfw}
blurPreview={shouldBlurPreview}
onClick={() => {
setOpen(true);
}}
Expand Down
18 changes: 17 additions & 1 deletion src/components/Display.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import Moment from "react-moment";

import { sanitizeUrl } from "@braintree/sanitize-url";

import Avatar from "@mui/joy/Avatar";
import Typography from "@mui/joy/Typography";
import Tooltip from "@mui/joy/Tooltip";
import Link from "@mui/joy/Link";
import Chip from "@mui/joy/Chip";

Expand Down Expand Up @@ -135,3 +135,19 @@ export const FediverseChipLink = ({ href, size = "md", ...props }) => {
</BasicInfoTooltip>
);
};

export function UserAvatar({ source, ...props }) {
return (
<Avatar
component="span"
size="sm"
src={source}
sx={{
display: "inline-flex",
alignItems: "center",
justifyContent: "center",
}}
{...props}
/>
);
}
160 changes: 160 additions & 0 deletions src/components/Header/AccountMenu.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import React from "react";

import { useDispatch, useSelector } from "react-redux";

import { useQueryClient } from "@tanstack/react-query";

import { Toaster, toast } from "sonner";

import { BrowserRouter as Router, useNavigate, useLocation } from "react-router-dom";

import Typography from "@mui/joy/Typography";
import Chip from "@mui/joy/Chip";
import Sheet from "@mui/joy/Sheet";
import Box from "@mui/joy/Box";
import Divider from "@mui/joy/Divider";
import Switch from "@mui/joy/Switch";
import Menu from "@mui/joy/Menu";
import MenuItem from "@mui/joy/MenuItem";
import IconButton from "@mui/joy/IconButton";
import CircularProgress from "@mui/joy/CircularProgress";

import CachedIcon from "@mui/icons-material/Cached";
import LogoutIcon from "@mui/icons-material/Logout";
import ArrowDropDown from "@mui/icons-material/ArrowDropDown";
import OpenInNewIcon from "@mui/icons-material/OpenInNew";

// user role icons
import VerifiedUserIcon from "@mui/icons-material/VerifiedUser";
import SupervisedUserCircleIcon from "@mui/icons-material/SupervisedUserCircle";
import AccountBoxIcon from "@mui/icons-material/AccountBox";
import DashboardIcon from "@mui/icons-material/Dashboard";
import SwitchAccountIcon from "@mui/icons-material/SwitchAccount";

import GitHubIcon from "@mui/icons-material/GitHub";

import FlagIcon from "@mui/icons-material/Flag";
import HowToRegIcon from "@mui/icons-material/HowToReg";

import { logoutCurrent, selectUsers } from "../../reducers/accountReducer";

import { LemmyHttp } from "lemmy-js-client";

import { useLemmyHttp, refreshAllData } from "../../hooks/useLemmyHttp";
import { getSiteData } from "../../hooks/getSiteData";

import { HeaderChip } from "../Display.jsx";
import { BasicInfoTooltip } from "../Tooltip.jsx";

import { parseActorId } from "../../utils.js";

import { addUser, setAccountIsLoading, setUsers, setCurrentUser } from "../../reducers/accountReducer";

import ConfigModal from "./ConfigModal.jsx";

export default function AccountMenu({ anchorEl, open, onClose }) {
const dispatch = useDispatch();

const queryClient = useQueryClient();

const users = useSelector(selectUsers);

const { mutate: refreshMutate } = refreshAllData();

const [isLoading, setIsLoading] = React.useState(false);

const { baseUrl, siteData, localPerson, userRole } = getSiteData();

let userTooltip = "user";
let userIcon = <AccountBoxIcon />;
if (userRole == "admin") {
userTooltip = "admin";
userIcon = <VerifiedUserIcon />;
}
if (userRole == "mod") {
userTooltip = "mod";
userIcon = <SupervisedUserCircleIcon />;
}

const parsedActor = parseActorId(localPerson.actor_id);

return (
<Menu id="user-menu" anchorEl={anchorEl} open={open} onClose={onClose} placement="bottom-end">
{users && users.length > 0 && (
<>
{users.map((user, index) => {
return (
<MenuItem
key={index}
sx={{
color: "text.body",
}}
disabled={user.site.my_user?.local_user_view?.person.actor_id == localPerson.actor_id}
onClick={async () => {
onClose();

queryClient.invalidateQueries({ queryKey: ["lemmyHttp", localPerson.id] });
dispatch(logoutCurrent());

setIsLoading(true);

dispatch(setAccountIsLoading(true));

try {
const lemmyClient = new LemmyHttp(`https://${user.base}`);

const getSite = await lemmyClient.getSite({
auth: user.jwt,
});

if (!getSite.my_user) {
// set instance base to the current instance
// setInstanceBase(user.base);
// setUsername(user.site.my_user.local_user_view?.person.name);

throw new Error("jwt does not provide auth, re-authenticate");
}

// if (saveSession) {
// dispatch(addUser(user.base, auth.jwt, getSite));
// } else {
// dispatch(setCurrentUser(user.base, auth.jwt, getSite));
dispatch(setCurrentUser(user.base, user.jwt, getSite));
// }
} catch (e) {
toast(typeof e == "string" ? e : e.message);
} finally {
// setIsLoading(false);

dispatch(setAccountIsLoading(false));
}
}}
>
{user.site.my_user?.local_user_view?.person.actor_id == localPerson.actor_id ? (
<SwitchAccountIcon sx={{ mr: 1 }} />
) : (
<SwitchAccountIcon sx={{ mr: 1 }} />
)}
{user.site.my_user?.local_user_view?.person.name}@{user.base}
</MenuItem>
);
})}
</>
)}
{/*
<MenuItem
sx={{
color: "text.body",
}}
onClick={() => {
handleClose();
queryClient.invalidateQueries({ queryKey: ["lemmyHttp"] });
dispatch(logoutCurrent());
}}
>
End Session
</MenuItem> */}
</Menu>
);
}
Loading

0 comments on commit 68c203c

Please sign in to comment.