Skip to content

Commit

Permalink
Add sponsorship information in post editor (#531)
Browse files Browse the repository at this point in the history
* Add sponsorship information in post editor

* Fix non solution posts being not editable

* Only parse and cleanup for Solution posts

* Add logic to handle non solution posts

---------
  • Loading branch information
itexpert120 authored Dec 1, 2023
1 parent d17bd7a commit 536b4f5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
27 changes: 24 additions & 3 deletions src/devhub/entity/post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,25 @@ const toggleEditor = () => {
State.update({ showEditor: !state.showEditor });
};

let amount = null;
let token = null;
let supervisor = 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 (
<div class="row" id={`accordion${postId}`} key="editors-footer">
Expand Down Expand Up @@ -595,9 +614,11 @@ 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 || token),
supervisor:
post.snapshot.post.snapshot.supervisor || supervisor,
seekingFunding: seekingFunding,
githubLink: post.snapshot.github_link,
onDraftStateChange,
draftState:
Expand Down
14 changes: 12 additions & 2 deletions src/devhub/entity/post/PostEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -52,7 +59,10 @@ initState({
labelStrings,
postType,
name: props.name ?? "",
description: props.description ?? "",
description:
(props.postType === "Solution"
? cleanDescription(props.description)
: props.description) ?? "",
amount: props.amount ?? "0",
token: props.token ?? "USDT",
supervisor: props.supervisor ?? "neardevdao.near",
Expand Down

0 comments on commit 536b4f5

Please sign in to comment.