diff --git a/src/common/app.tsx b/src/common/app.tsx index 7fb8b38dbf0..51ad4560c3e 100644 --- a/src/common/app.tsx +++ b/src/common/app.tsx @@ -35,7 +35,6 @@ import { useGetAccountFullQuery } from "./api/queries"; import { UIManager } from "@ui/core"; import defaults from "./constants/defaults.json"; import { getAccessToken } from "./helper/user-token"; -import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; // Define lazy pages const ProfileContainer = loadable(() => import("./pages/profile-functional")); @@ -118,7 +117,7 @@ const App = (props: any) => { {/*Excluded from production*/} - + {/**/} format(poll.endTime, "dd.MM.yyyy HH:mm"), [poll.endTime]); const isFinished = useMemo(() => isBefore(poll.endTime, new Date()), [poll.endTime]); const showViewVotes = useMemo( - () => poll.hideVotes && !resultsMode, + () => !poll.hideVotes && !resultsMode, [poll.hideVotes, resultsMode] ); const showChangeVote = useMemo( @@ -49,8 +49,8 @@ export function PollWidget({ poll, isReadOnly, entry }: Props) { [resultsMode, poll.voteChange, pollDetails.data?.status] ); const showVote = useMemo( - () => pollDetails.data?.status === "Active" && !resultsMode, - [pollDetails.data?.status, resultsMode] + () => pollDetails.data?.status === "Active" && !resultsMode && pollDetails.data?.poll_trx_id, + [pollDetails.data?.status, resultsMode, pollDetails.data?.poll_trx_id] ); const isInterpretationSelectionDisabled = useMemo( () => pollDetails.data?.poll_stats.total_hive_hp_incl_proxied === null, @@ -85,6 +85,12 @@ export function PollWidget({ poll, isReadOnly, entry }: Props) { } }, [pollDetails.data, isInterpretationSelectionDisabled]); + useEffect(() => { + if (!pollDetails.data?.poll_trx_id) { + setTimeout(() => pollDetails.refetch(), 5000); + } + }, [pollDetails.data?.poll_trx_id]); + return (
@@ -137,24 +143,25 @@ export function PollWidget({ poll, isReadOnly, entry }: Props) { /> ) )} - {resultsMode && ( -
-
{_t("polls.interpretation")}
- ) => - setInterpretation(e.target.value as PollSnapshot["interpretation"]) - } - > - - - -
- )} + {resultsMode && + activeUser?.username === entry?.author && + !isInterpretationSelectionDisabled && ( +
+
{_t("polls.interpretation")}
+ ) => + setInterpretation(e.target.value as PollSnapshot["interpretation"]) + } + > + + + +
+ )}
{showVote && ( + )} {showChangeVote && ( )} - {showViewVotes && ( + {!resultsMode && ( )} - {resultsMode && } + {resultsMode && showViewVotes && }
); diff --git a/src/common/features/polls/utils/build-poll-json-metadata.ts b/src/common/features/polls/utils/build-poll-json-metadata.ts deleted file mode 100644 index ba0840847cb..00000000000 --- a/src/common/features/polls/utils/build-poll-json-metadata.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { PollSnapshot } from "../components"; -import { MetaData } from "../../../api/operations"; - -export function buildPollJsonMetadata(poll: PollSnapshot) { - return { - content_type: "poll", - version: 0.6, - question: poll.title, - choices: poll.choices, - preferred_interpretation: poll.interpretation, - token: null, - hide_votes: poll.hideVotes, - vote_change: poll.voteChange, - filters: { - account_age: poll.filters.accountAge - }, - end_time: poll.endTime.getTime() / 1000 - } as MetaData; -} diff --git a/src/common/features/polls/utils/index.ts b/src/common/features/polls/utils/index.ts deleted file mode 100644 index a0f97d81962..00000000000 --- a/src/common/features/polls/utils/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./build-poll-json-metadata"; diff --git a/src/common/helper/temp-entry.ts b/src/common/helper/temp-entry.ts index 79774456f58..6f60ca4341b 100644 --- a/src/common/helper/temp-entry.ts +++ b/src/common/helper/temp-entry.ts @@ -1,9 +1,7 @@ import moment from "moment"; import { FullAccount } from "../store/accounts/types"; -import { Entry } from "../store/entries/types"; - -import accountReputation from "./account-reputation"; +import { Entry, JsonMetadata } from "../store/entries/types"; import { version } from "../../../package.json"; @@ -17,6 +15,7 @@ export interface TempEntryProps { description: string | null; tags: string[]; post_id?: string; + jsonMeta?: JsonMetadata; } export const correctIsoDate = (d: string): string => d.split(".")[0]; @@ -41,7 +40,7 @@ export default (p: TempEntryProps): Entry => { curator_payout_value: "0.000 HBD", depth: 0, is_paidout: false, - json_metadata: { + json_metadata: p.jsonMeta ?? { app: `ecency/${version}-vision`, format: "markdown+html", tags: p.tags, diff --git a/src/common/i18n/locales/en-US.json b/src/common/i18n/locales/en-US.json index fd35a2951c5..643e96f9024 100644 --- a/src/common/i18n/locales/en-US.json +++ b/src/common/i18n/locales/en-US.json @@ -2452,6 +2452,7 @@ "current-standing": "Hide votes", "finished": "Finished", "expired-date": "End date should be in present or future", - "interpretation": "Interpretation" + "interpretation": "Interpretation", + "creating-in-progress": "Creating in progress..." } } diff --git a/src/common/pages/submit/api/publish.ts b/src/common/pages/submit/api/publish.ts index a4d4eb8866e..eccdf3fcfce 100644 --- a/src/common/pages/submit/api/publish.ts +++ b/src/common/pages/submit/api/publish.ts @@ -1,4 +1,4 @@ -import { useMutation } from "@tanstack/react-query"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; import { FullAccount } from "../../../store/accounts/types"; import { createPermlink, makeApp, makeCommentOptions } from "../../../helper/posting"; import * as bridgeApi from "../../../api/bridge"; @@ -19,16 +19,19 @@ import { History } from "history"; import { useMappedStore } from "../../../store/use-mapped-store"; import { useThreeSpeakManager } from "../hooks"; import { useContext } from "react"; -import { EntriesCacheContext } from "../../../core"; +import { EntriesCacheContext, QueryIdentifiers } from "../../../core"; import { version } from "../../../../../package.json"; import { PollsContext } from "../hooks/polls-manager"; import { EntryBodyManagement, EntryMetadataManagement } from "../../../features/entry-management"; +import { Entry } from "../../../store/entries/types"; +import { GetPollDetailsQueryResponse } from "../../../features/polls/api"; export function usePublishApi(history: History, onClear: () => void) { const { activeUser } = useMappedStore(); const { activePoll, clearActivePoll } = useContext(PollsContext); const { videos, isNsfw, buildBody } = useThreeSpeakManager(); const { updateCache } = useContext(EntriesCacheContext); + const queryClient = useQueryClient(); return useMutation( ["publish"], @@ -60,7 +63,7 @@ export function usePublishApi(history: History, onClear: () => void) { // make sure active user fully loaded if (!activeUser || !activeUser.data.__loaded) { - return; + return []; } const author = activeUser.username; @@ -140,7 +143,8 @@ export function usePublishApi(history: History, onClear: () => void) { title, body: buildBody(body), tags, - description + description, + jsonMeta }), max_accepted_payout: options.max_accepted_payout, percent_hbd: options.percent_hbd @@ -163,8 +167,44 @@ export function usePublishApi(history: History, onClear: () => void) { if (isCommunity(tags[0]) && reblogSwitch) { await reblog(author, author, permlink); } + + return [entry as Entry, activePoll] as const; } catch (e) { error(...formatError(e)); + throw e; + } + }, + { + onSuccess([entry, poll]) { + queryClient.setQueryData( + [QueryIdentifiers.POLL_DETAILS, entry?.author, entry?.permlink], + (data) => { + if (!data) { + return data; + } + + return { + author: entry.author, + created: new Date().toISOString(), + end_time: poll?.endTime.toISOString(), + filter_account_age_days: poll?.filters.accountAge, + permlink: entry.permlink, + poll_choices: poll?.choices.map((c, i) => ({ + choice_num: i, + choice_text: c, + votes: null + })), + poll_stats: { total_voting_accounts_num: 0, total_hive_hp_incl_proxied: null }, + poll_trx_id: undefined, + poll_voters: undefined, + preferred_interpretation: poll?.interpretation, + question: poll?.title, + status: "active", + tags: [], + token: null + } as unknown as GetPollDetailsQueryResponse; + } + ); } } );