This commit is contained in:
Untone 2024-07-22 14:29:33 +03:00
parent 01e7dec615
commit b61b19a119
8 changed files with 146 additions and 129 deletions

View File

@ -4,12 +4,7 @@ import { useFeed } from '~/context/feed'
import { useLocalize } from '~/context/localize'
import { COMMENTS_PER_PAGE, useReactions } from '~/context/reactions'
import { useSession } from '~/context/session'
import {
Reaction,
ReactionKind,
ReactionSort,
Shout
} from '~/graphql/schema/core.gen'
import { Reaction, ReactionKind, ReactionSort, Shout } from '~/graphql/schema/core.gen'
import { byCreated, byStat } from '~/lib/sort'
import { SortFunction } from '~/types/common'
import { Button } from '../_shared/Button'

View File

@ -26,8 +26,14 @@ export const RatingControl = (props: RatingControlProps) => {
const [_, changeSearchParams] = useSearchParams()
const snackbar = useSnackbar()
const { session } = useSession()
const { reactionEntities, reactionsByShout, createReaction, deleteReaction, loadShoutRatings, loadCommentRatings } =
useReactions()
const {
reactionEntities,
reactionsByShout,
createReaction,
deleteReaction,
loadShoutRatings,
loadCommentRatings
} = useReactions()
const [myRate, setMyRate] = createSignal<Reaction | undefined>()
const [ratingReactions, setRatingReactions] = createSignal<Reaction[]>([])
const [isLoading, setIsLoading] = createSignal(false)

View File

@ -261,7 +261,6 @@ export const AuthorView = (props: AuthorViewProps) => {
</Show>
<AuthorFeed />
</Match>
</Switch>
</div>

View File

@ -53,14 +53,12 @@ export const LoadMoreWrapper = (props: LoadMoreProps) => {
return (
<>
{props.children}
<Show when={isLoading()}><Loading /></Show>
<Show when={isLoading()}>
<Loading />
</Show>
<Show when={isLoadMoreButtonVisible() && !props.hidden && !isLoading()}>
<div class="load-more-container">
<Button
onClick={loadItems}
value={t('Load more')}
title={`${items().length} ${t('loaded')}`}
/>
<Button onClick={loadItems} value={t('Load more')} title={`${items().length} ${t('loaded')}`} />
</div>
</Show>
</>

View File

@ -2,7 +2,12 @@ import type { JSX } from 'solid-js'
import { createContext, onCleanup, useContext } from 'solid-js'
import { createStore, reconcile } from 'solid-js/store'
import { loadCommentRatings, loadReactions, loadShoutComments, loadShoutRatings } from '~/graphql/api/public'
import {
loadCommentRatings,
loadReactions,
loadShoutComments,
loadShoutRatings
} from '~/graphql/api/public'
import createReactionMutation from '~/graphql/mutation/core/reaction-create'
import destroyReactionMutation from '~/graphql/mutation/core/reaction-destroy'
import updateReactionMutation from '~/graphql/mutation/core/reaction-update'
@ -69,7 +74,11 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => {
return result
}
const loadShoutRatingsAdding = async (shout: number, limit = RATINGS_PER_PAGE, offset = 0): Promise<Reaction[]> => {
const loadShoutRatingsAdding = async (
shout: number,
limit = RATINGS_PER_PAGE,
offset = 0
): Promise<Reaction[]> => {
const fetcher = await loadShoutRatings({ shout, limit, offset })
const result = (await fetcher()) || []
console.debug('[context.reactions] shout ratings loaded', result)
@ -77,7 +86,11 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => {
return result
}
const loadCommentRatingsAdding = async (comment: number, limit = RATINGS_PER_PAGE, offset = 0): Promise<Reaction[]> => {
const loadCommentRatingsAdding = async (
comment: number,
limit = RATINGS_PER_PAGE,
offset = 0
): Promise<Reaction[]> => {
const fetcher = await loadCommentRatings({ comment, limit, offset })
const result = (await fetcher()) || []
console.debug('[context.reactions] shout ratings loaded', result)
@ -85,7 +98,11 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => {
return result
}
const loadShoutCommentsAdding = async (shout: number, limit = COMMENTS_PER_PAGE, offset = 0): Promise<Reaction[]> => {
const loadShoutCommentsAdding = async (
shout: number,
limit = COMMENTS_PER_PAGE,
offset = 0
): Promise<Reaction[]> => {
const fetcher = await loadShoutComments({ shout, limit, offset })
const result = (await fetcher()) || []
console.debug('[context.reactions] shout comments loaded', result)

View File

@ -54,7 +54,10 @@ export default function AuthorPage(props: RouteSectionProps<AuthorPageProps>) {
const { authorsEntities } = useAuthors()
const { addFeed, feedByAuthor } = useFeed()
const { t } = useLocalize()
const author = createAsync(async() => props.data.author || authorsEntities()[props.params.slug] || await fetchAuthor(props.params.slug))
const author = createAsync(
async () =>
props.data.author || authorsEntities()[props.params.slug] || (await fetchAuthor(props.params.slug))
)
const shoutsByAuthor = createMemo(() => feedByAuthor()[props.params.slug])
const title = createMemo(() => `${author()?.name || ''}`)
const cover = createMemo(() =>
@ -74,7 +77,6 @@ export default function AuthorPage(props: RouteSectionProps<AuthorPageProps>) {
}
})
// author shouts
const loadAuthorShoutsMore = async (offset: number) => {
const loadedShouts = await fetchAuthorShouts(props.params.slug, offset)