{
"data": {
"thomasguntenaar.near": {
"widget": {
"devhub.entity.community.Discussions": {
"": "const { handle } = props;\nconst { getCommunity, setCommunitySocialDB } = VM.require(\n \"thomasguntenaar.near/widget/core.adapter.devhub-contract\"\n);\n\ngetCommunity = getCommunity || (() => <></>);\nsetCommunitySocialDB = setCommunitySocialDB || (() => <></>);\n\nconst communityData = getCommunity({ handle });\nconst [postsExists, setPostExists] = useState(false);\n\nconst MainContent = styled.div`\n padding-left: 2rem;\n flex: 3;\n @media screen and (max-width: 960px) {\n padding-left: 0rem;\n }\n .post:hover {\n background-color: inherit !important;\n }\n`;\n\nconst SidebarContainer = styled.div`\n flex: 1;\n`;\n\nconst Heading = styled.div`\n font-size: 19px;\n font-weight: 600;\n`;\n\nconst SubHeading = styled.div`\n font-size: 15px;\n font-weight: 600;\n`;\n\nconst Container = styled.div`\n flex-wrap: no-wrap;\n max-width: 100%;\n\n .max-width-100 {\n max-width: 100%;\n }\n @media screen and (max-width: 960px) {\n flex-wrap: wrap;\n }\n\n .card {\n border-radius: 1rem !important;\n }\n\n .display-none {\n display: none;\n }\n`;\n\nconst Tag = styled.div`\n border-top-right-radius: 50px;\n border-bottom-right-radius: 50px;\n border-top-left-radius: 50px;\n border-bottom-left-radius: 50px;\n padding-inline: 0.8rem;\n padding-block: 0.3rem;\n display: flex;\n gap: 0.5rem;\n border-width: 1px;\n border-style: solid;\n font-size: 14px;\n color: rgba(0, 236, 151, 1);\n font-weight: 800;\n`;\n\nconst [sort, setSort] = useState(\"timedesc\");\n\nfunction repostOnDiscussions(blockHeight) {\n Near.call([\n {\n contractName: \"devhub.near\",\n methodName: \"create_discussion\",\n args: {\n handle,\n blockHeight,\n },\n gas: Big(10).pow(14),\n deposit: Big(10).pow(22),\n },\n ]);\n}\n\n/**\n * I'm posting this message in the discussions of community devhub-test.\n * Which posts this to my profile @thomasguntenaar.near and reposts it\n * to discusssions.devhub-test.community.devhub.near by getting the latest\n * blockheight from my profile and reposting that message.\n */\n\nfunction setSocialDbAndRepost(v) {\n // Post to users social db\n Social.set(v, {\n onCommit: (data) => {\n console.log(\"onCommit data\", data);\n // onCommit is dead after redirect to near wallet\n },\n });\n}\n\nfunction checkHashes() {\n if (props.transactionHashes) {\n const transaction = useCache(\n () =>\n asyncFetch(\"https://rpc.mainnet.near.org\", {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n },\n body: JSON.stringify({\n jsonrpc: \"2.0\",\n id: \"dontcare\",\n method: \"tx\",\n params: [props.transactionHashes, context.accountId],\n }),\n }).then((res) => res),\n props.transactionHashes + context.accountId,\n { subscribe: false }\n );\n\n console.log(\"transaction\", transaction)\n\n if (transaction !== null) {\n const transaction_method_name =\n transaction?.body?.result?.transaction?.actions[0].FunctionCall\n .method_name;\n\n console.log(\"transaction_method_name\", transaction_method_name)\n if (transaction_method_name === \"set\") {\n // props.onDraftStateChange(null);\n console.log(\"getBlockHeightAndRepost\");\n getBlockHeightAndRepost();\n }\n\n // show the latest created post to user\n if (transaction_method_name === \"create_discussion\") {\n console.log(\"discussions created in the last call\");\n }\n }\n }\n}\n\nfunction getBlockHeightAndRepost() {\n Near.asyncView(\"social.near\", \"get\", {\n keys: [`${context.accountId}/**`],\n options: {\n with_block_height: true,\n },\n })\n .then((response) => {\n let blockHeight = response[context.accountId][\"post\"][\":block\"];\n repostOnDiscussions(blockHeight);\n })\n .catch(console.log);\n }\n}\n\nconsole.log(`discussions.${handle}.community.devhub.near`);\n\nreturn (\n <div className=\"w-100\" style={{ maxWidth: \"100%\" }}>\n <Container className=\"d-flex gap-3 m-3 pl-2\">\n <MainContent className=\"max-width-100\">\n <div className=\"d-flex flex-column gap-4\">\n {context.accountId && (\n <div className=\"card p-4\">\n {/* TODO: compose is only used for post not repost */}\n <Widget\n src={\"thomasguntenaar.near/widget/devhub.entity.community.Compose\"}\n props={{\n onSubmit: (v) => setSocialDbAndRepost(v),\n communityAccountId: `discussions.${handle}.community.devhub.near`,\n }}\n />\n </div>\n )}\n <div className=\"d-flex flex-wrap justify-content-between\">\n <Heading>Discussions</Heading>\n <div\n className={\n postsExists\n ? \"d-flex align-items-center gap-2\"\n : \" display-none\"\n }\n >\n <select\n name=\"sort\"\n id=\"sort\"\n class=\"form-select\"\n value={sort}\n onChange={(e) => {\n setSort(e.target.value);\n }}\n >\n <option selected value=\"timedesc\">\n Latest\n </option>\n <option value=\"recentcommentdesc\">Last Commented</option>\n </select>\n </div>\n </div>\n {!postsExists && (\n <div>\n <h6>No discussions exists.</h6>\n </div>\n )}\n <div className={postsExists && \"card p-4\"}>\n {/* TODO: this feed is from https://near.org/near/widget/ComponentDetailsPage?src=mob.near/widget/ProfileTabs */}\n <Widget\n key=\"feed\"\n src=\"mob.near/widget/MainPage.N.Feed\"\n props={{\n accounts: [\n `discussions.${handle}.community.devhub.near`,\n ],\n }}\n />\n {/* This is our custom feed which uses the one from near builders which should also show reposts! */}\n <Widget\n src=\"thomasguntenaar.near/widget/devhub.components.organism.Feed\"\n props={{\n showFlagAccountFeature: true,\n action: \"repost\",\n filteredAccountIds: [\n `discussions.${handle}.community.devhub.near`,\n ],\n sort: sort,\n setPostExists: setPostExists,\n showFlagAccountFeature: true,\n }}\n />\n </div>\n </div>\n </MainContent>\n <SidebarContainer>\n <div className=\"d-flex flex-column gap-3\">\n <div className=\"card p-4\">\n <div className=\"mb-2\">{communityData?.description}</div>\n <div className=\"d-flex gap-2 flex-wrap\">\n <Tag>{communityData?.tag} </Tag>\n </div>\n </div>\n <div className=\"card p-4 d-flex flex-column gap-2\">\n <SubHeading>Community Admins</SubHeading>\n {(communityData?.admins ?? []).map((accountId) => (\n <div\n key={accountId}\n className=\"d-flex\"\n style={{ fontWeight: 500 }}\n >\n <Widget\n src=\"thomasguntenaar.near/widget/devhub.components.molecule.ProfileCard\"\n props={{ accountId }}\n />\n </div>\n ))}\n </div>\n </div>\n </SidebarContainer>\n </Container>\n </div>\n);\n"
}
}
}
}
}