diff --git a/package.json b/package.json index 5f827604..af841d56 100644 --- a/package.json +++ b/package.json @@ -94,11 +94,12 @@ "@polkadot/ui-assets": "^0.52.0-beta.3", "@subsocial/api": "^0.2.15", "@subsocial/types": "^0.1.29", - "@subsocial/utils": "^0.1.21", + "@subsocial/utils": "^0.1.23", "@zeit/next-css": "^1.0.1", "antd": "^3.25.0", "antd-mobile": "^2.3.1", "axios": "^0.18.0", + "brace": "^0.11.1", "dotenv-webpack": "^1.7.0", "formik": "^1.5.0", "lodash.isempty": "^4.4.0", @@ -108,11 +109,13 @@ "moment-timezone": "^0.5.26", "next": "^9.1.1", "query-string": "^6.2.0", + "react-ace": "^8.1.0", "react-beautiful-dnd": "^13.0.0", "react-device-detect": "^1.11.14", "react-markdown": "^4.0.6", "react-router-hash-link": "^1.2.2", "react-tooltip": "^3.9.2", + "react-twitter-widgets": "^1.7.1", "store": "^2.0.12", "strip-markdown": "^3.0.3", "tsconfig-paths-webpack-plugin": "^3.2.0", diff --git a/public/play_youtube.png b/public/play_youtube.png new file mode 100644 index 00000000..c2157f40 Binary files /dev/null and b/public/play_youtube.png differ diff --git a/src/components/blogs/EditBlog.tsx b/src/components/blogs/EditBlog.tsx index efacb2d0..1ec9557c 100644 --- a/src/components/blogs/EditBlog.tsx +++ b/src/components/blogs/EditBlog.tsx @@ -120,7 +120,7 @@ const InnerForm = (props: FormProps) => { return (<> -
+
diff --git a/src/components/blogs/ViewBlog.tsx b/src/components/blogs/ViewBlog.tsx index ad9ae116..f4911851 100644 --- a/src/components/blogs/ViewBlog.tsx +++ b/src/components/blogs/ViewBlog.tsx @@ -33,6 +33,7 @@ import { Blog } from '@subsocial/types/substrate/interfaces'; import { BlogData, ExtendedPostData } from '@subsocial/types/dto' import { getSubsocialApi } from '../utils/SubsocialConnect'; import ViewTags from '../utils/ViewTags'; +import { BlockValueWithOptions } from '../types'; const log = newLogger('View blog') @@ -238,8 +239,8 @@ export const ViewBlogPage: NextPage = (props: Props) => { return - } + renderItem={(item: any, index) => + } noDataDesc='No posts yet' noDataExt={isMyBlog ? : null} />; @@ -272,7 +273,7 @@ export const ViewBlogPage: NextPage = (props: Props) => { ); return
-
+
{renderPreview()} @@ -298,9 +299,10 @@ export const ViewBlogPage: NextPage = (props: Props) => { ViewBlogPage.getInitialProps = async (props): Promise => { const { res, query: { blogId } } = props const subsocial = await getSubsocialApi() - const { substrate } = subsocial; + const { substrate, ipfs } = subsocial; const idOrHandle = blogId as string const id = await getBlogId(idOrHandle) + if (!id && res) { res.statusCode = 404 return { statusCode: 404 } @@ -313,7 +315,28 @@ ViewBlogPage.getInitialProps = async (props): Promise => { } const postIds = await substrate.postIdsByBlogId(new BN(blogId as string)) - const posts = await subsocial.findPostsWithExt(postIds.reverse()); + const posts: any = await subsocial.findPostsWithExt(postIds.reverse()); + + let i = 0; + for (const item of posts) { + const postBlockValues = [] + const blocks = item?.post?.content?.blocks + + if (blocks && blocks.length > 0) { + + for (const x of blocks) { + if (x.featured) { + const res = await ipfs.findPost(x.cid) as unknown as BlockValueWithOptions + if (x.featured && res) res.featured = true + postBlockValues.push(res) + } + } + } + posts[i].blockValues = postBlockValues + i++ + } + + console.log('posts in initialProps in ViewBlog', posts) return { blogData, posts diff --git a/src/components/posts/EditComment.tsx b/src/components/posts/EditComment.tsx index 4083d5f1..e95b08f3 100644 --- a/src/components/posts/EditComment.tsx +++ b/src/components/posts/EditComment.tsx @@ -137,7 +137,7 @@ const InnerForm = (props: FormProps) => { name='body' value={body} onChange={(data: string) => setFieldValue('body', data)} - className={`DfMdEditor ${errors['body'] && 'error'}`} + className={`DfMdEditor ${errors['body'] && 'error'} markdown-body CommentsEditor`} style={{ marginTop: '1rem' }} option={{ autofocus: autoFocus, diff --git a/src/components/posts/EditPost.tsx b/src/components/posts/EditPost.tsx deleted file mode 100644 index 36874cbc..00000000 --- a/src/components/posts/EditPost.tsx +++ /dev/null @@ -1,377 +0,0 @@ -import React, { useState, useEffect } from 'react'; -import { Button } from 'semantic-ui-react'; -import { Form, Field, withFormik, FormikProps } from 'formik'; -import dynamic from 'next/dynamic'; -import { SubmittableResult } from '@polkadot/api'; -import EditableTagGroup from '../utils/EditableTagGroup' -import { withCalls, withMulti, registry } from '@polkadot/react-api'; - -import { useSubsocialApi } from '../utils/SubsocialApiContext' -import * as DfForms from '../utils/forms'; -import { Null } from '@polkadot/types'; -import { Option } from '@polkadot/types/codec'; -import Section from '../utils/Section'; -import { useMyAccount } from '../utils/MyAccountContext'; -import { socialQueryToProp } from '../utils/index'; -import { getNewIdFromEvent, Loading } from '../utils/utils'; -import BN from 'bn.js'; -import SimpleMDEReact from 'react-simplemde-editor'; -import Router, { useRouter } from 'next/router'; -import HeadMeta from '../utils/HeadMeta'; -import { TxFailedCallback } from '@polkadot/react-components/Status/types'; -import { TxCallback } from '../utils/types'; -import { PostExtension, PostUpdate } from '@subsocial/types/substrate/classes'; -import { Post, IpfsHash, BlogId, PostExtension as IPostExtension } from '@subsocial/types/substrate/interfaces'; -import { PostContent } from '@subsocial/types/offchain'; -import { newLogger } from '@subsocial/utils' -import { ValidationProps, buildValidationSchema } from './PostValidation'; -import { LabeledValue } from 'antd/lib/select'; -import SelectBlogPreview from '../utils/SelectBlogPreview'; -import { Icon } from 'antd'; -import BloggedSectionTitle from '../blogs/BloggedSectionTitle'; - -const log = newLogger('Edit post') -const TxButton = dynamic(() => import('../utils/TxButton'), { ssr: false }); - -type OuterProps = ValidationProps & { - blogId?: BN, - id?: BN, - extension?: IPostExtension, - struct?: Post - json?: PostContent, - onlyTxButton?: boolean, - closeModal?: () => void, - withButtons?: boolean, - myAddress?: string, - blogIds?: BlogId[] -}; - -const DefaultPostExt = new PostExtension({ RegularPost: new Null(registry) }) - -type FormValues = PostContent; - -type FormProps = OuterProps & FormikProps; - -const LabelledField = DfForms.LabelledField(); - -const LabelledText = DfForms.LabelledText(); - -const InnerForm = (props: FormProps) => { - const { - id, - blogId, - struct, - extension = DefaultPostExt, - values, - dirty, - isValid, - errors, - setFieldValue, - isSubmitting, - setSubmitting, - resetForm, - onlyTxButton = false, - withButtons = true, - closeModal, - blogIds - } = props; - - const { isRegularPost } = extension - - const renderResetButton = () => ( -