diff --git a/src/components/Views/Home.tsx b/src/components/Views/Home.tsx index 90bbfbe3..5a6144a8 100644 --- a/src/components/Views/Home.tsx +++ b/src/components/Views/Home.tsx @@ -1,4 +1,4 @@ -import { createMemo, createSignal, For, onMount, Show } from 'solid-js' +import { createEffect, createMemo, createSignal, For, onMount, Show } from 'solid-js' import Banner from '../Discours/Banner' import { Topics } from '../Nav/Topics' import { Row5 } from '../Feed/Row5' @@ -132,7 +132,7 @@ export const HomeView = (props: Props) => { - {(a: Shout) => ( + {(a) => ( { resetToken() return null } finally { - setIsSessionLoaded(true) + setTimeout(() => { + setIsSessionLoaded(true) + }, 0) } } @@ -123,8 +125,8 @@ export const SessionProvider = (props: { children: JSX.Element }) => { const confirmEmail = async (token: string) => { const authResult = await apiClient.confirmEmail({ token }) - mutate(authResult) setToken(authResult.token) + mutate(authResult) } const actions = { diff --git a/src/pages/feed.page.tsx b/src/pages/feed.page.tsx index e695f29d..6d0440ae 100644 --- a/src/pages/feed.page.tsx +++ b/src/pages/feed.page.tsx @@ -1,6 +1,6 @@ import { PageLayout } from '../components/_shared/PageLayout' import { FeedView } from '../components/Views/Feed' -import { Match, onCleanup, Switch } from 'solid-js' +import { createEffect, Match, on, onCleanup, Switch } from 'solid-js' import { loadMyFeed, loadShouts, resetSortedArticles } from '../stores/zine/articles' import { ReactionsProvider } from '../context/reactions' import { useRouter } from '../stores/router' @@ -23,6 +23,16 @@ export const FeedPage = () => { return loadMyFeed(options) } + createEffect( + on( + () => page().route, + () => { + resetSortedArticles() + }, + { defer: true } + ) + ) + return ( diff --git a/src/stores/zine/articles.ts b/src/stores/zine/articles.ts index f680353a..a993aef6 100644 --- a/src/stores/zine/articles.ts +++ b/src/stores/zine/articles.ts @@ -12,41 +12,50 @@ const [topArticles, setTopArticles] = createSignal([]) const [topMonthArticles, setTopMonthArticles] = createSignal([]) const articlesByAuthor = createLazyMemo(() => { - return Object.values(articleEntities()).reduce((acc, article) => { - article.authors.forEach((author) => { - if (!acc[author.slug]) { - acc[author.slug] = [] - } - acc[author.slug].push(article) - }) + return Object.values(articleEntities()).reduce( + (acc, article) => { + article.authors.forEach((author) => { + if (!acc[author.slug]) { + acc[author.slug] = [] + } + acc[author.slug].push(article) + }) - return acc - }, {} as { [authorSlug: string]: Shout[] }) + return acc + }, + {} as { [authorSlug: string]: Shout[] } + ) }) const articlesByTopic = createLazyMemo(() => { - return Object.values(articleEntities()).reduce((acc, article) => { - article.topics.forEach((topic) => { - if (!acc[topic.slug]) { - acc[topic.slug] = [] - } - acc[topic.slug].push(article) - }) + return Object.values(articleEntities()).reduce( + (acc, article) => { + article.topics.forEach((topic) => { + if (!acc[topic.slug]) { + acc[topic.slug] = [] + } + acc[topic.slug].push(article) + }) - return acc - }, {} as { [authorSlug: string]: Shout[] }) + return acc + }, + {} as { [authorSlug: string]: Shout[] } + ) }) const articlesByLayout = createLazyMemo(() => { - return Object.values(articleEntities()).reduce((acc, article) => { - if (!acc[article.layout]) { - acc[article.layout] = [] - } + return Object.values(articleEntities()).reduce( + (acc, article) => { + if (!acc[article.layout]) { + acc[article.layout] = [] + } - acc[article.layout].push(article) + acc[article.layout].push(article) - return acc - }, {} as { [layout: string]: Shout[] }) + return acc + }, + {} as { [layout: string]: Shout[] } + ) }) const topViewedArticles = createLazyMemo(() => { @@ -65,10 +74,13 @@ const topCommentedArticles = createLazyMemo(() => { const addArticles = (...args: Shout[][]) => { const allArticles = args.flatMap((articles) => articles || []) - const newArticleEntities = allArticles.reduce((acc, article) => { - acc[article.slug] = article - return acc - }, {} as { [articleSLug: string]: Shout }) + const newArticleEntities = allArticles.reduce( + (acc, article) => { + acc[article.slug] = article + return acc + }, + {} as { [articleSLug: string]: Shout } + ) setArticleEntities((prevArticleEntities) => { return { @@ -77,23 +89,26 @@ const addArticles = (...args: Shout[][]) => { } }) - const authorsByTopic = allArticles.reduce((acc, article) => { - const { authors, topics } = article + const authorsByTopic = allArticles.reduce( + (acc, article) => { + const { authors, topics } = article - topics.forEach((topic) => { - if (!acc[topic.slug]) { - acc[topic.slug] = [] - } - - authors.forEach((author) => { - if (!acc[topic.slug].some((a) => a.slug === author.slug)) { - acc[topic.slug].push(author) + topics.forEach((topic) => { + if (!acc[topic.slug]) { + acc[topic.slug] = [] } - }) - }) - return acc - }, {} as { [topicSlug: string]: Author[] }) + authors.forEach((author) => { + if (!acc[topic.slug].some((a) => a.slug === author.slug)) { + acc[topic.slug].push(author) + } + }) + }) + + return acc + }, + {} as { [topicSlug: string]: Author[] } + ) addAuthorsByTopic(authorsByTopic) } diff --git a/src/utils/getImageUrl.ts b/src/utils/getImageUrl.ts index a36b4544..93f7f616 100644 --- a/src/utils/getImageUrl.ts +++ b/src/utils/getImageUrl.ts @@ -11,19 +11,15 @@ const getSizeUrlPart = (options: { width?: number; height?: number } = {}) => { return `${widthString}x${heightString}/` } -// I'm not proud of this export const getImageUrl = (src: string, options: { width?: number; height?: number } = {}) => { const sizeUrlPart = getSizeUrlPart(options) - if (!src.startsWith(thumborUrl)) { - return `${thumborUrl}/unsafe/${sizeUrlPart}${src}` - } + const thumborPrefix = `${thumborUrl}/unsafe/` - if (src.startsWith(`${thumborUrl}/unsafe`)) { - const thumborKey = src.replace(`${thumborUrl}/unsafe`, '') + if (src.startsWith(thumborPrefix)) { + const thumborKey = src.replace(thumborPrefix, '') return `${thumborUrl}/unsafe/${sizeUrlPart}${thumborKey}` } - const thumborKey = src.replace(`${thumborUrl}`, '') - return `${thumborUrl}/${sizeUrlPart}${thumborKey}` + return `${thumborUrl}/unsafe/${sizeUrlPart}${src}` }