Merge pull request #24 from Discours/author-page-fix

author page fixes
This commit is contained in:
Igor Lobanov 2022-10-04 14:49:42 +02:00 committed by GitHub
commit b9fab7fde3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 66 deletions

View File

@ -22,11 +22,8 @@ interface AuthorCardProps {
export const AuthorCard = (props: AuthorCardProps) => {
const { session } = useAuthStore()
const subscribed = createMemo(
() =>
!!session()
?.news?.authors?.filter((u) => u === props.author.slug)
.pop()
const subscribed = createMemo<boolean>(
() => session()?.news?.authors?.some((u) => u === props.author.slug) || false
)
const canFollow = createMemo(() => !props.hideFollow && session()?.user?.slug !== props.author.slug)
const bio = () => props.author.bio || t('Our regular contributor')
@ -37,8 +34,6 @@ export const AuthorCard = (props: AuthorCardProps) => {
}
// TODO: reimplement AuthorCard
return (
<>
<Show when={props.author?.slug}>
<div class="author">
<Userpic user={props.author} hasLink={props.hasLink} />
@ -81,13 +76,11 @@ export const AuthorCard = (props: AuthorCardProps) => {
{t('Write')}
</button>
<For each={props.author.links}>{(link: string) => <a href={link} />}</For>
<For each={props.author.links}>{(link) => <a href={link} />}</For>
</Show>
</div>
</Show>
</div>
</div>
</Show>
</>
)
}

View File

@ -4,7 +4,6 @@ import './Full.scss'
export default (props: { author: Author }) => {
return (
<>
<div class="container">
<div class="row">
<div class="user-details">
@ -12,6 +11,5 @@ export default (props: { author: Author }) => {
</div>
</div>
</div>
</>
)
}

View File

@ -26,6 +26,8 @@ export default gql`
_id: slug
name
slug
bio
links
userpic
}
createdAt

View File

@ -4,7 +4,7 @@ import '../styles/app.scss'
import { t } from '../utils/intl'
const lang = Astro.url.searchParams.get('lang') || 'ru'
console.log('[layout] server locale is', lang)
// console.log('[layout] server locale is', lang)
setLocale(lang)
---

View File

@ -19,25 +19,26 @@ const [topicsByAuthor, setTopicByAuthor] = createSignal<{ [authorSlug: string]:
const sortedTopics = createLazyMemo<Topic[]>(() => {
const topics = Object.values(topicEntities())
const sortAllByValue = sortAllBy()
switch (sortAllByValue) {
case 'created': {
switch (sortAllBy()) {
case 'created':
// log.debug('sorted by created')
topics.sort(byCreated)
break
}
case 'shouts':
// log.debug(`sorted by shouts`)
topics.sort(byTopicStatDesc('shouts'))
break
case 'authors':
// log.debug(`sorted by ${sortBy}`)
topics.sort(byTopicStatDesc(sortAllByValue))
// log.debug(`sorted by authors`)
topics.sort(byTopicStatDesc('authors'))
break
case 'title':
// log.debug('sorted by title')
topics.sort((a, b) => a.title.localeCompare(b.title))
break
default:
log.error(`Unknown sort: ${sortAllByValue}`)
log.error(`Unknown sort: ${sortAllBy()}`)
}
return topics

View File

@ -221,13 +221,22 @@ export const apiClient = {
},
getAllTopics: async () => {
const response = await publicGraphQLClient.query(topicsAll, {}).toPromise()
if (response.error) {
log.debug('getAllTopics', response.error)
}
return response.data.topicsAll
},
getAllAuthors: async () => {
const response = await publicGraphQLClient.query(authorsAll, {}).toPromise()
if (response.error) {
log.debug('getAllAuthors', response.error)
}
return response.data.authorsAll
},
getAuthor: async ({ slug }: { slug: string }) => {
const response = await publicGraphQLClient.query(authorsBySlugs, { slugs: [slug] }).toPromise()
return response.data.getUsersBySlugs
},
getArticle: async ({ slug }: { slug: string }): Promise<Shout> => {
const response = await publicGraphQLClient.query(articleBySlug, { slug }).toPromise()
return response.data?.getShoutBySlug