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

fix: confirmation only for add/edit post #216

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 25 additions & 1 deletion module/core/lib/draftstate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
const DRAFT_STATE_STORAGE_KEY = "POST_DRAFT_STATE";
let is_edit_or_add_post_transaction = false;
let transaction_method_name;

if (props.transactionHashes) {
Storage.privateSet(DRAFT_STATE_STORAGE_KEY, undefined);
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";

if (is_edit_or_add_post_transaction) {
Storage.privateSet(DRAFT_STATE_STORAGE_KEY, undefined);
}
}

const onDraftStateChange = (draftState) =>
Expand Down
31 changes: 28 additions & 3 deletions src/gigs-board/entity/post/List.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,32 @@ function href(widgetName, linkProps) {

/* 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) {
Storage.privateSet(DRAFT_STATE_STORAGE_KEY, undefined);
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";

if (is_edit_or_add_post_transaction) {
Storage.privateSet(DRAFT_STATE_STORAGE_KEY, undefined);
}
}

const onDraftStateChange = (draftState) =>
Expand Down Expand Up @@ -438,9 +462,10 @@ const Head =
return (
<>
{Head}
{props.transactionHashes ? (
{is_edit_or_add_post_transaction ? (
<p class="text-secondary mt-4">
Post submitted successfully. Back to{" "}
Post {transaction_method_name == "edit_post" ? "edited" : "added"}{" "}
successfully. Back to{" "}
<a
style={{
color: "#3252A6",
Expand Down
31 changes: 28 additions & 3 deletions src/gigs-board/pages/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,32 @@ function href(widgetName, linkProps) {

/* 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) {
Storage.privateSet(DRAFT_STATE_STORAGE_KEY, undefined);
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";

if (is_edit_or_add_post_transaction) {
Storage.privateSet(DRAFT_STATE_STORAGE_KEY, undefined);
}
}

const onDraftStateChange = (draftState) =>
Expand All @@ -66,10 +90,11 @@ try {
} catch (e) {}
/* END_INCLUDE: "core/lib/draftstate" */

if (props.transactionHashes) {
if (is_edit_or_add_post_transaction) {
return (
<p class="text-secondary">
Post submitted successfully. Back to{" "}
Post {transaction_method_name == "edit_post" ? "edited" : "added"}{" "}
successfully. Back to{" "}
<a
style={{
color: "#3252A6",
Expand Down