Skip to content

Commit

Permalink
feat: decode encoding hash
Browse files Browse the repository at this point in the history
  • Loading branch information
juliopavila committed May 27, 2024
1 parent b7fb29e commit 0cc21d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
18 changes: 7 additions & 11 deletions packages/app/src/components/layout/PublicationHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from "react"
import React, { useEffect, useMemo, useRef, useState } from "react"
import { Box, Button, Container, Grid, styled, Typography } from "@mui/material"
import { WalletBadge } from "@/components/commons/WalletBadge"
import { Publication } from "@/models/publication"
Expand All @@ -11,12 +11,13 @@ import { INITIAL_ARTICLE_VALUE, useArticleContext } from "@/services/publication
import { UserOptions } from "@/components/commons/UserOptions"
// import { useOnClickOutside } from "@/hooks/useOnClickOutside"
import { Edit } from "@mui/icons-material"
// import isIPFS from "is-ipfs"
import isIPFS from "is-ipfs"
// import { useIpfs } from "@/hooks/useIpfs"
import Avatar from "@/components/commons/Avatar"
// import { processArticleContent } from "@/utils/modifyHTML"
import { useWeb3Modal, useWeb3ModalAccount } from "@web3modal/ethers5/react"
import { addUrlToImageHashes } from "@/services/publications/utils/article-method"
import { useIPFSContext } from "@/services/ipfs/context"

type Props = {
articleId?: string
Expand All @@ -34,7 +35,6 @@ const ItemContainer = styled(Grid)({
},
})
const PublicationHeader: React.FC<Props> = ({ publication, showCreatePost, showEditButton }) => {
// const ipfs = useIpfs()
const { publicationSlug } = useParams<{ publicationSlug: string }>()
const { address, isConnected } = useWeb3ModalAccount()
const navigate = useNavigate()
Expand All @@ -51,17 +51,12 @@ const PublicationHeader: React.FC<Props> = ({ publication, showCreatePost, showE
} = useArticleContext()
const { open } = useWeb3Modal()
const { refetch } = usePublication(publicationSlug || "")
const { decodeIpfsHash } = useIPFSContext()
const [show, setShow] = useState<boolean>(false)
const permissions = publication && publication.permissions
// const isValidHash = useMemo(() => article && isIPFS.multihash(article.article), [article])
const isValidHash = useMemo(() => article && isIPFS.multihash(article.article), [article])

const ref = useRef()
// useOnClickOutside(ref, () => {
// if (show) {
// setShow(!show)
// }
// })

const { setValue } = articleFormMethods
useEffect(() => {
if (location.pathname) {
Expand All @@ -81,9 +76,10 @@ const PublicationHeader: React.FC<Props> = ({ publication, showCreatePost, showE

const handleEditNavigation = async () => {
if (article) {
let post = isValidHash ? await decodeIpfsHash(article?.article) : article?.article
setValue("id", article.id)
setValue("title", article.title)
setValue("article", addUrlToImageHashes(article.article))
setValue("article", addUrlToImageHashes(post))
setValue("description", article.description ?? undefined)
setValue("lastUpdated", article.lastUpdated ?? undefined)
setValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { shortTitle } from "@/utils/string-handler"
// import { processArticleContent } from "@/utils/modifyHTML"
import { addUrlToImageHashes } from "@/services/publications/utils/article-method"
import useArticles from "@/services/publications/hooks/useArticles"
import { useIPFSContext } from "@/services/ipfs/context"

const ArticleItemContainer = styled(Box)({
background: palette.grays[50],
Expand Down Expand Up @@ -59,6 +60,7 @@ export const ArticleItem: React.FC<ArticleItemProps> = React.memo(
({ article, couldUpdate, couldDelete, publicationSlug }) => {
const ipfs = useIpfs()
const navigate = useNavigate()
const { decodeIpfsHash } = useIPFSContext()
const { saveArticle, articleEditorState, articleFormMethods } = useArticleContext()
const { setLastPathWithChainName } = usePosterContext()
// const { deleteArticle } = usePoster()
Expand Down Expand Up @@ -135,10 +137,11 @@ export const ArticleItem: React.FC<ArticleItemProps> = React.memo(

const handleEditArticle = async () => {
const post = { ...article }
let articlePost = isValidHash ? await decodeIpfsHash(article?.article) : article?.article
if (article) {
setValue("id", post.id)
setValue("title", post.title)
setValue("article", addUrlToImageHashes(post.article))
setValue("article", addUrlToImageHashes(articlePost))
setValue("description", post.description ?? undefined)
setValue("lastUpdated", post.lastUpdated ?? undefined)
setValue(
Expand Down

0 comments on commit 0cc21d5

Please sign in to comment.