From e4da11b5124171b45b45ac36acdd0d7d31605cfe Mon Sep 17 00:00:00 2001 From: Zeeshan Ahmad Date: Wed, 29 Nov 2023 06:14:34 +0500 Subject: [PATCH 1/4] Add sponsorship information in post editor --- src/devhub/entity/post/Post.jsx | 22 +++++++++++++++++++--- src/devhub/entity/post/PostEditor.jsx | 11 +++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/devhub/entity/post/Post.jsx b/src/devhub/entity/post/Post.jsx index 9d8ba7d1b..553014ccd 100644 --- a/src/devhub/entity/post/Post.jsx +++ b/src/devhub/entity/post/Post.jsx @@ -561,6 +561,18 @@ const toggleEditor = () => { State.update({ showEditor: !state.showEditor }); }; +const amountMatch = post.snapshot.description.match( + /Requested amount: (\d+(\.\d+)?) (\w+)/ +); +const amount = amountMatch ? parseFloat(amountMatch[1]) : null; +const currency = amountMatch ? amountMatch[3] : null; + +const sponsorMatch = post.snapshot.description.match( + /Requested sponsor: @([^\s]+)/ +); +const sponsorTag = sponsorMatch ? sponsorMatch[1] : null; +const seekingFunding = amount !== 0 || currency !== "" || sponsorTag !== ""; + function Editor() { return (
@@ -595,9 +607,13 @@ function Editor() { labels: post.snapshot.labels, name: post.snapshot.name, description: post.snapshot.description, - amount: post.snapshot.amount, - token: tokenResolver(post.snapshot.sponsorship_token), - supervisor: post.snapshot.supervisor, + amount: post.snapshot.amount || amount, + token: tokenResolver( + post.snapshot.sponsorship_token || currency + ), + supervisor: + post.snapshot.post.snapshot.supervisor || sponsorTag, + seekingFunding: seekingFunding, githubLink: post.snapshot.github_link, onDraftStateChange, draftState: diff --git a/src/devhub/entity/post/PostEditor.jsx b/src/devhub/entity/post/PostEditor.jsx index 7481cf6a8..778162bc9 100644 --- a/src/devhub/entity/post/PostEditor.jsx +++ b/src/devhub/entity/post/PostEditor.jsx @@ -42,8 +42,15 @@ const labels = labelStrings.map((s) => { return { name: s }; }); +const cleanDescription = (description) => { + return description.replace( + /###### Requested amount: .+?\n###### Requested sponsor: @[^\s]+\n/g, + "" + ); +}; + initState({ - seekingFunding: false, + seekingFunding: props.seekingFunding ?? false, author_id: context.accountId, // Should be a list of objects with field "name". labels, @@ -52,7 +59,7 @@ initState({ labelStrings, postType, name: props.name ?? "", - description: props.description ?? "", + description: cleanDescription(props.description) ?? "", amount: props.amount ?? "0", token: props.token ?? "USDT", supervisor: props.supervisor ?? "neardevdao.near", From 6323bedb251badc8e0e0902986b11a6e4dd61451 Mon Sep 17 00:00:00 2001 From: Zeeshan Ahmad Date: Wed, 29 Nov 2023 09:53:04 +0500 Subject: [PATCH 2/4] Fix non solution posts being not editable --- src/devhub/entity/post/Post.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/devhub/entity/post/Post.jsx b/src/devhub/entity/post/Post.jsx index 553014ccd..725a117f0 100644 --- a/src/devhub/entity/post/Post.jsx +++ b/src/devhub/entity/post/Post.jsx @@ -571,7 +571,8 @@ const sponsorMatch = post.snapshot.description.match( /Requested sponsor: @([^\s]+)/ ); const sponsorTag = sponsorMatch ? sponsorMatch[1] : null; -const seekingFunding = amount !== 0 || currency !== "" || sponsorTag !== ""; +const seekingFunding = + amount !== null || currency !== null || sponsorTag !== null; function Editor() { return ( From 2fb7e2f6fafb45adb35c2c021421fe1090c46443 Mon Sep 17 00:00:00 2001 From: Zeeshan Ahmad Date: Wed, 29 Nov 2023 23:07:16 +0500 Subject: [PATCH 3/4] Only parse and cleanup for Solution posts --- src/devhub/entity/post/Post.jsx | 34 +++++++++++++++------------ src/devhub/entity/post/PostEditor.jsx | 4 ++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/devhub/entity/post/Post.jsx b/src/devhub/entity/post/Post.jsx index 725a117f0..444a8488b 100644 --- a/src/devhub/entity/post/Post.jsx +++ b/src/devhub/entity/post/Post.jsx @@ -561,18 +561,24 @@ const toggleEditor = () => { State.update({ showEditor: !state.showEditor }); }; -const amountMatch = post.snapshot.description.match( - /Requested amount: (\d+(\.\d+)?) (\w+)/ -); -const amount = amountMatch ? parseFloat(amountMatch[1]) : null; -const currency = amountMatch ? amountMatch[3] : null; +let amount; +let token; +let supervisor; -const sponsorMatch = post.snapshot.description.match( - /Requested sponsor: @([^\s]+)/ -); -const sponsorTag = sponsorMatch ? sponsorMatch[1] : null; -const seekingFunding = - amount !== null || currency !== null || sponsorTag !== null; +if (state.postType === "Solution") { + const amountMatch = post.snapshot.description.match( + /Requested amount: (\d+(\.\d+)?) (\w+)/ + ); + amount = amountMatch ? parseFloat(amountMatch[1]) : null; + token = amountMatch ? amountMatch[3] : null; + + const sponsorMatch = post.snapshot.description.match( + /Requested sponsor: @([^\s]+)/ + ); + supervisor = sponsorMatch ? sponsorMatch[1] : null; +} + +const seekingFunding = amount !== null || token !== null || supervisor !== null; function Editor() { return ( @@ -609,11 +615,9 @@ function Editor() { name: post.snapshot.name, description: post.snapshot.description, amount: post.snapshot.amount || amount, - token: tokenResolver( - post.snapshot.sponsorship_token || currency - ), + token: tokenResolver(post.snapshot.sponsorship_token || token), supervisor: - post.snapshot.post.snapshot.supervisor || sponsorTag, + post.snapshot.post.snapshot.supervisor || supervisor, seekingFunding: seekingFunding, githubLink: post.snapshot.github_link, onDraftStateChange, diff --git a/src/devhub/entity/post/PostEditor.jsx b/src/devhub/entity/post/PostEditor.jsx index 778162bc9..9a72046a7 100644 --- a/src/devhub/entity/post/PostEditor.jsx +++ b/src/devhub/entity/post/PostEditor.jsx @@ -43,6 +43,10 @@ const labels = labelStrings.map((s) => { }); const cleanDescription = (description) => { + if (props.postType !== "Solution") { + return description; + } + return description.replace( /###### Requested amount: .+?\n###### Requested sponsor: @[^\s]+\n/g, "" From 77503f9c06159b5fba306b3889f0c383217c084d Mon Sep 17 00:00:00 2001 From: Zeeshan Ahmad Date: Fri, 1 Dec 2023 03:59:55 +0500 Subject: [PATCH 4/4] Add logic to handle non solution posts --- src/devhub/entity/post/Post.jsx | 6 +++--- src/devhub/entity/post/PostEditor.jsx | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/devhub/entity/post/Post.jsx b/src/devhub/entity/post/Post.jsx index 444a8488b..2b42d6d7c 100644 --- a/src/devhub/entity/post/Post.jsx +++ b/src/devhub/entity/post/Post.jsx @@ -561,9 +561,9 @@ const toggleEditor = () => { State.update({ showEditor: !state.showEditor }); }; -let amount; -let token; -let supervisor; +let amount = null; +let token = null; +let supervisor = null; if (state.postType === "Solution") { const amountMatch = post.snapshot.description.match( diff --git a/src/devhub/entity/post/PostEditor.jsx b/src/devhub/entity/post/PostEditor.jsx index 9a72046a7..a95772b4f 100644 --- a/src/devhub/entity/post/PostEditor.jsx +++ b/src/devhub/entity/post/PostEditor.jsx @@ -43,10 +43,6 @@ const labels = labelStrings.map((s) => { }); const cleanDescription = (description) => { - if (props.postType !== "Solution") { - return description; - } - return description.replace( /###### Requested amount: .+?\n###### Requested sponsor: @[^\s]+\n/g, "" @@ -63,7 +59,10 @@ initState({ labelStrings, postType, name: props.name ?? "", - description: cleanDescription(props.description) ?? "", + description: + (props.postType === "Solution" + ? cleanDescription(props.description) + : props.description) ?? "", amount: props.amount ?? "0", token: props.token ?? "USDT", supervisor: props.supervisor ?? "neardevdao.near",