diff --git a/src/components/App.tsx b/src/components/App.tsx index 164eaab7..ebd77789 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -45,6 +45,11 @@ import { EditorProvider } from '../context/editor' // const SomePage = lazy(() => import('./Pages/SomePage')) const pagesMap: Record> = { + author: AuthorPage, + authorComments: AuthorPage, + authorAbout: AuthorPage, + authorFollowing: AuthorPage, + authorFollowers: AuthorPage, inbox: InboxPage, expo: LayoutShoutsPage, connect: ConnectPage, @@ -56,7 +61,6 @@ const pagesMap: Record> = { topics: AllTopicsPage, topic: TopicPage, authors: AllAuthorsPage, - author: AuthorPage, feed: FeedPage, feedMy: FeedPage, feedNotifications: FeedPage, diff --git a/src/components/Author/AuthorCard/AuthorCard.tsx b/src/components/Author/AuthorCard/AuthorCard.tsx index d9980fa6..c4547cf4 100644 --- a/src/components/Author/AuthorCard/AuthorCard.tsx +++ b/src/components/Author/AuthorCard/AuthorCard.tsx @@ -10,7 +10,7 @@ import { useSession } from '../../../context/session' import { ShowOnlyOnClient } from '../../_shared/ShowOnlyOnClient' import { FollowingEntity, Topic } from '../../../graphql/types.gen' import { router, useRouter } from '../../../stores/router' -import { openPage } from '@nanostores/router' +import { openPage, redirectPage } from '@nanostores/router' import { useLocalize } from '../../../context/localize' import { ConditionalWrapper } from '../../_shared/ConditionalWrapper' import { Modal } from '../../Nav/Modal' @@ -38,7 +38,7 @@ type Props = { isNowrap?: boolean class?: string followers?: Author[] - subscriptions?: Array + following?: Array showPublicationsCounter?: boolean } @@ -48,7 +48,7 @@ function isAuthor(value: Author | Topic): value is Author { export const AuthorCard = (props: Props) => { const { t, lang } = useLocalize() - + const { page } = useRouter() const { session, isSessionLoaded, @@ -56,7 +56,7 @@ export const AuthorCard = (props: Props) => { } = useSession() const [isSubscribing, setIsSubscribing] = createSignal(false) - const [subscriptions, setSubscriptions] = createSignal>(props.subscriptions) + const [following, setFollowing] = createSignal>(props.following) const [subscriptionFilter, setSubscriptionFilter] = createSignal('all') const [userpicUrl, setUserpicUrl] = createSignal() @@ -105,17 +105,27 @@ export const AuthorCard = (props: Props) => { } createEffect(() => { - if (props.subscriptions) { + if (props.following) { if (subscriptionFilter() === 'users') { - setSubscriptions(props.subscriptions.filter((s) => 'name' in s)) + setFollowing(props.following.filter((s) => 'name' in s)) } else if (subscriptionFilter() === 'topics') { - setSubscriptions(props.subscriptions.filter((s) => 'title' in s)) + setFollowing(props.following.filter((s) => 'title' in s)) } else { - setSubscriptions(props.subscriptions) + setFollowing(props.following) } } }) + createEffect(() => { + if (page().route === 'authorFollowing') { + showModal('following') + } + }) + + const handleCloseFollowModals = () => { + redirectPage(router, 'author', { slug: props.author.slug }) + } + if (props.isAuthorPage && props.author.userpic.includes('assets.discours.io')) { setUserpicUrl(props.author.userpic.replace('100x', '500x500')) } @@ -201,12 +211,18 @@ export const AuthorCard = (props: Props) => { 0) || - (props.subscriptions && props.subscriptions.length > 0) + (props.following && props.following.length > 0) } >
0}> -
showModal('followers')}> +
{ + redirectPage(router, 'authorFollowers', { slug: props.author.slug }) + showModal('followers') + }} + > {(f) => } @@ -220,9 +236,15 @@ export const AuthorCard = (props: Props) => {
- 0}> -
showModal('subscriptions')}> - + 0}> +
{ + redirectPage(router, 'authorFollowing', { slug: props.author.slug }) + showModal('following') + }} + > + {(f) => { if ('name' in f) { return @@ -233,8 +255,8 @@ export const AuthorCard = (props: Props) => { }}
- {props.subscriptions.length}  - {getNumeralsDeclension(props.subscriptions.length, [ + {props.following.length}  + {getNumeralsDeclension(props.following.length, [ t('subscription'), t('subscription_rp'), t('subscriptions') @@ -344,7 +366,7 @@ export const AuthorCard = (props: Props) => {
- + <>

{t('Followers')}

@@ -370,8 +392,8 @@ export const AuthorCard = (props: Props) => { - - + + <>

{t('Subscriptions')}

    @@ -379,14 +401,14 @@ export const AuthorCard = (props: Props) => { - {props.subscriptions.length} + {props.following.length}
  • - {props.subscriptions.filter((s) => 'name' in s).length} + {props.following.filter((s) => 'name' in s).length}
  • @@ -394,7 +416,7 @@ export const AuthorCard = (props: Props) => { {t('Topics')} - {props.subscriptions.filter((s) => 'title' in s).length} + {props.following.filter((s) => 'title' in s).length}
@@ -402,7 +424,7 @@ export const AuthorCard = (props: Props) => {
- + {(subscription: Author | Topic) => isAuthor(subscription) ? ( { {t('Drafts')}
  • - + {t('Subscriptions')}
  • - - {t('Comments')} - + {t('Comments')}
  • {t('Bookmarks')} diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index 8da07e6a..5370bbf4 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -5,7 +5,7 @@ import { Row2 } from '../../Feed/Row2' import { Row3 } from '../../Feed/Row3' import { useAuthorsStore } from '../../../stores/zine/authors' import { loadShouts, useArticlesStore } from '../../../stores/zine/articles' -import { useRouter } from '../../../stores/router' +import { router, useRouter } from '../../../stores/router' import { restoreScrollPosition, saveScrollPosition } from '../../../utils/scroll' import { splitToPages } from '../../../utils/splitToPages' import styles from './Author.module.scss' @@ -17,15 +17,13 @@ import { Comment } from '../../Article/Comment' import { useLocalize } from '../../../context/localize' import { AuthorRatingControl } from '../../Author/AuthorRatingControl' import { hideModal } from '../../../stores/ui' +import { getPagePath } from '@nanostores/router' type Props = { shouts: Shout[] author: Author authorSlug: string -} - -export type AuthorPageSearchParams = { - by: '' | 'viewed' | 'rating' | 'commented' | 'recent' | 'about' | 'popular' + // route?: 'author' | 'authorComments' | 'authorAbout' | 'authorFollowing' | 'authorFollowers' | string } export const PRERENDERED_ARTICLES_COUNT = 12 @@ -34,9 +32,9 @@ const LOAD_MORE_PAGE_SIZE = 9 export const AuthorView = (props: Props) => { const { t } = useLocalize() const { sortedArticles } = useArticlesStore({ shouts: props.shouts }) - const { searchParams, changeSearchParam } = useRouter() const { authorEntities } = useAuthorsStore({ authors: [props.author] }) + const { page } = useRouter() const author = createMemo(() => authorEntities()[props.authorSlug]) const [isLoadMoreButtonVisible, setIsLoadMoreButtonVisible] = createSignal(false) @@ -79,9 +77,6 @@ export const AuthorView = (props: Props) => { checkBioHeight() - if (!searchParams().by) { - changeSearchParam('by', 'rating') - } if (sortedArticles().length === PRERENDERED_ARTICLES_COUNT) { await loadMore() } @@ -109,14 +104,14 @@ export const AuthorView = (props: Props) => { // return t('Top recent') // }) - const pages = createMemo(() => + const shouts = createMemo(() => splitToPages(sortedArticles(), PRERENDERED_ARTICLES_COUNT, LOAD_MORE_PAGE_SIZE) ) const [commented, setCommented] = createSignal([]) createEffect(async () => { - if (searchParams().by === 'commented') { + if (page().route === 'authorComments') { try { const data = await apiClient.getReactionsBy({ by: { comment: true, createdBy: props.authorSlug } @@ -136,32 +131,27 @@ export const AuthorView = (props: Props) => { author={author()} isAuthorPage={true} followers={followers()} - subscriptions={subscriptions()} + following={subscriptions()} />
    @@ -175,7 +165,7 @@ export const AuthorView = (props: Props) => {
    - +
    @@ -199,7 +189,7 @@ export const AuthorView = (props: Props) => {
    - +
    @@ -213,7 +203,7 @@ export const AuthorView = (props: Props) => {
    - + @@ -234,15 +224,15 @@ export const AuthorView = (props: Props) => { - - {(page) => ( + + {(shout) => ( <> - - - - - - + + + + + + )} diff --git a/src/pages/author.page.server.ts b/src/pages/author.page.server.ts index 635d7abf..479e7fc7 100644 --- a/src/pages/author.page.server.ts +++ b/src/pages/author.page.server.ts @@ -1,7 +1,7 @@ import type { PageContext } from '../renderer/types' import { apiClient } from '../utils/apiClient' import type { PageProps } from './types' -import { PRERENDERED_ARTICLES_COUNT } from '../components/Views/Author/Author' +import { PRERENDERED_ARTICLES_COUNT } from '../components/Views/Author' export const onBeforeRender = async (pageContext: PageContext) => { const { slug } = pageContext.routeParams diff --git a/src/pages/author.page.tsx b/src/pages/author.page.tsx index c0533f19..778396d5 100644 --- a/src/pages/author.page.tsx +++ b/src/pages/author.page.tsx @@ -10,7 +10,6 @@ import { ReactionsProvider } from '../context/reactions' export const AuthorPage = (props: PageProps) => { const { page } = useRouter() - const slug = createMemo(() => page().params['slug'] as string) const [isLoaded, setIsLoaded] = createSignal( diff --git a/src/pages/authorAbout.page.route.ts b/src/pages/authorAbout.page.route.ts new file mode 100644 index 00000000..4bcf9ef3 --- /dev/null +++ b/src/pages/authorAbout.page.route.ts @@ -0,0 +1,4 @@ +import { ROUTES } from '../stores/router' +import { getServerRoute } from '../utils/getServerRoute' + +export default getServerRoute(ROUTES.authorAbout) diff --git a/src/pages/authorComment.page.route.ts b/src/pages/authorComment.page.route.ts new file mode 100644 index 00000000..10ff3029 --- /dev/null +++ b/src/pages/authorComment.page.route.ts @@ -0,0 +1,4 @@ +import { ROUTES } from '../stores/router' +import { getServerRoute } from '../utils/getServerRoute' + +export default getServerRoute(ROUTES.authorComments) diff --git a/src/pages/authorFollowers.page.route.ts b/src/pages/authorFollowers.page.route.ts new file mode 100644 index 00000000..c18a617a --- /dev/null +++ b/src/pages/authorFollowers.page.route.ts @@ -0,0 +1,4 @@ +import { ROUTES } from '../stores/router' +import { getServerRoute } from '../utils/getServerRoute' + +export default getServerRoute(ROUTES.authorFollowers) diff --git a/src/pages/authorFollowing.page.route.ts b/src/pages/authorFollowing.page.route.ts new file mode 100644 index 00000000..a8925f2f --- /dev/null +++ b/src/pages/authorFollowing.page.route.ts @@ -0,0 +1,4 @@ +import { ROUTES } from '../stores/router' +import { getServerRoute } from '../utils/getServerRoute' + +export default getServerRoute(ROUTES.authorFollowing) diff --git a/src/stores/router.ts b/src/stores/router.ts index bd23d7bb..db420959 100644 --- a/src/stores/router.ts +++ b/src/stores/router.ts @@ -16,6 +16,10 @@ export const ROUTES = { topic: '/topic/:slug', authors: '/authors', author: '/author/:slug', + authorComments: '/author/:slug/comments', + authorAbout: '/author/:slug/about', + authorFollowers: '/author/:slug/followers', + authorFollowing: '/author/:slug/following', feed: '/feed', feedMy: '/feed/my', feedNotifications: '/feed/notifications', diff --git a/src/stores/ui.ts b/src/stores/ui.ts index 1477d57d..e385ec34 100644 --- a/src/stores/ui.ts +++ b/src/stores/ui.ts @@ -21,7 +21,7 @@ export type ModalType = | 'editorInsertLink' | 'simplifiedEditorInsertLink' | 'followers' - | 'subscriptions' + | 'following' type WarnKind = 'error' | 'warn' | 'info' @@ -45,7 +45,7 @@ export const MODALS: Record = { editorInsertLink: 'editorInsertLink', simplifiedEditorInsertLink: 'simplifiedEditorInsertLink', followers: 'followers', - subscriptions: 'subscriptions' + following: 'following' } const [modal, setModal] = createSignal(null)