Skip to content

Commit

Permalink
Use Squid for space/post page
Browse files Browse the repository at this point in the history
  • Loading branch information
olehmell committed Apr 21, 2024
1 parent 4a63204 commit f107fb2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/components/posts/editor/ModalEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ export const PostEditorModalBody = ({
const goToPostPage = (postId: AnyId) => {
const content = getFieldValues() as PostContent
const postData = { struct: { id: postId.toString() }, content }

const url = postUrl({ id: spaceId! }, postData)
router
.push('/[spaceId]/[slug]', postUrl({ id: spaceId! }, postData))
.push('/[spaceId]/[slug]', url + '?source=chain')
.catch(err => log.error(`Failed to redirect to a post page. ${err}`))
}

Expand Down
4 changes: 3 additions & 1 deletion src/components/posts/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ function EditPostForm(props: PostFormProps) {
const goToPostPage = (postId: AnyId) => {
const content = getFieldValues() as PostContent
const postData = { struct: { id: postId.toString() }, content }

const url = postUrl({ id: spaceForPost! }, postData)
router
.push('/[spaceId]/[slug]', postUrl({ id: spaceForPost! }, postData))
.push('/[spaceId]/[slug]', url + '?source=chain')
.catch(err => log.error(`Failed to redirect to a post page. ${err}`))
}

Expand Down
12 changes: 9 additions & 3 deletions src/components/posts/view-post/PostPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { useIsPostBlocked } from 'src/rtk/features/moderation/hooks'
import { fetchPost, fetchPosts, selectPost } from 'src/rtk/features/posts/postsSlice'
import { fetchPostsViewCount } from 'src/rtk/features/posts/postsViewCountSlice'
import { useFetchMyReactionsByPostId } from 'src/rtk/features/reactions/myPostReactionsHooks'
import { asCommentStruct, HasStatusCode, idToBn, PostData, PostWithSomeDetails } from 'src/types'
import { asCommentStruct, DataSourceTypes, HasStatusCode, idToBn, PostData, PostWithSomeDetails } from 'src/types'
import { DfImage } from '../../utils/DfImage'
import { DfMd } from '../../utils/DfMd'
import Section from '../../utils/Section'
Expand Down Expand Up @@ -275,7 +275,7 @@ export async function loadPostOnNextReq({
reduxStore,
}: NextContextWithRedux): Promise<PostWithSomeDetails & HasStatusCode> {
const {
query: { slug },
query: { slug, source },
res,
asPath,
} = context
Expand All @@ -290,7 +290,13 @@ export async function loadPostOnNextReq({
async function getPost() {
const replyIds = await blockchain.getReplyIdsByPostId(idToBn(postId!))
const ids = replyIds.concat(postId!)
await dispatch(fetchPosts({ api: subsocial, ids, reload: true, eagerLoadHandles: true }))
await dispatch(fetchPosts({
api: subsocial,
ids,
reload: true,
eagerLoadHandles: true,
dataSource: source === 'chain' ? DataSourceTypes.CHAIN : DataSourceTypes.SQUID
}))
}
await Promise.all([getPost(), dispatch(fetchBlockedResources({ appId }))])
const postData = selectPost(reduxStore.getState(), { id: postId })
Expand Down
4 changes: 2 additions & 2 deletions src/components/spaces/helpers/loadSpaceOnNextReq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function loadSpaceOnNextReq(
): Promise<SpaceWithSomeDetails & HasStatusCode> {
const { context, subsocial, dispatch, reduxStore } = props
const { query, res } = context
const { spaceId } = query
const { spaceId, source } = query
const idOrHandle = spaceId as string

try {
Expand All @@ -29,7 +29,7 @@ export async function loadSpaceOnNextReq(
id: idStr,
reload: true,
eagerLoadHandles: true,
dataSource: DataSourceTypes.CHAIN,
dataSource: source === 'chain' ? DataSourceTypes.CHAIN : DataSourceTypes.SQUID,
}),
)
const spaceData = selectSpace(reduxStore.getState(), { id: idStr })
Expand Down
2 changes: 1 addition & 1 deletion src/components/urls/goToPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createNewPostLinkProps } from '../spaces/helpers'
const log = newLogger('Go to page')

export function goToSpacePage(spaceId: AnyId, isFirstSpace?: boolean) {
const params = isFirstSpace ? '?isFirst' : ''
const params = `?source=chain${isFirstSpace ? '&isFirst' : ''}`

Router.push('/[spaceId]', `/${spaceId.toString()}${params}`).catch(err =>
log.error('Failed to redirect to "View Space" page:', err),
Expand Down
2 changes: 1 addition & 1 deletion src/rtk/features/contents/contentsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const fetchContents = createAsyncThunk<
unknownFlagAttr: 'isOverview',
},
getData: async ({ api, newIds }) => {
const timeoutMs = 10_000
const timeoutMs = 3_000
let contents = await api.ipfs.getContentArray(newIds as string[], timeoutMs)
return Object.entries(contents)
.map(([id, content]) => {
Expand Down

0 comments on commit f107fb2

Please sign in to comment.