diff --git a/.vscode/launch.json b/.vscode/launch.json index 7dc2d68d..6a7811d5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,16 +1,14 @@ { "version": "0.2.0", "configurations": [ - { - "name": "Launch Brave against localhost", + "name": "Launch browser against localhost", "type": "chrome", "request": "launch", - "url": "http://localhost:3000", + "url": "https://localhost:3000", "webRoot": "${workspaceFolder}/src", "sourceMaps": true, - "trace": true, - "runtimeExecutable": "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser" + "trace": true } ] } diff --git a/src/components/Article/CommentsTree.tsx b/src/components/Article/CommentsTree.tsx index ef05e014..55d4d5d0 100644 --- a/src/components/Article/CommentsTree.tsx +++ b/src/components/Article/CommentsTree.tsx @@ -1,12 +1,10 @@ import { clsx } from 'clsx' import { For, Show, createMemo, createSignal, lazy, onMount } from 'solid-js' - import { useFeed } from '~/context/feed' import { useLocalize } from '~/context/localize' -import { useReactions } from '~/context/reactions' +import { COMMENTS_PER_PAGE, useReactions } from '~/context/reactions' import { useSession } from '~/context/session' import { - QueryLoad_Reactions_ByArgs, Reaction, ReactionKind, ReactionSort, @@ -26,12 +24,11 @@ const SimplifiedEditor = lazy(() => import('../Editor/SimplifiedEditor')) type Props = { shout: Shout } -const COMMENTS_PER_PAGE = 50 export const CommentsTree = (props: Props) => { const { session } = useSession() const { t } = useLocalize() - const { reactionEntities, createReaction, loadReactionsBy, addReactions } = useReactions() + const { reactionEntities, createReaction, loadShoutComments } = useReactions() const { seen } = useFeed() const [commentsOrder, setCommentsOrder] = createSignal(ReactionSort.Newest) const [onlyNew, setOnlyNew] = createSignal(false) @@ -83,13 +80,7 @@ export const CommentsTree = (props: Props) => { setCommentsLoading(true) const next = pagination() + 1 const offset = next * COMMENTS_PER_PAGE - const opts: QueryLoad_Reactions_ByArgs = { - by: { comment: true, shout: props.shout.slug }, - limit: COMMENTS_PER_PAGE, - offset - } - const rrr = await loadReactionsBy(opts) - rrr && addReactions(rrr) + const rrr = await loadShoutComments(props.shout.id, COMMENTS_PER_PAGE, offset) rrr && setPagination(next) setCommentsLoading(false) return rrr as LoadMoreItems diff --git a/src/components/Article/RatingControl.tsx b/src/components/Article/RatingControl.tsx index 31ca8821..f492118c 100644 --- a/src/components/Article/RatingControl.tsx +++ b/src/components/Article/RatingControl.tsx @@ -3,10 +3,10 @@ import { clsx } from 'clsx' import { Show, createEffect, createMemo, createSignal, on } from 'solid-js' import { byCreated } from '~/lib/sort' import { useLocalize } from '../../context/localize' -import { useReactions } from '../../context/reactions' +import { RATINGS_PER_PAGE, useReactions } from '../../context/reactions' import { useSession } from '../../context/session' import { useSnackbar } from '../../context/ui' -import { QueryLoad_Reactions_ByArgs, Reaction, ReactionKind, Shout } from '../../graphql/schema/core.gen' +import { Reaction, ReactionKind, Shout } from '../../graphql/schema/core.gen' import { Icon } from '../_shared/Icon' import { InlineLoader } from '../_shared/InlineLoader' import { LoadMoreItems, LoadMoreWrapper } from '../_shared/LoadMoreWrapper' @@ -26,8 +26,7 @@ export const RatingControl = (props: RatingControlProps) => { const [_, changeSearchParams] = useSearchParams() const snackbar = useSnackbar() const { session } = useSession() - const { addReactions } = useReactions() - const { reactionEntities, reactionsByShout, createReaction, deleteReaction, loadReactionsBy } = + const { reactionEntities, reactionsByShout, createReaction, deleteReaction, loadShoutRatings, loadCommentRatings } = useReactions() const [myRate, setMyRate] = createSignal() const [ratingReactions, setRatingReactions] = createSignal([]) @@ -70,12 +69,13 @@ export const RatingControl = (props: RatingControlProps) => { // rating change const handleRatingChange = async (isUpvote: boolean) => { setIsLoading(true) + let error = '' try { - if (isUpvoted()) { - await deleteRating(ReactionKind.Like) - } else if (isDownvoted()) { - await deleteRating(ReactionKind.Dislike) - } else { + if (isUpvoted() && isUpvote) return + if (isDownvoted() && !isUpvote) return + if (isUpvoted() && !isUpvote) error = (await deleteRating(ReactionKind.Like))?.error || '' + if (isDownvoted() && isUpvote) error = (await deleteRating(ReactionKind.Dislike))?.error || '' + if (!(isUpvoted() || isDownvoted())) { props.comment?.shout.id && (await createReaction({ reaction: { @@ -85,13 +85,8 @@ export const RatingControl = (props: RatingControlProps) => { } })) } - } catch { - snackbar?.showSnackbar({ type: 'error', body: t('Error') }) - } - - if (props.comment?.shout.slug) { - const rrr = await loadReactionsBy({ by: { shout: props.comment.shout.slug } }) - addReactions(rrr) + } catch(err) { + snackbar?.showSnackbar({ type: 'error', body: `${t('Error')}: ${error || err || ''}` }) } setIsLoading(false) } @@ -138,16 +133,12 @@ export const RatingControl = (props: RatingControlProps) => { : [] ) const loadMoreReactions = async () => { + if (!(props.shout?.id || props.comment?.id)) return [] as LoadMoreItems setRatingLoading(true) const next = ratingPage() + 1 - const offset = VOTERS_PER_PAGE * next - const opts: QueryLoad_Reactions_ByArgs = { - by: { rating: true, shout: props.shout?.slug }, - limit: VOTERS_PER_PAGE, - offset - } - const rrr = await loadReactionsBy(opts) - rrr && addReactions(rrr) + const offset = RATINGS_PER_PAGE * next + const loader = props.comment ? loadCommentRatings : loadShoutRatings + const rrr = await loader(props.shout?.id || 0, RATINGS_PER_PAGE, offset) rrr && setRatingPage(next) setRatingLoading(false) return rrr as LoadMoreItems diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index 6cef65a1..0cb88453 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -61,7 +61,7 @@ export const AuthorView = (props: AuthorViewProps) => { on( [() => session()?.user?.app_data?.profile, () => props.authorSlug || ''], async ([me, slug]) => { - console.debug('check if my profile') + console.debug('[AuthorView] checking if my profile') const my = slug && me?.slug === slug if (my) { console.debug('[Author] my profile precached') @@ -86,7 +86,7 @@ export const AuthorView = (props: AuthorViewProps) => { () => authorsEntities()[props.author?.slug || props.authorSlug || ''], async (found) => { if (!found) return - setAuthor(found) + console.debug('[AuthorView] ') console.info(`[Author] profile for @${found.slug} fetched`) const followsResp = await query(getAuthorFollowsQuery, { slug: found.slug }).toPromise() const follows = followsResp?.data?.get_author_followers || {} @@ -96,6 +96,7 @@ export const AuthorView = (props: AuthorViewProps) => { setFollowers(followersResp?.data?.get_author_followers || []) console.info(`[Author] followers for @${found.slug} fetched`) setIsFetching(false) + setTimeout(() => setAuthor(found), 1) }, { defer: true } ) @@ -123,7 +124,37 @@ export const AuthorView = (props: AuthorViewProps) => { (tab) => tab && console.log('[views.Author] profile tab switched') ) ) + const AuthorFeed = () => ( + 0 && props.shouts[0]}> + + + + + + + + + + + + 3}> + + {(page) => ( + <> + + + + + + + + )} + + + + + ) return (
@@ -229,34 +260,8 @@ export const AuthorView = (props: AuthorViewProps) => {
- 0 && props.shouts[0]}> - + - 1}> - - - - - - - - 3}> - - {(page) => ( - <> - - - - - - - - )} - - - - -
diff --git a/src/components/_shared/LoadMoreWrapper.tsx b/src/components/_shared/LoadMoreWrapper.tsx index 9bb7887d..a5aa30a2 100644 --- a/src/components/_shared/LoadMoreWrapper.tsx +++ b/src/components/_shared/LoadMoreWrapper.tsx @@ -5,6 +5,7 @@ import { Author, Reaction, Shout } from '~/graphql/schema/core.gen' import { byCreated } from '~/lib/sort' import { SortFunction } from '~/types/common' import { restoreScrollPosition, saveScrollPosition } from '~/utils/scroll' +import { Loading } from './Loading' export type LoadMoreItems = Shout[] | Author[] | Reaction[] @@ -52,11 +53,11 @@ export const LoadMoreWrapper = (props: LoadMoreProps) => { return ( <> {props.children} - + +