diff --git a/package.json b/package.json index 7e6b3b47..c907114e 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "@nanostores/persistent": "^0.7.0", "@nanostores/router": "^0.7.0", "@nanostores/solid": "^0.3.0", + "@solid-primitives/memo": "^1.0.2", "axios": "^0.27.2", "google-translate-api-x": "^10.4.1", "loglevel": "^1.8.0", diff --git a/src/components/Views/AllTopics.tsx b/src/components/Views/AllTopics.tsx index 43b2b972..d007af9f 100644 --- a/src/components/Views/AllTopics.tsx +++ b/src/components/Views/AllTopics.tsx @@ -8,22 +8,26 @@ import { TopicCard } from '../Topic/Card' import { session } from '../../stores/auth' import { useStore } from '@nanostores/solid' import '../../styles/AllTopics.scss' +import { getLogger } from '../../utils/logger' + +const log = getLogger('AllTopicsView') type AllTopicsPageSearchParams = { by: 'shouts' | 'authors' | 'title' | '' } -type Props = { +type AllTopicsViewProps = { topics: Topic[] } -export const AllTopicsView = (props: Props) => { +export const AllTopicsView = (props: AllTopicsViewProps) => { const { getSearchParams, changeSearchParam } = useRouter() const { sortedTopics } = useTopicsStore({ topics: props.topics, sortBy: getSearchParams().by || 'shouts' }) + const auth = useStore(session) createEffect(() => { diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts index 761cee55..3f593788 100644 --- a/src/graphql/types.gen.ts +++ b/src/graphql/types.gen.ts @@ -324,11 +324,11 @@ export type Query = { getUserRoles: Array> getUsersBySlugs: Array> isEmailUsed: Scalars['Boolean'] - myCandidates: Array> reactionsByAuthor: Array> reactionsByShout: Array> reactionsForShouts: Array> recentAll: Array> + recentCandidates: Array> recentCommented: Array> recentPublished: Array> recentReacted: Array> @@ -397,11 +397,6 @@ export type QueryIsEmailUsedArgs = { email: Scalars['String'] } -export type QueryMyCandidatesArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] -} - export type QueryReactionsByAuthorArgs = { limit: Scalars['Int'] offset: Scalars['Int'] @@ -425,6 +420,11 @@ export type QueryRecentAllArgs = { offset: Scalars['Int'] } +export type QueryRecentCandidatesArgs = { + limit: Scalars['Int'] + offset: Scalars['Int'] +} + export type QueryRecentCommentedArgs = { limit: Scalars['Int'] offset: Scalars['Int'] diff --git a/src/stores/zine/articles.ts b/src/stores/zine/articles.ts index 1608fa12..37ec3741 100644 --- a/src/stores/zine/articles.ts +++ b/src/stores/zine/articles.ts @@ -6,6 +6,7 @@ import { byStat } from '../../utils/sortby' import { getLogger } from '../../utils/logger' import { createMemo, createSignal } from 'solid-js' +import { createLazyMemo } from '@solid-primitives/memo' const log = getLogger('articles store') @@ -15,7 +16,7 @@ const [articleEntities, setArticleEntities] = createSignal<{ [articleSlug: strin const [topArticles, setTopArticles] = createSignal([]) const [topMonthArticles, setTopMonthArticles] = createSignal([]) -const articlesByAuthor = createMemo(() => { +const articlesByAuthor = createLazyMemo(() => { return Object.values(articleEntities()).reduce((acc, article) => { article.authors.forEach((author) => { if (!acc[author.slug]) { @@ -28,7 +29,7 @@ const articlesByAuthor = createMemo(() => { }, {} as { [authorSlug: string]: Shout[] }) }) -const articlesByTopic = createMemo(() => { +const articlesByTopic = createLazyMemo(() => { return Object.values(articleEntities()).reduce((acc, article) => { article.topics.forEach((topic) => { if (!acc[topic.slug]) { @@ -41,7 +42,7 @@ const articlesByTopic = createMemo(() => { }, {} as { [authorSlug: string]: Shout[] }) }) -const articlesByLayout = createMemo(() => { +const articlesByLayout = createLazyMemo(() => { return Object.values(articleEntities()).reduce((acc, article) => { if (!acc[article.layout]) { acc[article.layout] = [] @@ -53,13 +54,13 @@ const articlesByLayout = createMemo(() => { }, {} as { [layout: string]: Shout[] }) }) -const topViewedArticles = createMemo(() => { +const topViewedArticles = createLazyMemo(() => { const result = Object.values(articleEntities()) result.sort(byStat('viewed')) return result }) -const topCommentedArticles = createMemo(() => { +const topCommentedArticles = createLazyMemo(() => { const result = Object.values(articleEntities()) result.sort(byStat('commented')) return result diff --git a/src/stores/zine/authors.ts b/src/stores/zine/authors.ts index f3ac741a..c09604dc 100644 --- a/src/stores/zine/authors.ts +++ b/src/stores/zine/authors.ts @@ -3,7 +3,8 @@ import type { Author } from '../../graphql/types.gen' import { byCreated } from '../../utils/sortby' 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') @@ -14,7 +15,7 @@ const [sortAllBy, setSortAllBy] = createSignal('created') const [authorEntities, setAuthorEntities] = createSignal<{ [authorSlug: string]: Author }>({}) const [authorsByTopic, setAuthorsByTopic] = createSignal<{ [topicSlug: string]: Author[] }>({}) -const sortedAuthors = createMemo(() => { +const sortedAuthors = createLazyMemo(() => { const authors = Object.values(authorEntities()) switch (sortAllBy()) { case 'created': { diff --git a/src/stores/zine/topics.ts b/src/stores/zine/topics.ts index 12f31c1d..8994375e 100644 --- a/src/stores/zine/topics.ts +++ b/src/stores/zine/topics.ts @@ -3,6 +3,7 @@ import { apiClient } from '../../utils/apiClient' import type { Topic } from '../../graphql/types.gen' import { byCreated, byTopicStatDesc } from '../../utils/sortby' import { getLogger } from '../../utils/logger' +import { createLazyMemo } from '@solid-primitives/memo' const log = getLogger('topics store') @@ -16,8 +17,8 @@ const [topicEntities, setTopicEntities] = createSignal<{ [topicSlug: string]: To const [randomTopics, setRandomTopics] = createSignal([]) const [topicsByAuthor, setTopicByAuthor] = createSignal<{ [authorSlug: string]: Topic[] }>({}) -const sortedTopics = createMemo(() => { - const topics = Object.values(topicEntities) +const sortedTopics = createLazyMemo(() => { + const topics = Object.values(topicEntities()) const sortAllByValue = sortAllBy() switch (sortAllByValue) { @@ -38,6 +39,7 @@ const sortedTopics = createMemo(() => { default: log.error(`Unknown sort: ${sortAllByValue}`) } + return topics }) diff --git a/yarn.lock b/yarn.lock index 111d2429..abd29288 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2707,6 +2707,14 @@ "@solid-primitives/rootless" "^1.1.3" "@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": version "0.0.101" resolved "https://registry.yarnpkg.com/@solid-primitives/platform/-/platform-0.0.101.tgz#7bfa879152a59169589e2dc999aac8ceb63233c7" @@ -2737,6 +2745,11 @@ dependencies: "@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": version "1.0.2" resolved "https://registry.yarnpkg.com/@solid-primitives/scheduled/-/scheduled-1.0.2.tgz#8c2e8511b9b361c22c13e78377dc4168cc9c0452"