Skip to content

Commit

Permalink
Merge pull request #2897 from ecency/nt/poll-fix
Browse files Browse the repository at this point in the history
Nt/poll fix
  • Loading branch information
feruzm authored Jul 17, 2024
2 parents f764aaf + 72bb9a5 commit 3a2ab9e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/markdownEditor/children/editorToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export const EditorToolbar = ({

<IconButton
size={18}
style={[styles.rightIcons, !!pollDraft && styles.iconBottomBar]}
style={[styles.rightIcons, !!pollDraft?.title && styles.iconBottomBar]}
iconStyle={styles.icon}
iconType="SimpleLineIcons"
name="chart"
Expand Down
5 changes: 4 additions & 1 deletion src/components/postCard/children/postCardContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ export const PostCardContent = ({
}, [dim.height]);

// featured text can be used to add more labels in future by just inserting text as array item
const _isPollPost = content?.json_metadata?.content_type === ContentType.POLL &&
!!content?.json_metadata?.question;

const _featuredText = [
content?.is_promoted && intl.formatMessage({ id: 'post.promoted' }),
content?.json_metadata?.content_type === ContentType.POLL &&
_isPollPost &&
intl.formatMessage({ id: 'post.poll' }),
]
.filter((i) => !!i)
Expand Down
4 changes: 3 additions & 1 deletion src/components/postCard/children/postCardHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ interface Props {
export const PostCardHeader = ({ intl, content, isHideImage, handleCardInteraction }: Props) => {
const rebloggedBy = get(content, 'reblogged_by[0]', null);
const dateString = useMemo(() => getTimeFromNow(content?.created), [content]);
const _isPollPost = content?.json_metadata?.content_type === ContentType.POLL &&
!!content?.json_metadata?.question

const _handleOnTagPress = (navParams) => {
handleCardInteraction(PostCardActionIds.NAVIGATE, navParams);
Expand Down Expand Up @@ -60,7 +62,7 @@ export const PostCardHeader = ({ intl, content, isHideImage, handleCardInteracti
/>

<View style={styles.headerIconsWrapper}>
{content?.json_metadata?.content_type === ContentType.POLL && (
{_isPollPost && (
<Icon style={styles.pollPostIcon} size={16} name="chart" iconType="SimpleLineIcons" />
)}
{(content?.stats?.is_pinned || content?.stats?.is_pinned_blog) && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/postPoll/container/postPoll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface PostPoll {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const PostPoll = ({ author, permlink, metadata, initMode, compactView }: PostPoll) => {
if (metadata.content_type !== ContentType.POLL) {
if (metadata.content_type !== ContentType.POLL || !metadata.question) {
return null;
}

Expand Down
8 changes: 5 additions & 3 deletions src/screens/editor/container/editorContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ class EditorContainer extends Component<EditorContainerProps, any> {
const { draftId } = this.state;
const { pollDraftsMap } = this.props;

return pollDraftsMap[draftId || DEFAULT_USER_DRAFT_ID] || null;
return pollDraftsMap[draftId || DEFAULT_USER_DRAFT_ID];
};

_saveDraftToDB = async (fields, saveAsNew = false) => {
Expand Down Expand Up @@ -555,10 +555,12 @@ class EditorContainer extends Component<EditorContainerProps, any> {
(item) => item.account !== currentAccount.username,
); // remove default beneficiary from array while saving
dispatch(setBeneficiaries(_resDraft._id, filteredBeneficiaries));
dispatch(setPollDraftAction(_resDraft._id, pollDraft));

// TODO: assess if need to set poll meta here as well
if(pollDraft){
dispatch(setPollDraftAction(_resDraft._id, pollDraft));
}

// TODO: assess if need to set poll meta here as well
dispatch(removeEditorCache(DEFAULT_USER_DRAFT_ID));

// clear local copy if darft save is successful
Expand Down
12 changes: 9 additions & 3 deletions src/utils/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ export const extractMetadata = async ({
// NOTE: keepting regex to extract usernames as reference for later usage if any
// const userReg = /(^|\s)(@[a-z][-.a-z\d]+[a-z\d])/gim;

let out: PostMetadata = {};
let out: PostMetadata = {
content_type:ContentType.GENERAL
};

const mUrls = extractUrls(body);
const matchedImages = [...extractImageUrls({ urls: mUrls }), ...(videoThumbUrls || [])];

Expand Down Expand Up @@ -316,17 +319,20 @@ export const extractMetadata = async ({
}

if (pollDraft && pollDraft.title) {
// TODO convert draft poll to poll meta here

//TODO: added poll validity checks

//convert draft poll to poll meta here
const _pollMeta = convertToPollMeta(pollDraft);
out = {
...out,
..._pollMeta,
content_type:ContentType.POLL
};
}

// setting post type, primary usecase for separating waves from other posts
out.type = postType || PostTypes.POST;
out.content_type = pollDraft ? ContentType.POLL : ContentType.GENERAL;

return out;
};
Expand Down

0 comments on commit 3a2ab9e

Please sign in to comment.