Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #58

Merged
merged 6 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/Actions/BaseElements.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import WarningRoundedIcon from "@mui/icons-material/WarningRounded";

import useLemmyReports from "../../hooks/useLemmyReports";

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

export const BaseActionButton = ({
// icon = null,
size = "small",
Expand All @@ -30,7 +32,7 @@ export const BaseActionButton = ({
// const { isFetching } = useLemmyReports();

return (
<Tooltip title={tooltip} color={color} variant="plain" placement="top">
<BasicInfoTooltip title={tooltip} color={color} variant="plain" placement="top" arrow disableInteractive>
<Button
variant={variant}
color={color}
Expand All @@ -47,7 +49,7 @@ export const BaseActionButton = ({
>
{text}
</Button>
</Tooltip>
</BasicInfoTooltip>
);
};

Expand Down
34 changes: 32 additions & 2 deletions src/components/Actions/CommentButtons.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
import { useSelector } from "react-redux";

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

Expand All @@ -13,10 +14,14 @@ import {
ExpiryLengthElement,
ConfirmDialog,
} from "./BaseElements.jsx";
import { getSiteData } from "../../hooks/getSiteData";

export const ResolveCommentReportButton = ({ report, ...props }) => {
const queryClient = useQueryClient();

const showResolved = useSelector((state) => state.configReducer.showResolved);
const { baseUrl, siteData, localPerson, userRole } = getSiteData();

const { data, callAction, isSuccess, isLoading, error } = useLemmyHttpAction("resolveCommentReport");

const [isConfirming, setIsConfirming] = React.useState(false);
Expand All @@ -38,8 +43,33 @@ export const ResolveCommentReportButton = ({ report, ...props }) => {
if (isSuccess) {
console.log("useLemmyHttpAction", "onSuccess", data);

queryClient.invalidateQueries({ queryKey: ["lemmyHttp"] });

if (showResolved) {
queryClient.invalidateQueries({ queryKey: ["lemmyHttp"] });
} else {
queryClient.setQueryData(
["lemmyHttp", localPerson.id, "listCommentReports", ["unresolved_only", true]],
(old) => {
// remove it from the array
const newPages = !old
? null
: old.pages.map((page) => {
const newData = page.data.filter((oldReport) => {
return oldReport.comment_report.id !== report.comment_report.id;
});

return {
...page,
data: newData,
};
});

return {
...old,
pages: newPages,
};
},
);
}
setIsConfirming(false);
}
}, [data]);
Expand Down
38 changes: 35 additions & 3 deletions src/components/Actions/PMButtons.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
import { useSelector } from "react-redux";

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

Expand All @@ -13,12 +14,16 @@ import {
ExpiryLengthElement,
ConfirmDialog,
} from "./BaseElements.jsx";
import { getSiteData } from "../../hooks/getSiteData";

// allow resolving / unresolving a post report
// resolvePrivateMessageReport
export const ResolvePMReportButton = ({ report, ...props }) => {
const queryClient = useQueryClient();

const showResolved = useSelector((state) => state.configReducer.showResolved);
const { baseUrl, siteData, localPerson, userRole } = getSiteData();

const { data, callAction, isSuccess, isLoading, error } = useLemmyHttpAction("resolvePrivateMessageReport");

const [isConfirming, setIsConfirming] = React.useState(false);
Expand All @@ -27,7 +32,9 @@ export const ResolvePMReportButton = ({ report, ...props }) => {
React.useEffect(() => {
if (isConfirming) {
const timeout = setTimeout(() => {
setIsConfirming(false);
if (!isLoading) {
setIsConfirming(false);
}
}, 5000);

return () => {
Expand All @@ -40,8 +47,33 @@ export const ResolvePMReportButton = ({ report, ...props }) => {
if (isSuccess) {
console.log("useLemmyHttpAction", "onSuccess", data);

queryClient.invalidateQueries({ queryKey: ["lemmyHttp"] });

if (showResolved) {
queryClient.invalidateQueries({ queryKey: ["lemmyHttp"] });
} else {
queryClient.setQueryData(
["lemmyHttp", localPerson.id, "listPrivateMessageReports", ["unresolved_only", true]],
(old) => {
// remove it from the array
const newPages = !old
? null
: old.pages.map((page) => {
const newData = page.data.filter((oldReport) => {
return oldReport.pm_report.id !== report.pm_report.id;
});

return {
...page,
data: newData,
};
});

return {
...old,
pages: newPages,
};
},
);
}
setIsConfirming(false);
}
}, [data]);
Expand Down
40 changes: 34 additions & 6 deletions src/components/Actions/PostButtons.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
import { useSelector } from "react-redux";

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

Expand All @@ -13,20 +14,22 @@ import {
ExpiryLengthElement,
ConfirmDialog,
} from "./BaseElements.jsx";
import { getSiteData } from "../../hooks/getSiteData";

// allow resolving / unresolving a post report
export const ResolvePostReportButton = ({ report, ...props }) => {
// const [confirmOpen, setConfirmOpen] = React.useState(false);

const queryClient = useQueryClient();

const showResolved = useSelector((state) => state.configReducer.showResolved);
const { baseUrl, siteData, localPerson, userRole } = getSiteData();

const { data, callAction, isSuccess, isLoading, error } = useLemmyHttpAction("resolvePostReport");

const [isConfirming, setIsConfirming] = React.useState(false);

// close confirm after 5 seconds of no activity
React.useEffect(() => {
if (isConfirming) {
if (isConfirming && !isLoading) {
const timeout = setTimeout(() => {
setIsConfirming(false);
}, 5000);
Expand All @@ -35,14 +38,39 @@ export const ResolvePostReportButton = ({ report, ...props }) => {
clearTimeout(timeout);
};
}
}, [isConfirming]);
}, [isConfirming, isLoading]);

React.useEffect(() => {
if (isSuccess) {
console.log("useLemmyHttpAction", "onSuccess", data);

queryClient.invalidateQueries({ queryKey: ["lemmyHttp"] });

if (showResolved) {
queryClient.invalidateQueries({ queryKey: ["lemmyHttp"] });
} else {
queryClient.setQueryData(
["lemmyHttp", localPerson.id, "listPostReports", ["unresolved_only", true]],
(old) => {
// remove it from the array
const newPages = !old
? null
: old.pages.map((page) => {
const newData = page.data.filter((oldReport) => {
return oldReport.post_report.id !== report.post_report.id;
});

return {
...page,
data: newData,
};
});

return {
...old,
pages: newPages,
};
},
);
}
setIsConfirming(false);
}
}, [data]);
Expand Down
42 changes: 35 additions & 7 deletions src/components/Display.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ import Moment from "react-moment";

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

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

import ThumbsUpDownIcon from "@mui/icons-material/ThumbsUpDown";
import ThumbDownIcon from "@mui/icons-material/ThumbDown";
import ThumbUpIcon from "@mui/icons-material/ThumbUp";

import FediVerse from "../../public/icons/fedi.png";

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

// time in formats `2023-07-14T04:12:07.720101` are in GMT and must be adjusted to unix epoch for moment display// replace .720101 with Z
export function MomentAdjustedTimeAgo({ children, ...props }) {
if (children.includes("T")) {
Expand All @@ -24,7 +31,7 @@ export function MomentAdjustedTimeAgo({ children, ...props }) {
}

export const HeaderChip = ({ children, tooltip = null, count = 0, ...props }) => (
<Tooltip title={tooltip} color={"neutral"} variant="soft" placement="bottom">
<BasicInfoTooltip title={tooltip} color={"neutral"} variant="soft" placement="bottom">
<Chip
size="md"
color={count > 0 ? "danger" : "success"}
Expand All @@ -39,7 +46,7 @@ export const HeaderChip = ({ children, tooltip = null, count = 0, ...props }) =>
>
{children}
</Chip>
</Tooltip>
</BasicInfoTooltip>
);

export const SquareChip = ({
Expand All @@ -50,7 +57,7 @@ export const SquareChip = ({
color = "neutral",
...props
}) => (
<Tooltip title={tooltip} color={"neutral"} variant="plain" placement={tooltipPlacement}>
<BasicInfoTooltip title={tooltip} color={color} variant="outlined" placement={tooltipPlacement}>
<Chip
size={size}
color={color}
Expand All @@ -62,11 +69,11 @@ export const SquareChip = ({
fontWeight: "normal",
userSelect: "none",
borderRadius: 4,
"--Chip-gap": iconOnly ? 0 : "0.25rem",
gap: iconOnly !== null ? 0 : "0.25rem",
}}
{...props}
/>
</Tooltip>
</BasicInfoTooltip>
);

export const SanitizedLink = ({ children, href, ...props }) => {
Expand All @@ -78,9 +85,30 @@ export const SanitizedLink = ({ children, href, ...props }) => {
);
};

export const UpvoteDownvoteChip = ({ counts, ...props }) => {
return (
<SquareChip
color={"neutral"}
tooltip={
<>
<Typography color="success" sx={{ pr: 1 }}>
<ThumbUpIcon /> {counts.upvotes}
</Typography>
<Typography color="warning">
<ThumbDownIcon /> {counts.downvotes}
</Typography>
</>
}
startDecorator={<ThumbsUpDownIcon />}
>
{counts.score}
</SquareChip>
);
};

export const FediverseChipLink = ({ href, size = "md", ...props }) => {
return (
<Tooltip title="Open on remote instance" color="neutral" variant="plain" placement="top">
<BasicInfoTooltip title="Open on remote instance" color="neutral" variant="outlined" placement="top">
<Chip
component={Link}
href={href}
Expand All @@ -105,6 +133,6 @@ export const FediverseChipLink = ({ href, size = "md", ...props }) => {
}}
{...props}
/>
</Tooltip>
</BasicInfoTooltip>
);
};
22 changes: 12 additions & 10 deletions src/components/ListItem/Comment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import { SquareChip } from "../Display.jsx";
import { ResolveCommentReportButton, RemoveCommentButton } from "../Actions/CommentButtons.jsx";
import { BanUserCommunityButton, BanUserSiteButton, PurgeUserSiteButton } from "../Actions/GenButtons.jsx";

import { PersonMetaLine, ReportDetails } from "./Common.jsx";
import { PersonMetaLine, CommunityMetaLine, ReportDetails } from "./Common.jsx";

import { MomentAdjustedTimeAgo, SanitizedLink, FediverseChipLink } from "../Display.jsx";
import { MomentAdjustedTimeAgo, SanitizedLink, FediverseChipLink, UpvoteDownvoteChip } from "../Display.jsx";

import { getSiteData } from "../../hooks/getSiteData";

Expand Down Expand Up @@ -47,7 +47,7 @@ const CommentContentDetail = ({ report }) => {
</Typography>

{/* Comment Meta */}
<Typography variant="h6" component="h2" sx={{ display: "flex", gap: 1 }}>
<Typography variant="h6" component="h2" sx={{ display: "flex", gap: 1, pt: 1 }}>
{baseUrl != apId && <FediverseChipLink href={fediversePostLink} />}

{report.comment.published && (
Expand All @@ -60,13 +60,7 @@ const CommentContentDetail = ({ report }) => {
{report.counts.child_count}
</SquareChip>

<SquareChip color={"primary"} tooltip="Score" startDecorator={<ThumbsUpDownIcon />}>
{report.counts.score}
</SquareChip>

<SquareChip color={"primary"} tooltip="Downvotes" startDecorator={<ThumbDownIcon />}>
{report.counts.downvotes}
</SquareChip>
<UpvoteDownvoteChip counts={report.counts} />

{report.comment_report.resolved && (
<SquareChip
Expand Down Expand Up @@ -106,6 +100,14 @@ const CommentContentDetail = ({ report }) => {
{report.comment.content}
</Alert>

<CommunityMetaLine
community={report.community}
showIn
sx={{
px: 1,
}}
/>

<PersonMetaLine
creator={report.comment_creator}
by
Expand Down
Loading