Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
carina-akaia committed Nov 10, 2023
1 parent 3050c09 commit fa04850
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 49 deletions.
42 changes: 5 additions & 37 deletions src/devhub/entity/post/List.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,14 @@

const { href } = VM.require("${REPL_DEVHUB}/widget/core.lib.url");

href || (href = () => {});

/* INCLUDE: "core/lib/draftstate" */
const DRAFT_STATE_STORAGE_KEY = "POST_DRAFT_STATE";
let is_edit_or_add_post_transaction = false;
let transaction_method_name;

if (props.transactionHashes) {
const transaction = fetch("https://rpc.mainnet.near.org", {
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: "dontcare",
method: "tx",
params: [props.transactionHashes, context.accountId],
}),
});
transaction_method_name =
transaction?.body?.result?.transaction?.actions[0].FunctionCall.method_name;

is_edit_or_add_post_transaction =
transaction_method_name == "add_post" ||
transaction_method_name == "edit_post";
const { draftState, onDraftStateChange } = VM.require(
"${REPL_DEVHUB}/widget/devhub.entity.post.draft"
);

if (is_edit_or_add_post_transaction) {
Storage.privateSet(DRAFT_STATE_STORAGE_KEY, undefined);
}
if (!href) {
return <p>Loading modules...</p>;
}

const onDraftStateChange = (draftState) =>
Storage.privateSet(DRAFT_STATE_STORAGE_KEY, JSON.stringify(draftState));
let draftState;
try {
draftState = JSON.parse(Storage.privateGet(DRAFT_STATE_STORAGE_KEY));
} catch (e) {}
/* END_INCLUDE: "core/lib/draftstate" */

const QUERYAPI_ENDPOINT = `https://near-queryapi.api.pagoda.co/v1/graphql/`;

const queryName =
Expand Down
8 changes: 4 additions & 4 deletions src/devhub/entity/post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
const { href } = VM.require("${REPL_DEVHUB}/widget/core.lib.url");

const { draftState, onDraftStateChange } = VM.require(
"${REPL_DEVHUB}/widget/entity.post.draft"
"${REPL_DEVHUB}/widget/devhub.entity.post.draft"
);

href || (href = () => {});
if (!href) {
return <p>Loading modules...</p>;
}

const ButtonWithHover = styled.button`
background-color: #fff;
Expand All @@ -26,8 +28,6 @@ if (!post) {
return <div>Loading ...</div>;
}

console.log({ onDraftStateChange });

const referral = props.referral;
const currentTimestamp = props.timestamp ?? post.snapshot.timestamp;
const compareTimestamp = props.compareTimestamp ?? "";
Expand Down
2 changes: 1 addition & 1 deletion src/devhub/entity/post/draft.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ try {
draftState = JSON.parse(Storage.privateGet(DRAFT_STATE_STORAGE_KEY));
} catch (e) {}

return { draftState, onDraftStateChange };
return { DRAFT_STATE_STORAGE_KEY, draftState, onDraftStateChange };
17 changes: 10 additions & 7 deletions src/devhub/page/create.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
const { href } = VM.require("${REPL_DEVHUB}/widget/core.lib.url");

if (!href) {
return <p>Loading modules...</p>;
}

/* INCLUDE: "core/lib/autocomplete" */
const autocompleteEnabled = true;

Expand Down Expand Up @@ -35,7 +29,16 @@ function autoCompleteAccountId(id) {
}
/* END_INCLUDE: "core/lib/autocomplete" */

const DRAFT_STATE_STORAGE_KEY = "DRAFT_STATE";
const { href } = VM.require("${REPL_DEVHUB}/widget/core.lib.url");

const { DRAFT_STATE_STORAGE_KEY, draftState, onDraftStateChange } = VM.require(
"${REPL_DEVHUB}/widget/devhub.entity.post.draft"
);

if (!href) {
return <p>Loading modules...</p>;
}

const parentId = props.parentId ?? null;
const postId = props.postId ?? null;
const mode = props.mode ?? "Create";
Expand Down

0 comments on commit fa04850

Please sign in to comment.