Skip to content

Commit

Permalink
Add sponsorship information in post editor
Browse files Browse the repository at this point in the history
  • Loading branch information
itexpert120 committed Nov 29, 2023
1 parent 79f6ee2 commit d24b2d9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
22 changes: 19 additions & 3 deletions src/devhub/entity/post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,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 (
<div class="row" id={`accordion${postId}`} key="editors-footer">
Expand Down Expand Up @@ -597,9 +609,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:
Expand Down
11 changes: 9 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,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",
Expand Down

0 comments on commit d24b2d9

Please sign in to comment.