/* INCLUDE: "common.jsx" */ const nearNFDevsContractAccountId = props.nearNFDevsContractAccountId || (context.widgetSrc ?? "near-analytics.near").split("/", 1)[0]; const nearNFDevsWidgetsAccountId = props.nearNFDevsWidgetsAccountId || (context.widgetSrc ?? "near-analytics.near").split("/", 1)[0]; function widget(widgetName, widgetProps, key) { widgetProps = { ...widgetProps, nearNFDevsContractAccountId: props.nearNFDevsContractAccountId, nearNFDevsWidgetsAccountId: props.nearNFDevsWidgetsAccountId, referral: props.referral, }; return ( <Widget src={`${nearNFDevsWidgetsAccountId}/widget/townhall-board.${widgetName}`} props={widgetProps} key={key} /> ); } function href(widgetName, linkProps) { linkProps = { ...linkProps }; if (props.nearNFDevsContractAccountId) { linkProps.nearNFDevsContractAccountId = props.nearNFDevsContractAccountId; } if (props.nearNFDevsWidgetsAccountId) { linkProps.nearNFDevsWidgetsAccountId = props.nearNFDevsWidgetsAccountId; } if (props.referral) { linkProps.referral = props.referral; } const linkPropsQuery = Object.entries(linkProps) .filter(([_key, nullable]) => (nullable ?? null) !== null) .map(([key, value]) => `${key}=${value}`) .join("&"); return `/#/${nearNFDevsWidgetsAccountId}/widget/townhall-board.pages.${widgetName}${ linkPropsQuery ? "?" : "" }${linkPropsQuery}`; } /* END_INCLUDE: "common.jsx" */ /* INCLUDE: "shared/lib/gui" */ const Card = styled.div` &:hover { box-shadow: rgba(3, 102, 214, 0.3) 0px 0px 0px 3px; } `; const CompactContainer = styled.div` width: fit-content !important; max-width: 100%; `; /* END_INCLUDE: "shared/lib/gui" */ const postId = props.post.id ?? (props.id ? parseInt(props.id) : 0); const post = props.post ?? Near.view(nearNFDevsContractAccountId, "get_post", { post_id: postId }); if (!post) { return <div>Loading ...</div>; } const snapshot = post.snapshot; // If this post is displayed under another post. Used to limit the size. const isUnderPost = props.isUnderPost ? true : false; const parentId = Near.view(nearNFDevsContractAccountId, "get_parent_id", { post_id: postId, }); const childPostIdsUnordered = Near.view(nearNFDevsContractAccountId, "get_children_ids", { post_id: postId, }) ?? []; const childPostIds = props.isPreview ? [] : childPostIdsUnordered.reverse(); const expandable = props.isPreview ? false : props.expandable ?? false; const defaultExpanded = expandable ? props.defaultExpanded : true; function readableDate(timestamp) { var a = new Date(timestamp); return a.toDateString() + " " + a.toLocaleTimeString(); } const timestamp = readableDate( snapshot.timestamp ? snapshot.timestamp / 1000000 : Date.now() ); const postSearchKeywords = props.searchKeywords ? ( <div style={{ "font-family": "monospace" }} key="post-search-keywords"> <span>Found keywords: </span> {props.searchKeywords.map((label) => { return <span class="badge text-bg-info me-1">{label}</span>; })} </div> ) : ( <div key="post-search-keywords"></div> ); const searchKeywords = props.searchKeywords ? ( <div class="mb-1" key="search-keywords"> <small class="text-muted">{postSearchKeywords}</small> </div> ) : ( <div key="search-keywords"></div> ); const linkToParent = isUnderPost || !parentId ? ( <div key="link-to-parent"></div> ) : ( <div className="card-header" key="link-to-parent"> <a href={href("Post", { id: parentId })}> <i class="bi bi-arrow-90deg-up"></i>Go to parent{" "} </a> </div> ); const allowedToEdit = !props.isPreview && Near.view(nearNFDevsContractAccountId, "is_allowed_to_edit", { post_id: postId, editor: context.accountId, }); const btnEditorWidget = (postType, name) => { return ( <li> <a class="dropdown-item" data-bs-toggle="collapse" href={`#collapse${postType}Editor${postId}`} role="button" aria-expanded="false" aria-controls={`collapse${postType}Editor${postId}`} > {name} </a> </li> ); }; const editControl = allowedToEdit ? ( <div class="btn-group" role="group"> <a class="card-link px-2" role="button" title="Edit post" data-bs-toggle="dropdown" aria-expanded="false" type="button" > <div class="bi bi-pencil-square"></div> </a> <ul class="dropdown-menu"> {btnEditorWidget("Idea", "Edit as an idea")} {btnEditorWidget("Submission", "Edit as a solution")} {btnEditorWidget("Attestation", "Edit as an attestation")} {btnEditorWidget("Sponsorship", "Edit as a sponsorship")} {btnEditorWidget("Comment", "Edit as a comment")} </ul> </div> ) : ( <div></div> ); const shareButton = props.isPreview ? ( <div></div> ) : ( <a class="card-link" href={href("Post", { id: postId })} role="button" target="_blank" title="Open in new tab" > <div class="bi bi-share"></div> </a> ); const header = ( <div className="card-header" key="header"> <small class="text-muted"> <div class="row justify-content-between"> <div class="col-4"> <Widget src={`neardevgov.near/widget/ProfileLine`} props={{ accountId: post.author_id }} /> </div> <div class="col-5"> <div class="d-flex justify-content-end"> {editControl} {timestamp} <div class="bi bi-clock-history px-2"></div> {shareButton} </div> </div> </div> </small> </div> ); const emptyIcons = { Idea: "bi-lightbulb", Comment: "bi-chat", Submission: "bi-rocket", Attestation: "bi-check-circle", Sponsorship: "bi-cash-coin", Github: "bi-github", Like: "bi-heart", Reply: "bi-reply", }; const fillIcons = { Idea: "bi-lightbulb-fill", Comment: "bi-chat-fill", Submission: "bi-rocket-fill", Attestation: "bi-check-circle-fill", Sponsorship: "bi-cash-coin", Github: "bi-github", Like: "bi-heart-fill", Reply: "bi-reply-fill", }; // Trigger saving this widget. const borders = { Idea: "border-secondary", Comment: "border-secondary", Submission: "border-secondary", Attestation: "border-secondary", Sponsorship: "border-secondary", Github: "border-secondary", }; const containsLike = props.isPreview ? false : post.likes.find((l) => l.author_id == context.accountId); const likeBtnClass = containsLike ? fillIcons.Like : emptyIcons.Like; // This must be outside onLike, because Near.view returns null at first, and when the view call finished, it returns true/false. // If checking this inside onLike, it will give `null` and we cannot tell the result is true or false. let grantNotify = Near.view("social.near", "is_write_permission_granted", { predecessor_id: nearNFDevsContractAccountId, key: context.accountId + "/index/notify", }); if (grantNotify === null) { return; } const onLike = () => { if (!context.accountId) { return; } let likeTxn = [ { contractName: nearNFDevsContractAccountId, methodName: "add_like", args: { post_id: postId, }, deposit: Big(10).pow(21).mul(2), gas: Big(10).pow(12).mul(100), }, ]; if (grantNotify === false) { likeTxn.unshift({ contractName: "social.near", methodName: "grant_write_permission", args: { predecessor_id: nearNFDevsContractAccountId, keys: [context.accountId + "/index/notify"], }, deposit: Big(10).pow(23), gas: Big(10).pow(12).mul(30), }); } Near.call(likeTxn); }; const btnCreatorWidget = (postType, icon, name, desc) => { return ( <li class="py-1"> <a class="dropdown-item text-decoration-none d-flex align-items-center lh-sm" style={{ color: "rgb(55,109,137)" }} data-bs-toggle="collapse" href={`#collapse${postType}Creator${postId}`} role="button" aria-expanded="false" aria-controls={`collapse${postType}Creator${postId}`} > <i class={`bi ${icon}`} style={{ fontSize: "1.5rem" }}> {" "} </i> <div class="ps-2 text-wrap" style={{ width: "18rem" }}> <div>{name}</div> <small class="fw-light text-secondary">{desc}</small> </div> </a> </li> ); }; const buttonsFooter = props.isPreview ? null : ( <div class="row" key="buttons-footer"> <div class="col-8"> <div class="btn-group" role="group" aria-label="Basic outlined example"> <button type="button" class="btn btn-outline-primary" style={{ border: "0px" }} onClick={onLike} > <i class={`bi ${likeBtnClass}`}> </i> {post.likes.length == 0 ? "Like" : widget("components.layout.LikeButton.Faces", { likesByUsers: Object.fromEntries( post.likes.map(({ author_id }) => [author_id, ""]) ), })} </button> <div class="btn-group" role="group"> <button type="button" class="btn btn-outline-primary" style={{ border: "0px" }} data-bs-toggle="dropdown" aria-expanded="false" > <i class={`bi ${emptyIcons.Reply}`}> </i> Reply </button> <ul class="dropdown-menu"> {btnCreatorWidget( "Idea", emptyIcons.Idea, "Idea", "Get feedback from the community about a problem, opportunity, or need." )} {btnCreatorWidget( "Submission", emptyIcons.Submission, "Solution", "Provide a specific proposal or implementation to an idea, optionally requesting funding." )} {btnCreatorWidget( "Attestation", emptyIcons.Attestation, "Attestation", "Formally review or validate a solution as a recognized expert." )} {btnCreatorWidget( "Sponsorship", emptyIcons.Sponsorship, "Sponsorship", "Offer to fund projects, events, or proposals that match your needs." )} <li> <hr class="dropdown-divider" /> </li> {btnCreatorWidget( "Comment", emptyIcons.Comment, "Comment", "Ask a question, provide information, or share a resource that is relevant to the thread." )} </ul> </div> <button type="button" class="btn btn-outline-primary" style={{ border: "0px" }} data-bs-toggle="collapse" href={`#collapseChildPosts${postId}`} aria-expanded={defaultExpanded} aria-controls={`collapseChildPosts${postId}`} > <i class="bi bi-arrows-expand"> </i>{" "} {`Expand Replies (${childPostIds.length})`} </button> </div> </div> </div> ); const CreatorWidget = (postType) => { return ( <div class="collapse" id={`collapse${postType}Creator${postId}`} data-bs-parent={`#accordion${postId}`} > {widget("components.posts.PostEditor", { postType, parentId: postId, mode: "Create", })} </div> ); }; const EditorWidget = (postType) => { return ( <div class="collapse" id={`collapse${postType}Editor${postId}`} data-bs-parent={`#accordion${postId}`} > {widget("components.posts.PostEditor", { postType, postId, mode: "Edit", author_id: post.author_id, labels: post.snapshot.labels, name: post.snapshot.name, description: post.snapshot.description, amount: post.snapshot.amount, token: post.snapshot.sponsorship_token, supervisor: post.snapshot.supervisor, githubLink: post.snapshot.github_link, })} </div> ); };