From 6aa82cf5cb6e81d8532ccd10ce7496dd1653800c Mon Sep 17 00:00:00 2001 From: KaleemNeslit Date: Mon, 14 Oct 2024 22:16:54 +0500 Subject: [PATCH 1/4] improve the edit of thread from other screens --- .../pages/discussions/DiscussionsPage.tsx | 2 +- .../pages/view_thread/ViewThreadPage.tsx | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/pages/discussions/DiscussionsPage.tsx b/packages/commonwealth/client/scripts/views/pages/discussions/DiscussionsPage.tsx index 18c17665678..51b6a3399dd 100644 --- a/packages/commonwealth/client/scripts/views/pages/discussions/DiscussionsPage.tsx +++ b/packages/commonwealth/client/scripts/views/pages/discussions/DiscussionsPage.tsx @@ -240,7 +240,7 @@ const DiscussionsPage = ({ topicName }: DiscussionsPageProps) => { thread={thread} canReact={!disabledActionsTooltipText} canComment={!disabledActionsTooltipText} - onEditStart={() => navigate(`${discussionLink}`)} + onEditStart={() => navigate(`${discussionLink}?isEdit=true`)} onStageTagClick={() => { navigate(`/discussions?stage=${thread.stage}`); }} diff --git a/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx b/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx index 807e5f859ac..25c337a1905 100644 --- a/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx +++ b/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx @@ -11,6 +11,7 @@ import { useCommonNavigate } from 'navigation/helpers'; import 'pages/view_thread/index.scss'; import React, { useEffect, useState } from 'react'; import { Helmet } from 'react-helmet-async'; +import { useSearchParams } from 'react-router-dom'; import app from 'state'; import { useFetchCommentsQuery } from 'state/api/comments'; import useGetViewCountByObjectIdQuery from 'state/api/general/getViewCountByObjectId'; @@ -68,12 +69,18 @@ import { SnapshotCreationCard } from './snapshot_creation_card'; type ViewThreadPageProps = { identifier: string; }; +function useParams() { + const [searchParams] = useSearchParams(); + const isEdit = searchParams.get('isEdit') ?? undefined; + return { + isEdit, + }; +} const ViewThreadPage = ({ identifier }: ViewThreadPageProps) => { const threadId = identifier.split('-')[0]; - + const { isEdit } = useParams(); const navigate = useCommonNavigate(); - const [isEditingBody, setIsEditingBody] = useState(false); const [isGloballyEditing, setIsGloballyEditing] = useState(false); const [savedEdits, setSavedEdits] = useState(''); @@ -130,6 +137,15 @@ const ViewThreadPage = ({ identifier }: ViewThreadPageProps) => { thread?.topic?.id, ); + //TODO: + useEffect(() => { + if (thread && isEdit) { + setShouldRestoreEdits(true); + setIsGloballyEditing(true); + setIsEditingBody(true); + } + }, [isEdit]); + const { data: comments = [], error: fetchCommentsError } = useFetchCommentsQuery({ communityId, From 3356bd426d47a2eb75352cad8efff44698aef94d Mon Sep 17 00:00:00 2001 From: KaleemNeslit Date: Mon, 14 Oct 2024 22:39:12 +0500 Subject: [PATCH 2/4] improve the edit of thread from other screens --- .../client/scripts/views/pages/view_thread/ViewThreadPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx b/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx index 25c337a1905..3418342f1b8 100644 --- a/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx +++ b/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx @@ -139,7 +139,7 @@ const ViewThreadPage = ({ identifier }: ViewThreadPageProps) => { //TODO: useEffect(() => { - if (thread && isEdit) { + if (isEdit === 'true') { setShouldRestoreEdits(true); setIsGloballyEditing(true); setIsEditingBody(true); From 0a245a76e6adeb47d0b39e14df2f72fd390afc65 Mon Sep 17 00:00:00 2001 From: KaleemNeslit Date: Thu, 24 Oct 2024 16:59:59 +0500 Subject: [PATCH 3/4] fix pr review --- .../views/pages/view_thread/ViewThreadPage.tsx | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx b/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx index 3418342f1b8..a1ed0acbb1e 100644 --- a/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx +++ b/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx @@ -69,17 +69,10 @@ import { SnapshotCreationCard } from './snapshot_creation_card'; type ViewThreadPageProps = { identifier: string; }; -function useParams() { - const [searchParams] = useSearchParams(); - const isEdit = searchParams.get('isEdit') ?? undefined; - - return { - isEdit, - }; -} const ViewThreadPage = ({ identifier }: ViewThreadPageProps) => { const threadId = identifier.split('-')[0]; - const { isEdit } = useParams(); + const [searchParams] = useSearchParams(); + const isEdit = searchParams.get('isEdit') ?? undefined; const navigate = useCommonNavigate(); const [isEditingBody, setIsEditingBody] = useState(false); const [isGloballyEditing, setIsGloballyEditing] = useState(false); @@ -137,7 +130,6 @@ const ViewThreadPage = ({ identifier }: ViewThreadPageProps) => { thread?.topic?.id, ); - //TODO: useEffect(() => { if (isEdit === 'true') { setShouldRestoreEdits(true); From d077b2f3b078f6301d12f9b57f816d0253f1a16d Mon Sep 17 00:00:00 2001 From: KaleemNeslit Date: Thu, 24 Oct 2024 18:57:10 +0500 Subject: [PATCH 4/4] added the permission chek --- .../scripts/views/pages/view_thread/ViewThreadPage.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx b/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx index 0b1a76f25ec..0b49f9d1ed5 100644 --- a/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx +++ b/packages/commonwealth/client/scripts/views/pages/view_thread/ViewThreadPage.tsx @@ -152,12 +152,16 @@ const ViewThreadPage = ({ identifier }: ViewThreadPageProps) => { ); useEffect(() => { - if (isEdit === 'true') { + if ( + isEdit === 'true' && + thread && + (isAdmin || Permissions.isThreadAuthor(thread)) + ) { setShouldRestoreEdits(true); setIsGloballyEditing(true); setIsEditingBody(true); } - }, [isEdit]); + }, [isEdit, thread, isAdmin]); const { data: comments = [], error: fetchCommentsError } = useFetchCommentsQuery({