This commit is contained in:
tonyrewin 2022-10-05 11:57:58 +03:00
commit 6bb82d7492
6 changed files with 69 additions and 66 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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