From cdf23c7fac8b56f4b2be158cdc68e77371e3efec Mon Sep 17 00:00:00 2001 From: enes Date: Thu, 16 Jan 2025 12:56:46 +0100 Subject: [PATCH 1/3] feat(mutelist): add post warnings to blog/mod + fix: block/unblock string --- src/components/PostWarning.tsx | 22 ++++++++++++++++++++++ src/pages/blog/index.tsx | 4 +++- src/pages/blog/loader.ts | 28 ++++++++++++++++++++++++++-- src/pages/mod/index.tsx | 5 ++++- src/pages/mod/loader.ts | 26 ++++++++++++++++++++++++-- src/types/blog.ts | 1 + src/types/mod.ts | 1 + 7 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 src/components/PostWarning.tsx diff --git a/src/components/PostWarning.tsx b/src/components/PostWarning.tsx new file mode 100644 index 0000000..f476c67 --- /dev/null +++ b/src/components/PostWarning.tsx @@ -0,0 +1,22 @@ +interface PostWarningsProps { + type: 'user' | 'admin' +} + +export const PostWarnings = ({ type }: PostWarningsProps) => ( +
+

+ {type === 'admin' ? ( + <> + Warning: This post has been blocked/hidden by the site for one of the + following reasons: +
+ Malware, Not a Mod, Illegal, Spam, Verified Report of Unauthorized + Repost. +
+ + ) : ( + <>Notice: You have blocked this post + )} +

+
+) diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx index 60927ff..47d5cd6 100644 --- a/src/pages/blog/index.tsx +++ b/src/pages/blog/index.tsx @@ -18,6 +18,7 @@ import { toast } from 'react-toastify' import { useAppSelector, useBodyScrollDisable } from 'hooks' import { ReportPopup } from 'components/ReportPopup' import { Viewer } from 'components/Markdown/Viewer' +import { PostWarnings } from 'components/PostWarning' const BLOG_REPORT_REASONS = [ { label: 'Actually CP', key: 'actuallyCP' }, @@ -29,7 +30,7 @@ const BLOG_REPORT_REASONS = [ ] export const BlogPage = () => { - const { blog, latest, isAddedToNSFW, isBlocked } = + const { blog, latest, isAddedToNSFW, isBlocked, postWarning } = useLoaderData() as BlogPageLoaderResult const userState = useAppSelector((state) => state.user) const isAdmin = @@ -84,6 +85,7 @@ export const BlogPage = () => { <>
+ {postWarning && }
{ - const { mod } = useLoaderData() as ModPageLoaderResult + const { mod, postWarning } = useLoaderData() as ModPageLoaderResult // We can get author right away from naddr, no need to wait for mod data const { naddr } = useParams() @@ -98,6 +99,7 @@ export const ModPage = () => { <>
+ {postWarning && } {

Mod Download

+ {postWarning && } {mod.downloadUrls.length > 0 && (
diff --git a/src/pages/mod/loader.ts b/src/pages/mod/loader.ts index e490e65..38e6c55 100644 --- a/src/pages/mod/loader.ts +++ b/src/pages/mod/loader.ts @@ -50,6 +50,7 @@ export const modRouteLoader = const userState = store.getState().user const loggedInUserPubkey = (userState?.user?.pubkey as string | undefined) || getFallbackPubkey() + const isAdmin = userState.user?.npub === import.meta.env.VITE_REPORTING_NPUB // Check if editing and the user is the original author // Redirect if NOT @@ -146,10 +147,33 @@ export const modRouteLoader = if (muteLists.status === 'fulfilled' && muteLists.value) { if (muteLists && muteLists.value) { if (result.mod && result.mod.aTag) { + // Show user or admin post warning if any mute list includes either post or author + if ( + muteLists.value.user.replaceableEvents.includes( + result.mod.aTag + ) || + muteLists.value.user.authors.includes(result.mod.author) + ) { + result.postWarning = 'user' + } + if ( muteLists.value.admin.replaceableEvents.includes( result.mod.aTag ) || + muteLists.value.admin.authors.includes(result.mod.author) + ) { + result.postWarning = 'admin' + } + + if ( + isAdmin && + muteLists.value.admin.replaceableEvents.includes(result.mod.aTag) + ) { + result.isBlocked = true + } + if ( + !isAdmin && muteLists.value.user.replaceableEvents.includes(result.mod.aTag) ) { result.isBlocked = true @@ -157,8 +181,6 @@ export const modRouteLoader = } // Moderate the latest - const isAdmin = - userState.user?.npub === import.meta.env.VITE_REPORTING_NPUB const isOwner = userState.user?.pubkey && userState.user.pubkey === pubkey const isUnmoderatedFully = diff --git a/src/types/blog.ts b/src/types/blog.ts index 813c76c..7e7fc18 100644 --- a/src/types/blog.ts +++ b/src/types/blog.ts @@ -39,6 +39,7 @@ export interface BlogPageLoaderResult { latest: Partial[] isAddedToNSFW: boolean isBlocked: boolean + postWarning?: 'user' | 'admin' } export interface BlogsFilterOptions { diff --git a/src/types/mod.ts b/src/types/mod.ts index 1b4ae53..a62fe5b 100644 --- a/src/types/mod.ts +++ b/src/types/mod.ts @@ -66,6 +66,7 @@ export interface ModPageLoaderResult { isAddedToNSFW: boolean isBlocked: boolean isRepost: boolean + postWarning?: 'user' | 'admin' } export type SubmitModActionResult = -- 2.34.1 From 8c10a467be38b267415ca0a36219688c65ea9f27 Mon Sep 17 00:00:00 2001 From: enes Date: Thu, 16 Jan 2025 12:57:13 +0100 Subject: [PATCH 2/3] fix(router): revalited loaders on auth --- src/layout/header.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/layout/header.tsx b/src/layout/header.tsx index 1871374..8b6b454 100644 --- a/src/layout/header.tsx +++ b/src/layout/header.tsx @@ -3,7 +3,7 @@ import { launch as launchNostrLoginDialog } from 'nostr-login' import React, { useEffect, useState } from 'react' -import { Link } from 'react-router-dom' +import { Link, useRevalidator } from 'react-router-dom' import { Banner } from '../components/Banner' import { ZapPopUp } from '../components/Zap' import { @@ -27,7 +27,7 @@ export const Header = () => { const dispatch = useAppDispatch() const { findMetadata } = useNDKContext() const userState = useAppSelector((state) => state.user) - + const revalidator = useRevalidator() // Track nostr-login extension modal open state const [isOpen, setIsOpen] = useState(false) const handleOpen = () => setIsOpen(true) @@ -75,8 +75,12 @@ export const Header = () => { } }) } + + // React router - revalidate loader states on auth changes + revalidator.revalidate() } }) + // eslint-disable-next-line react-hooks/exhaustive-deps }, [dispatch, findMetadata]) const handleLogin = () => { @@ -447,7 +451,9 @@ const RegisterButtonWithDialog = () => { color: '#ffffffbf' }} > - Warning: Make sure you backup your private key somewhere safe. If you lose it or it gets leaked, we actually can't help you. + Warning: Make sure you backup your private key + somewhere safe. If you lose it or it gets leaked, we + actually can't help you.

Date: Thu, 16 Jan 2025 13:06:16 +0100 Subject: [PATCH 3/3] refactor(mutelist): no need to check admin specific list for isBlocked --- src/pages/blog/loader.ts | 7 ------- src/pages/mod/loader.ts | 8 +------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/pages/blog/loader.ts b/src/pages/blog/loader.ts index 08df1de..b5657e1 100644 --- a/src/pages/blog/loader.ts +++ b/src/pages/blog/loader.ts @@ -161,13 +161,6 @@ export const blogRouteLoader = } if ( - isAdmin && - muteLists.value.admin.replaceableEvents.includes(result.blog.aTag) - ) { - result.isBlocked = true - } - if ( - !isAdmin && muteLists.value.user.replaceableEvents.includes(result.blog.aTag) ) { result.isBlocked = true diff --git a/src/pages/mod/loader.ts b/src/pages/mod/loader.ts index 38e6c55..afc7fa9 100644 --- a/src/pages/mod/loader.ts +++ b/src/pages/mod/loader.ts @@ -166,14 +166,8 @@ export const modRouteLoader = result.postWarning = 'admin' } + // Check if user has blocked this profile if ( - isAdmin && - muteLists.value.admin.replaceableEvents.includes(result.mod.aTag) - ) { - result.isBlocked = true - } - if ( - !isAdmin && muteLists.value.user.replaceableEvents.includes(result.mod.aTag) ) { result.isBlocked = true -- 2.34.1