Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add discussions tab to community page #645

Merged
merged 28 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b950911
initial commit
Tguntenaar Jan 23, 2024
8de82ab
added createDiscussion and dynamic feed action
Tguntenaar Jan 26, 2024
3a7dd60
remove old test
Tguntenaar Jan 26, 2024
b6f3db7
call grant_write_permission on socialdb contract to repost
Tguntenaar Jan 26, 2024
d9846b5
removed comment
Tguntenaar Jan 26, 2024
51a1a1e
add import for getDepositAmountForWriteAccess
Tguntenaar Jan 26, 2024
6040946
get storage_balance_of user
Tguntenaar Jan 26, 2024
ae0034e
grant permission for discussion to write post
Tguntenaar Jan 31, 2024
61ca49d
follow the discussions account in the feed
Tguntenaar Feb 2, 2024
787fbb4
removed grant_write_permission
Tguntenaar Feb 5, 2024
c8ac8eb
need a better way to get the blockheight
Tguntenaar Feb 6, 2024
815c8db
added near view get with_block_height
Tguntenaar Feb 6, 2024
d4ebeda
change title
Tguntenaar Feb 7, 2024
63d75bb
updated preview with latest changes
Tguntenaar Feb 7, 2024
b98b0a4
Merge branch 'main' of github.com:near/neardevhub-widgets into featur…
Tguntenaar Feb 7, 2024
75962f1
Recreate what announcements does: TODO listen to index/repost instead…
Tguntenaar Feb 8, 2024
6af9aa1
wip
Tguntenaar Feb 8, 2024
e171f4e
wip props.transactionHashes not recognized ?
Tguntenaar Feb 10, 2024
a4520e1
pass transactionHashes on from the page
Tguntenaar Feb 10, 2024
f95363a
Ready for review @frol
Tguntenaar Feb 12, 2024
b33eb09
added force option and getBlockHeightAndRepost onCommit
Tguntenaar Feb 16, 2024
b430920
Change the profile preview where discussions is posted from
Tguntenaar Feb 17, 2024
54d6c4b
Update src/devhub/entity/community/Discussions.jsx
Tguntenaar Feb 17, 2024
1b92280
added REPL_RPC_URL
Tguntenaar Feb 17, 2024
9e98b74
Merge branch 'feature/584-discussions-front-end' of github.com:Tgunte…
Tguntenaar Feb 17, 2024
ce7be7c
removed double feed
Tguntenaar Feb 17, 2024
5156218
added space to replacements
Tguntenaar Feb 17, 2024
5bae5f0
notify mention in discussions
Tguntenaar Feb 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function Page() {
// ?page=community
case "community": {
return (
// Considering to consolsidate this into a single widget,
// Considering to consolidate this into a single widget,
// where each level handles its own routing.
// Modularizing a page just like we do with addons
<Widget
Expand Down
13 changes: 13 additions & 0 deletions src/core/adapter/devhub-contract.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ function getAllCommunitiesMetadata() {
);
}

function getSocialWithBlockHeight(data) {
return Near.view("${REPL_SOCIAL_CONTRACT}", "get", data) ?? null;
}

function getAllLabels() {
return Near.view("${REPL_DEVHUB_LEGACY}", "get_all_labels") ?? null;
}
Expand Down Expand Up @@ -131,6 +135,15 @@ function setCommunitySocialDB({ handle, data }) {
);
}

function createDiscussion({ handle, data }) {
return (
Near.call("${REPL_DEVHUB_CONTRACT}", "create_discussion", {
handle,
data,
}) ?? null
);
}

function useQuery(name, params) {
const initialState = { data: null, error: null, isLoading: true };

Expand Down
2 changes: 1 addition & 1 deletion src/devhub/components/organism/Feed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ return (
<Feed
index={[
{
action: "post",
action: props.action ? props.action : "post",
key: "main",
options: {
limit: 10,
Expand Down
183 changes: 183 additions & 0 deletions src/devhub/entity/community/Discussions.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
const { handle } = props;
const { getCommunity, setCommunitySocialDB } = VM.require(
"${REPL_DEVHUB}/widget/core.adapter.devhub-contract"
);

getCommunity = getCommunity || (() => <></>);
setCommunitySocialDB = setCommunitySocialDB || (() => <></>);

const communityData = getCommunity({ handle });

const MainContent = styled.div`
padding-left: 2rem;
flex: 3;
@media screen and (max-width: 960px) {
padding-left: 0rem;
}
.post:hover {
background-color: inherit !important;
}
`;

const SidebarContainer = styled.div`
flex: 1;
`;

const Heading = styled.div`
font-size: 19px;
font-weight: 600;
`;

const SubHeading = styled.div`
font-size: 15px;
font-weight: 600;
`;

const Container = styled.div`
flex-wrap: no-wrap;
max-width: 100%;

.max-width-100 {
max-width: 100%;
}
@media screen and (max-width: 960px) {
flex-wrap: wrap;
}

.card {
border-radius: 1rem !important;
}
`;

const Tag = styled.div`
border-top-right-radius: 50px;
border-bottom-right-radius: 50px;
border-top-left-radius: 50px;
border-bottom-left-radius: 50px;
padding-inline: 0.8rem;
padding-block: 0.3rem;
display: flex;
gap: 0.5rem;
border-width: 1px;
border-style: solid;
font-size: 14px;
color: rgba(0, 236, 151, 1);
font-weight: 800;
`;

const [sort, setSort] = useState("timedesc");

function repostOnDiscussions(blockHeight) {
Near.call([
{
contractName: "${REPL_DEVHUB_CONTRACT}",
methodName: "create_discussion",
args: {
handle,
blockHeight,
},
gas: Big(10).pow(14),
},
]);
}

function setSocialDbAndRepost(v) {
// TODO remove
console.log("v", v);
// Post to users social db
const result = Social.set(v, {
onCommit: (data) => {
console.log("onCommit data", data);
// TODO move to devhub-contract.jsx
Near.asyncView("${REPL_SOCIAL_CONTRACT}", "get", {
keys: [`${context.accountId}/**`],
options: {
with_block_height: true,
},
})
.then((response) => {
let blockHeight = response[context.accountId]["post"][":block"];
repostOnDiscussions(blockHeight);
})
.catch(console.log);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good on processing user discussions!

},
});
// TODO remove
console.log("result", result);
}

return (
<div className="w-100" style={{ maxWidth: "100%" }}>
<Container className="d-flex gap-3 m-3 pl-2">
<MainContent className="max-width-100">
<div className="d-flex flex-column gap-4">
{context.accountId && (
<div className="card p-4">
<Widget
src={"${REPL_DEVHUB}/widget/devhub.entity.community.Compose"}
props={{
onSubmit: setSocialDbAndRepost,
}}
/>
</div>
)}
<div className="d-flex flex-wrap justify-content-between">
<Heading>Discussions</Heading>
<div className="d-flex align-items-center gap-2">
<select
name="sort"
id="sort"
class="form-select"
value={sort}
onChange={(e) => {
setSort(e.target.value);
}}
>
<option selected value="timedesc">
Latest
</option>
<option value="recentcommentdesc">Last Commented</option>
</select>
</div>
</div>
<Widget
src="${REPL_DEVHUB}/widget/devhub.components.organism.Feed"
props={{
showFlagAccountFeature: true,
action: "repost",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is mostly a copy of the Announcements.jsx feed only difference is that it looks for repost instead of post. And the Compose component call createDiscussion in the devhub-contract.

filteredAccountIds: [
`discussions.${handle}.community.${REPL_DEVHUB_CONTRACT}`,
],
sort: sort,
}}
/>
</div>
</MainContent>
<SidebarContainer>
<div className="d-flex flex-column gap-3">
<div className="card p-4">
<div className="mb-2">{communityData?.description}</div>
<div className="d-flex gap-2 flex-wrap">
<Tag>{communityData?.tag} </Tag>
</div>
</div>
<div className="card p-4 d-flex flex-column gap-2">
<SubHeading>Community Admins</SubHeading>
{(communityData?.admins ?? []).map((accountId) => (
<div
key={accountId}
className="d-flex"
style={{ fontWeight: 500 }}
>
<Widget
src="${REPL_DEVHUB}/widget/devhub.components.molecule.ProfileCard"
props={{ accountId }}
/>
</div>
))}
</div>
</div>
</SidebarContainer>
</Container>
</div>
);
7 changes: 7 additions & 0 deletions src/devhub/page/community/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ const tabs = [
handle: community.handle,
},
},
{
title: "Discussions",
view: "${REPL_DEVHUB}/widget/devhub.entity.community.Discussions",
params: {
handle: community.handle,
},
},
{
title: "Activity",
view: "${REPL_DEVHUB}/widget/devhub.entity.community.Activity",
Expand Down
Loading