diff --git a/src/devhub/entity/post/List.jsx b/src/devhub/entity/post/List.jsx index 2b56fa313..e2303fa9b 100644 --- a/src/devhub/entity/post/List.jsx +++ b/src/devhub/entity/post/List.jsx @@ -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

Loading modules...

; } -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 = diff --git a/src/devhub/entity/post/Post.jsx b/src/devhub/entity/post/Post.jsx index 34a8733c3..f0f50a394 100644 --- a/src/devhub/entity/post/Post.jsx +++ b/src/devhub/entity/post/Post.jsx @@ -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

Loading modules...

; +} const ButtonWithHover = styled.button` background-color: #fff; @@ -26,8 +28,6 @@ if (!post) { return
Loading ...
; } -console.log({ onDraftStateChange }); - const referral = props.referral; const currentTimestamp = props.timestamp ?? post.snapshot.timestamp; const compareTimestamp = props.compareTimestamp ?? ""; diff --git a/src/devhub/entity/post/draft.jsx b/src/devhub/entity/post/draft.jsx index 019016eb1..6c28793c1 100644 --- a/src/devhub/entity/post/draft.jsx +++ b/src/devhub/entity/post/draft.jsx @@ -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 }; diff --git a/src/devhub/page/create.jsx b/src/devhub/page/create.jsx index 93a9631e8..f77dd4206 100644 --- a/src/devhub/page/create.jsx +++ b/src/devhub/page/create.jsx @@ -1,9 +1,3 @@ -const { href } = VM.require("${REPL_DEVHUB}/widget/core.lib.url"); - -if (!href) { - return

Loading modules...

; -} - /* INCLUDE: "core/lib/autocomplete" */ const autocompleteEnabled = true; @@ -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

Loading modules...

; +} + const parentId = props.parentId ?? null; const postId = props.postId ?? null; const mode = props.mode ?? "Create";