Skip to content

Commit

Permalink
configures with updated function call
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotBraem committed Dec 28, 2023
1 parent f70467f commit aa7091e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/core/adapter/devhub-contract.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ function getPostsByLabel({ label }) {
);
}

function addCommunityAnnouncement({ handle, data }) {
function setCommunitySocialDB({ handle, data }) {
return (
Near.call("${REPL_DEVHUB_CONTRACT}", "add_community_announcement", {
Near.call("${REPL_DEVHUB_CONTRACT}", "set_community_socialdb", {
handle,
data,
}) ?? null
Expand Down Expand Up @@ -215,6 +215,6 @@ return {
getPost,
getPostsByAuthor,
getPostsByLabel,
addCommunityAnnouncement,
setCommunitySocialDB,
useQuery,
};
11 changes: 4 additions & 7 deletions src/devhub/entity/community/Announcements.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { handle } = props;
const { Feed } = VM.require("devs.near/widget/Module.Feed");
const { getCommunity, addCommunityAnnouncement } = VM.require(
const { getCommunity, setCommunitySocialDB } = VM.require(
"${REPL_DEVHUB}/widget/core.adapter.devhub-contract"
);

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

const communityData = getCommunity({ handle });

Expand Down Expand Up @@ -64,10 +64,7 @@ return (
<Widget
src={"${REPL_DEVHUB}/widget/devhub.entity.community.Compose"}
props={{
optimisticUpdateFn: () => console.log("commit"),
clearOptimisticUpdateFn: () => console.log("clear"),
onSubmit: (v) =>
addCommunityAnnouncement({ handle, data: v }),
onSubmit: (v) => setCommunitySocialDB({ handle, data: v }),
}}
/>
</div>
Expand Down Expand Up @@ -98,7 +95,7 @@ return (
options: {
limit: 10,
order: "desc",
accountId: [`${handle}.communities.devhub.near`],
accountId: [`${handle}.community.${REPL_DEVHUB_CONTRACT}`],
},
cacheOptions: {
ignoreCache: true,
Expand Down
30 changes: 4 additions & 26 deletions src/devhub/entity/community/Compose.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ if (!context.accountId) {
return <></>;
}

const optimisticUpdateFn = props.optimisticUpdateFn;
const clearOptimisticUpdateFn = props.clearOptimisticUpdateFn;

State.init({
image: {},
text: "",
Expand Down Expand Up @@ -81,33 +78,14 @@ function composeData() {
return data;
}

function onCancel() {
if (clearOptimisticUpdateFn) {
clearOptimisticUpdateFn();
}
}

function onPostClick() {
if (optimisticUpdateFn) {
const post = {
account_id: context.accountId,
block_height: "now",
block_timestamp: Date.now() * 1000000,
content,
comments: [],
accounts_liked: [],
};
optimisticUpdateFn(post);
}
}

const handleSubmit = () => {
const data = composeData();
onSubmit(data);
onCancel();
if (props.onSubmit) {
props.onSubmit(data);
}
};

function onCommit() {
function resetState() {
State.update({
image: {},
text: "",
Expand Down

0 comments on commit aa7091e

Please sign in to comment.