diff --git a/layouts/nav/post-nav.tsx b/layouts/nav/post-nav.tsx index d60113bd..3dafc945 100644 --- a/layouts/nav/post-nav.tsx +++ b/layouts/nav/post-nav.tsx @@ -32,7 +32,7 @@ function PostNav(props:Props) { useEffect(() => { if (post) { - requestApi.get(`/interaction/followed/${post.id}`).then(res => setFollowed(res.data)) + requestApi.get(`/interaction/followed/${post.creator.id}`).then(res => setFollowed(res.data)) } }, []) @@ -50,7 +50,7 @@ function PostNav(props:Props) { Sunface的博客 - {followed !== null && } + {followed !== null && } diff --git a/pages/[username]/index.tsx b/pages/[username]/index.tsx index c8fd43bf..f7eb62a0 100644 --- a/pages/[username]/index.tsx +++ b/pages/[username]/index.tsx @@ -22,27 +22,61 @@ import Posts from "components/story/posts" import Link from "next/link" import Empty from "components/empty" import Count from "components/count" +import { Tag } from "src/types/tag" const UserPage = () => { const router = useRouter() const username = router.query.username const session = useSession() const [user, setUser]: [User, any] = useState(null) + const [rawPosts, setRawPosts]: [Post[], any] = useState([]) const [posts, setPosts]: [Post[], any] = useState([]) + const [tags,setTags]:[Tag[],any] = useState([]) + const [tagFilter,setTagFilter]:[Tag,any] = useState(null) + const borderColor = useColorModeValue('white', 'transparent') useEffect(() => { if (username) { initData(username) + } }, [username]) const initData = async (username) => { const res = await requestApi.get(`/user/info/${username}`) setUser(res.data) + getTags(res.data.id) + const res1 = await requestApi.get(`/user/posts/${res.data.id}`) setPosts(res1.data) + setRawPosts(res1.data) + } + + const getTags = async (userID) => { + const res = await requestApi.get(`/tag/user/${userID}`) + setTags(res.data) } + const filterPostsByTag = tag => { + if (tag.id === tagFilter?.id) { + setTagFilter(null) + setPosts(rawPosts) + return + } + + setTagFilter(tag) + const p = [] + rawPosts.forEach(post => { + for (let i=0;i @@ -61,7 +95,7 @@ const UserPage = () => { {user.nickname} {user.tagline && {user.tagline}} - Followers + Followers Following {session?.user.id === user.id ? @@ -91,7 +125,7 @@ const UserPage = () => { {moment(user.created).fromNow()} - + {user.github && } {user.twitter && } {user.facebook && } @@ -107,7 +141,7 @@ const UserPage = () => { } {user.rawSkills.length > 0 && - My Tech Stack + 擅长技能 { user.rawSkills.map(skill => @@ -120,13 +154,19 @@ const UserPage = () => { } } - {/* - - - 2 posts written - 30 comments written - - */} + + {tags.length > 0 && + 博客标签 + + { + tags.map(tag => + + ) + } + + } @@ -138,7 +178,7 @@ const UserPage = () => { : - + } diff --git a/pages/bookmarks.tsx b/pages/bookmarks.tsx index 8034b0b2..084ac082 100644 --- a/pages/bookmarks.tsx +++ b/pages/bookmarks.tsx @@ -29,7 +29,7 @@ import Empty from "components/empty" const BookmarksPage = () => { - const [filter, setFilter]:[Tag,any] = useState({id:"-1"}) + const [filter, setFilter]:[Tag,any] = useState(null) const [tags, setTags]: [Tag[], any] = useState([]) const [rawPosts,setRawPosts]: [Post[],any] = useState([]) const [posts,setPosts]: [Post[],any] = useState([]) @@ -37,42 +37,45 @@ import Empty from "components/empty" useEffect(() => { getBookmarkPosts() }, []) - - useEffect(() => { - filterPosts() - }, [filter]) const getBookmarkPosts = async() => { const res = await requestApi.get(`/story/bookmark/posts`) setRawPosts(res.data) setPosts(res.data) - const ts = [{id:-1,title:'All Tags',icon: 'https://cdn.hashnode.com/res/hashnode/image/upload/v1605105898259/3vuMFM8qM.png?w=200&h=200&fit=crop&crop=entropy&auto=compress&auto=compress'}] + const ts = [] res.data.forEach(post => { - post.rawTags?.forEach(tag => { - if (!find(ts, t => t.id === tag.id)) { - ts.push(tag) - } - }) + for (let i=0;i t.id === tag.id)) { + ts.push(tag) + break + } + } }) setTags(ts) } - const filterPosts = () => { - if (filter.id === "-1") { - setPosts(rawPosts) - return + const filterPostsByTag = (t:Tag) => { + if (t.id === filter?.id) { + setPosts(rawPosts) + setFilter(null) + return } + const newPosts = [] rawPosts.forEach(post => { - post.rawTags?.forEach(tag => { - if (tag.id === filter.id) { - newPosts.push(post) - } - }) + for (let i=0;i { tags.map(t => - setFilter(t)}> + filterPostsByTag(t)}> {t.title} ) diff --git a/pages/settings/profile.tsx b/pages/settings/profile.tsx index 77c7ada9..12b6df0f 100644 --- a/pages/settings/profile.tsx +++ b/pages/settings/profile.tsx @@ -201,15 +201,6 @@ const UserProfilePage = () => { )} - - {({ field, form }) => ( - - 自我介绍 -