ReviewDB: allow deleting reviews on own profile
This commit is contained in:
parent
f66e35b658
commit
664dd0a992
3 changed files with 12 additions and 8 deletions
|
@ -20,7 +20,7 @@ import { openUserProfile } from "@utils/discord";
|
||||||
import { classes } from "@utils/misc";
|
import { classes } from "@utils/misc";
|
||||||
import { LazyComponent } from "@utils/react";
|
import { LazyComponent } from "@utils/react";
|
||||||
import { filters, findBulk } from "@webpack";
|
import { filters, findBulk } from "@webpack";
|
||||||
import { Alerts, moment, Parser, Timestamp, UserStore } from "@webpack/common";
|
import { Alerts, moment, Parser, Timestamp } from "@webpack/common";
|
||||||
|
|
||||||
import { Review, ReviewType } from "../entities";
|
import { Review, ReviewType } from "../entities";
|
||||||
import { deleteReview, reportReview } from "../reviewDbApi";
|
import { deleteReview, reportReview } from "../reviewDbApi";
|
||||||
|
@ -30,7 +30,7 @@ import { DeleteButton, ReportButton } from "./MessageButton";
|
||||||
import ReviewBadge from "./ReviewBadge";
|
import ReviewBadge from "./ReviewBadge";
|
||||||
|
|
||||||
export default LazyComponent(() => {
|
export default LazyComponent(() => {
|
||||||
// this is terrible, blame ven
|
// this is terrible, blame mantika
|
||||||
const p = filters.byProps;
|
const p = filters.byProps;
|
||||||
const [
|
const [
|
||||||
{ cozyMessage, buttons, message, buttonsInner, groupStart },
|
{ cozyMessage, buttons, message, buttonsInner, groupStart },
|
||||||
|
@ -48,7 +48,7 @@ export default LazyComponent(() => {
|
||||||
|
|
||||||
const dateFormat = new Intl.DateTimeFormat();
|
const dateFormat = new Intl.DateTimeFormat();
|
||||||
|
|
||||||
return function ReviewComponent({ review, refetch }: { review: Review; refetch(): void; }) {
|
return function ReviewComponent({ review, refetch, profileId }: { review: Review; refetch(): void; profileId: string; }) {
|
||||||
function openModal() {
|
function openModal() {
|
||||||
openUserProfile(review.sender.discordID);
|
openUserProfile(review.sender.discordID);
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ export default LazyComponent(() => {
|
||||||
<div className={classes(buttonClasses.wrapper, buttonsInner)} >
|
<div className={classes(buttonClasses.wrapper, buttonsInner)} >
|
||||||
<ReportButton onClick={reportRev} />
|
<ReportButton onClick={reportRev} />
|
||||||
|
|
||||||
{canDeleteReview(review, UserStore.getCurrentUser().id) && (
|
{canDeleteReview(profileId, review) && (
|
||||||
<DeleteButton onClick={delReview} />
|
<DeleteButton onClick={delReview} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -79,6 +79,7 @@ export default function ReviewsView({
|
||||||
refetch={refetch}
|
refetch={refetch}
|
||||||
reviews={reviewData!.reviews}
|
reviews={reviewData!.reviews}
|
||||||
hideOwnReview={hideOwnReview}
|
hideOwnReview={hideOwnReview}
|
||||||
|
profileId={discordId}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{showInput && (
|
{showInput && (
|
||||||
|
@ -93,7 +94,7 @@ export default function ReviewsView({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ReviewList({ refetch, reviews, hideOwnReview }: { refetch(): void; reviews: Review[]; hideOwnReview: boolean; }) {
|
function ReviewList({ refetch, reviews, hideOwnReview, profileId }: { refetch(): void; reviews: Review[]; hideOwnReview: boolean; profileId: string; }) {
|
||||||
const myId = UserStore.getCurrentUser().id;
|
const myId = UserStore.getCurrentUser().id;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -104,6 +105,7 @@ function ReviewList({ refetch, reviews, hideOwnReview }: { refetch(): void; revi
|
||||||
key={review.id}
|
key={review.id}
|
||||||
review={review}
|
review={review}
|
||||||
refetch={refetch}
|
refetch={refetch}
|
||||||
|
profileId={profileId}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import { classNameFactory } from "@api/Styles";
|
||||||
import { Logger } from "@utils/Logger";
|
import { Logger } from "@utils/Logger";
|
||||||
import { openModal } from "@utils/modal";
|
import { openModal } from "@utils/modal";
|
||||||
import { findByProps } from "@webpack";
|
import { findByProps } from "@webpack";
|
||||||
import { React, Toasts } from "@webpack/common";
|
import { React, Toasts, UserStore } from "@webpack/common";
|
||||||
|
|
||||||
import { Review, UserType } from "./entities";
|
import { Review, UserType } from "./entities";
|
||||||
import { settings } from "./settings";
|
import { settings } from "./settings";
|
||||||
|
@ -73,9 +73,11 @@ export function showToast(text: string) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function canDeleteReview(review: Review, userId: string) {
|
export function canDeleteReview(profileId: string, review: Review) {
|
||||||
|
const myId = UserStore.getCurrentUser().id;
|
||||||
return (
|
return (
|
||||||
review.sender.discordID === userId
|
myId === profileId
|
||||||
|
|| review.sender.discordID === profileId
|
||||||
|| settings.store.user?.type === UserType.Admin
|
|| settings.store.user?.type === UserType.Admin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue