topics page fix

This commit is contained in:
Igor Lobanov 2022-09-29 19:37:21 +02:00
parent 65c7fcfe3d
commit 09b83bf31d
7 changed files with 39 additions and 17 deletions

View File

@ -33,6 +33,7 @@
"@nanostores/persistent": "^0.7.0", "@nanostores/persistent": "^0.7.0",
"@nanostores/router": "^0.7.0", "@nanostores/router": "^0.7.0",
"@nanostores/solid": "^0.3.0", "@nanostores/solid": "^0.3.0",
"@solid-primitives/memo": "^1.0.2",
"axios": "^0.27.2", "axios": "^0.27.2",
"google-translate-api-x": "^10.4.1", "google-translate-api-x": "^10.4.1",
"loglevel": "^1.8.0", "loglevel": "^1.8.0",

View File

@ -8,22 +8,26 @@ import { TopicCard } from '../Topic/Card'
import { session } from '../../stores/auth' import { session } from '../../stores/auth'
import { useStore } from '@nanostores/solid' import { useStore } from '@nanostores/solid'
import '../../styles/AllTopics.scss' import '../../styles/AllTopics.scss'
import { getLogger } from '../../utils/logger'
const log = getLogger('AllTopicsView')
type AllTopicsPageSearchParams = { type AllTopicsPageSearchParams = {
by: 'shouts' | 'authors' | 'title' | '' by: 'shouts' | 'authors' | 'title' | ''
} }
type Props = { type AllTopicsViewProps = {
topics: Topic[] topics: Topic[]
} }
export const AllTopicsView = (props: Props) => { export const AllTopicsView = (props: AllTopicsViewProps) => {
const { getSearchParams, changeSearchParam } = useRouter<AllTopicsPageSearchParams>() const { getSearchParams, changeSearchParam } = useRouter<AllTopicsPageSearchParams>()
const { sortedTopics } = useTopicsStore({ const { sortedTopics } = useTopicsStore({
topics: props.topics, topics: props.topics,
sortBy: getSearchParams().by || 'shouts' sortBy: getSearchParams().by || 'shouts'
}) })
const auth = useStore(session) const auth = useStore(session)
createEffect(() => { createEffect(() => {

View File

@ -324,11 +324,11 @@ export type Query = {
getUserRoles: Array<Maybe<Role>> getUserRoles: Array<Maybe<Role>>
getUsersBySlugs: Array<Maybe<User>> getUsersBySlugs: Array<Maybe<User>>
isEmailUsed: Scalars['Boolean'] isEmailUsed: Scalars['Boolean']
myCandidates: Array<Maybe<Shout>>
reactionsByAuthor: Array<Maybe<Reaction>> reactionsByAuthor: Array<Maybe<Reaction>>
reactionsByShout: Array<Maybe<Reaction>> reactionsByShout: Array<Maybe<Reaction>>
reactionsForShouts: Array<Maybe<Reaction>> reactionsForShouts: Array<Maybe<Reaction>>
recentAll: Array<Maybe<Shout>> recentAll: Array<Maybe<Shout>>
recentCandidates: Array<Maybe<Shout>>
recentCommented: Array<Maybe<Shout>> recentCommented: Array<Maybe<Shout>>
recentPublished: Array<Maybe<Shout>> recentPublished: Array<Maybe<Shout>>
recentReacted: Array<Maybe<Shout>> recentReacted: Array<Maybe<Shout>>
@ -397,11 +397,6 @@ export type QueryIsEmailUsedArgs = {
email: Scalars['String'] email: Scalars['String']
} }
export type QueryMyCandidatesArgs = {
limit: Scalars['Int']
offset: Scalars['Int']
}
export type QueryReactionsByAuthorArgs = { export type QueryReactionsByAuthorArgs = {
limit: Scalars['Int'] limit: Scalars['Int']
offset: Scalars['Int'] offset: Scalars['Int']
@ -425,6 +420,11 @@ export type QueryRecentAllArgs = {
offset: Scalars['Int'] offset: Scalars['Int']
} }
export type QueryRecentCandidatesArgs = {
limit: Scalars['Int']
offset: Scalars['Int']
}
export type QueryRecentCommentedArgs = { export type QueryRecentCommentedArgs = {
limit: Scalars['Int'] limit: Scalars['Int']
offset: Scalars['Int'] offset: Scalars['Int']

View File

@ -6,6 +6,7 @@ import { byStat } from '../../utils/sortby'
import { getLogger } from '../../utils/logger' import { getLogger } from '../../utils/logger'
import { createMemo, createSignal } from 'solid-js' import { createMemo, createSignal } from 'solid-js'
import { createLazyMemo } from '@solid-primitives/memo'
const log = getLogger('articles store') const log = getLogger('articles store')
@ -15,7 +16,7 @@ const [articleEntities, setArticleEntities] = createSignal<{ [articleSlug: strin
const [topArticles, setTopArticles] = createSignal<Shout[]>([]) const [topArticles, setTopArticles] = createSignal<Shout[]>([])
const [topMonthArticles, setTopMonthArticles] = createSignal<Shout[]>([]) const [topMonthArticles, setTopMonthArticles] = createSignal<Shout[]>([])
const articlesByAuthor = createMemo(() => { const articlesByAuthor = createLazyMemo(() => {
return Object.values(articleEntities()).reduce((acc, article) => { return Object.values(articleEntities()).reduce((acc, article) => {
article.authors.forEach((author) => { article.authors.forEach((author) => {
if (!acc[author.slug]) { if (!acc[author.slug]) {
@ -28,7 +29,7 @@ const articlesByAuthor = createMemo(() => {
}, {} as { [authorSlug: string]: Shout[] }) }, {} as { [authorSlug: string]: Shout[] })
}) })
const articlesByTopic = createMemo(() => { const articlesByTopic = createLazyMemo(() => {
return Object.values(articleEntities()).reduce((acc, article) => { return Object.values(articleEntities()).reduce((acc, article) => {
article.topics.forEach((topic) => { article.topics.forEach((topic) => {
if (!acc[topic.slug]) { if (!acc[topic.slug]) {
@ -41,7 +42,7 @@ const articlesByTopic = createMemo(() => {
}, {} as { [authorSlug: string]: Shout[] }) }, {} as { [authorSlug: string]: Shout[] })
}) })
const articlesByLayout = createMemo(() => { const articlesByLayout = createLazyMemo(() => {
return Object.values(articleEntities()).reduce((acc, article) => { return Object.values(articleEntities()).reduce((acc, article) => {
if (!acc[article.layout]) { if (!acc[article.layout]) {
acc[article.layout] = [] acc[article.layout] = []
@ -53,13 +54,13 @@ const articlesByLayout = createMemo(() => {
}, {} as { [layout: string]: Shout[] }) }, {} as { [layout: string]: Shout[] })
}) })
const topViewedArticles = createMemo(() => { const topViewedArticles = createLazyMemo(() => {
const result = Object.values(articleEntities()) const result = Object.values(articleEntities())
result.sort(byStat('viewed')) result.sort(byStat('viewed'))
return result return result
}) })
const topCommentedArticles = createMemo(() => { const topCommentedArticles = createLazyMemo(() => {
const result = Object.values(articleEntities()) const result = Object.values(articleEntities())
result.sort(byStat('commented')) result.sort(byStat('commented'))
return result return result

View File

@ -3,7 +3,8 @@ import type { Author } from '../../graphql/types.gen'
import { byCreated } from '../../utils/sortby' import { byCreated } from '../../utils/sortby'
import { getLogger } from '../../utils/logger' import { getLogger } from '../../utils/logger'
import { createMemo, createSignal } from 'solid-js' import { createSignal } from 'solid-js'
import { createLazyMemo } from '@solid-primitives/memo'
const log = getLogger('authors store') const log = getLogger('authors store')
@ -14,7 +15,7 @@ const [sortAllBy, setSortAllBy] = createSignal<AuthorsSortBy>('created')
const [authorEntities, setAuthorEntities] = createSignal<{ [authorSlug: string]: Author }>({}) const [authorEntities, setAuthorEntities] = createSignal<{ [authorSlug: string]: Author }>({})
const [authorsByTopic, setAuthorsByTopic] = createSignal<{ [topicSlug: string]: Author[] }>({}) const [authorsByTopic, setAuthorsByTopic] = createSignal<{ [topicSlug: string]: Author[] }>({})
const sortedAuthors = createMemo(() => { const sortedAuthors = createLazyMemo(() => {
const authors = Object.values(authorEntities()) const authors = Object.values(authorEntities())
switch (sortAllBy()) { switch (sortAllBy()) {
case 'created': { case 'created': {

View File

@ -3,6 +3,7 @@ import { apiClient } from '../../utils/apiClient'
import type { Topic } from '../../graphql/types.gen' import type { Topic } from '../../graphql/types.gen'
import { byCreated, byTopicStatDesc } from '../../utils/sortby' import { byCreated, byTopicStatDesc } from '../../utils/sortby'
import { getLogger } from '../../utils/logger' import { getLogger } from '../../utils/logger'
import { createLazyMemo } from '@solid-primitives/memo'
const log = getLogger('topics store') const log = getLogger('topics store')
@ -16,8 +17,8 @@ const [topicEntities, setTopicEntities] = createSignal<{ [topicSlug: string]: To
const [randomTopics, setRandomTopics] = createSignal<Topic[]>([]) const [randomTopics, setRandomTopics] = createSignal<Topic[]>([])
const [topicsByAuthor, setTopicByAuthor] = createSignal<{ [authorSlug: string]: Topic[] }>({}) const [topicsByAuthor, setTopicByAuthor] = createSignal<{ [authorSlug: string]: Topic[] }>({})
const sortedTopics = createMemo(() => { const sortedTopics = createLazyMemo<Topic[]>(() => {
const topics = Object.values(topicEntities) const topics = Object.values(topicEntities())
const sortAllByValue = sortAllBy() const sortAllByValue = sortAllBy()
switch (sortAllByValue) { switch (sortAllByValue) {
@ -38,6 +39,7 @@ const sortedTopics = createMemo(() => {
default: default:
log.error(`Unknown sort: ${sortAllByValue}`) log.error(`Unknown sort: ${sortAllByValue}`)
} }
return topics return topics
}) })

View File

@ -2707,6 +2707,14 @@
"@solid-primitives/rootless" "^1.1.3" "@solid-primitives/rootless" "^1.1.3"
"@solid-primitives/utils" "^3.0.2" "@solid-primitives/utils" "^3.0.2"
"@solid-primitives/memo@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@solid-primitives/memo/-/memo-1.0.2.tgz#7a33216e665a94ac85413be206dacf3f295221d0"
integrity sha512-I4BKJAItiRxjR1ngc+gWsdpiz3V79LQdgxxRlFPp3K+8Oi2dolXweDlLKKX5qec8cSuhV99gTfsxEoVBMkzNgQ==
dependencies:
"@solid-primitives/scheduled" "1.0.1"
"@solid-primitives/utils" "^3.0.2"
"@solid-primitives/platform@^0.0.101": "@solid-primitives/platform@^0.0.101":
version "0.0.101" version "0.0.101"
resolved "https://registry.yarnpkg.com/@solid-primitives/platform/-/platform-0.0.101.tgz#7bfa879152a59169589e2dc999aac8ceb63233c7" resolved "https://registry.yarnpkg.com/@solid-primitives/platform/-/platform-0.0.101.tgz#7bfa879152a59169589e2dc999aac8ceb63233c7"
@ -2737,6 +2745,11 @@
dependencies: dependencies:
"@solid-primitives/utils" "^3.0.2" "@solid-primitives/utils" "^3.0.2"
"@solid-primitives/scheduled@1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@solid-primitives/scheduled/-/scheduled-1.0.1.tgz#e5b07452f39d27504c4ba1caa64d65020110c017"
integrity sha512-zRyW9L4nYdL0yZktvJz/Ye9kVNa6UW26L71sZEqzzHnxvDidbT+mln4np7jqFrAeGiWMwWnRDR/ZvM0FK85jMw==
"@solid-primitives/scheduled@^1.0.1": "@solid-primitives/scheduled@^1.0.1":
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/@solid-primitives/scheduled/-/scheduled-1.0.2.tgz#8c2e8511b9b361c22c13e78377dc4168cc9c0452" resolved "https://registry.yarnpkg.com/@solid-primitives/scheduled/-/scheduled-1.0.2.tgz#8c2e8511b9b361c22c13e78377dc4168cc9c0452"