/* 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", };