run fix checks

This commit is contained in:
ilya-bkv 2024-03-15 17:57:03 +03:00
parent edf4400627
commit d202845aab
6 changed files with 67 additions and 67 deletions

View File

@ -10,13 +10,13 @@ import { Author, FollowingEntity } from '../../../graphql/schema/core.gen'
import { router, useRouter } from '../../../stores/router' import { router, useRouter } from '../../../stores/router'
import { translit } from '../../../utils/ru2en' import { translit } from '../../../utils/ru2en'
import { isCyrillic } from '../../../utils/translate' import { isCyrillic } from '../../../utils/translate'
import { BadgeSubscribeButton } from '../../_shared/BadgeSubscribeButton'
import { Button } from '../../_shared/Button' import { Button } from '../../_shared/Button'
import { CheckButton } from '../../_shared/CheckButton' import { CheckButton } from '../../_shared/CheckButton'
import { ConditionalWrapper } from '../../_shared/ConditionalWrapper' import { ConditionalWrapper } from '../../_shared/ConditionalWrapper'
import { Icon } from '../../_shared/Icon' import { Icon } from '../../_shared/Icon'
import { Userpic } from '../Userpic' import { Userpic } from '../Userpic'
import styles from './AuthorBadge.module.scss' import styles from './AuthorBadge.module.scss'
import { BadgeSubscribeButton } from "../../_shared/BadgeSubscribeButton";
type Props = { type Props = {
author: Author author: Author
@ -37,7 +37,7 @@ export const AuthorBadge = (props: Props) => {
createEffect(() => { createEffect(() => {
if (!subscriptions || !props.author) return if (!subscriptions || !props.author) return
const subscribed = subscriptions.authors?.some((authorEntity) => authorEntity.id === props.author?.id); const subscribed = subscriptions.authors?.some((authorEntity) => authorEntity.id === props.author?.id)
setIsSubscribed(subscribed) setIsSubscribed(subscribed)
}) })
@ -73,7 +73,9 @@ export const AuthorBadge = (props: Props) => {
const handleFollowClick = () => { const handleFollowClick = () => {
requireAuthentication(() => { requireAuthentication(() => {
isSubscribed() ? unfollow(FollowingEntity.Author, props.author.slug) : follow(FollowingEntity.Author, props.author.slug) isSubscribed()
? unfollow(FollowingEntity.Author, props.author.slug)
: follow(FollowingEntity.Author, props.author.slug)
}, 'subscribe') }, 'subscribe')
} }
@ -130,7 +132,9 @@ export const AuthorBadge = (props: Props) => {
<BadgeSubscribeButton <BadgeSubscribeButton
action={() => handleFollowClick()} action={() => handleFollowClick()}
isSubscribed={isSubscribed()} isSubscribed={isSubscribed()}
actionMessageType={subscribeInAction()?.slug === props.author.slug ? subscribeInAction().type : undefined} actionMessageType={
subscribeInAction()?.slug === props.author.slug ? subscribeInAction().type : undefined
}
/> />
<Show when={props.showMessageButton}> <Show when={props.showMessageButton}>
<Button <Button

View File

@ -44,7 +44,7 @@ export const AuthorCard = (props: Props) => {
createEffect(() => { createEffect(() => {
if (!subscriptions || !props.author) return if (!subscriptions || !props.author) return
const subscribed = subscriptions.authors?.some((authorEntity) => authorEntity.id === props.author?.id); const subscribed = subscriptions.authors?.some((authorEntity) => authorEntity.id === props.author?.id)
setIsSubscribed(subscribed) setIsSubscribed(subscribed)
}) })
@ -86,7 +86,9 @@ export const AuthorCard = (props: Props) => {
const handleFollowClick = () => { const handleFollowClick = () => {
requireAuthentication(() => { requireAuthentication(() => {
isSubscribed() ? unfollow(FollowingEntity.Author, props.author.slug) : follow(FollowingEntity.Author, props.author.slug) isSubscribed()
? unfollow(FollowingEntity.Author, props.author.slug)
: follow(FollowingEntity.Author, props.author.slug)
}, 'subscribe') }, 'subscribe')
} }
@ -123,9 +125,7 @@ export const AuthorCard = (props: Props) => {
<Show when={props.author.bio}> <Show when={props.author.bio}>
<div class={styles.authorAbout} innerHTML={props.author.bio} /> <div class={styles.authorAbout} innerHTML={props.author.bio} />
</Show> </Show>
<Show <Show when={props.followers?.length > 0 || props.following?.length > 0}>
when={(props.followers?.length > 0) || (props.following?.length > 0)}
>
<div class={styles.subscribersContainer}> <div class={styles.subscribersContainer}>
<Show when={props.followers && props.followers.length > 0}> <Show when={props.followers && props.followers.length > 0}>
<a href="?m=followers" class={styles.subscribers}> <a href="?m=followers" class={styles.subscribers}>
@ -251,9 +251,7 @@ export const AuthorCard = (props: Props) => {
<div class="row"> <div class="row">
<div class="col-24"> <div class="col-24">
<For each={props.followers}> <For each={props.followers}>
{(follower: Author) => ( {(follower: Author) => <AuthorBadge author={follower} />}
<AuthorBadge author={follower}/>
)}
</For> </For>
</div> </div>
</div> </div>
@ -296,13 +294,9 @@ export const AuthorCard = (props: Props) => {
<For each={authorSubs()}> <For each={authorSubs()}>
{(subscription) => {(subscription) =>
isAuthor(subscription) ? ( isAuthor(subscription) ? (
<AuthorBadge <AuthorBadge author={subscription} />
author={subscription}
/>
) : ( ) : (
<TopicBadge <TopicBadge topic={subscription} />
topic={subscription}
/>
) )
} }
</For> </For>

View File

@ -8,10 +8,10 @@ import { useSession } from '../../../context/session'
import { FollowingEntity, Topic } from '../../../graphql/schema/core.gen' import { FollowingEntity, Topic } from '../../../graphql/schema/core.gen'
import { capitalize } from '../../../utils/capitalize' import { capitalize } from '../../../utils/capitalize'
import { getImageUrl } from '../../../utils/getImageUrl' import { getImageUrl } from '../../../utils/getImageUrl'
import { BadgeSubscribeButton } from '../../_shared/BadgeSubscribeButton'
import { Button } from '../../_shared/Button' import { Button } from '../../_shared/Button'
import { CheckButton } from '../../_shared/CheckButton' import { CheckButton } from '../../_shared/CheckButton'
import styles from './TopicBadge.module.scss' import styles from './TopicBadge.module.scss'
import { BadgeSubscribeButton } from "../../_shared/BadgeSubscribeButton";
type Props = { type Props = {
topic: Topic topic: Topic
@ -29,13 +29,15 @@ export const TopicBadge = (props: Props) => {
createEffect(() => { createEffect(() => {
if (!subscriptions || !props.topic) return if (!subscriptions || !props.topic) return
const subscribed = subscriptions.authors?.some((authorEntity) => authorEntity.id === props.topic?.id); const subscribed = subscriptions.authors?.some((authorEntity) => authorEntity.id === props.topic?.id)
setIsSubscribed(subscribed) setIsSubscribed(subscribed)
}) })
const handleFollowClick = () => { const handleFollowClick = () => {
requireAuthentication(() => { requireAuthentication(() => {
isSubscribed() ? follow(FollowingEntity.Topic, props.topic.slug) : unfollow(FollowingEntity.Topic, props.topic.slug) isSubscribed()
? follow(FollowingEntity.Topic, props.topic.slug)
: unfollow(FollowingEntity.Topic, props.topic.slug)
}, 'subscribe') }, 'subscribe')
} }
@ -80,7 +82,9 @@ export const TopicBadge = (props: Props) => {
<BadgeSubscribeButton <BadgeSubscribeButton
isSubscribed={isSubscribed()} isSubscribed={isSubscribed()}
action={handleFollowClick} action={handleFollowClick}
actionMessageType={subscribeInAction()?.slug === props.topic.slug ? subscribeInAction().type : undefined} actionMessageType={
subscribeInAction()?.slug === props.topic.slug ? subscribeInAction().type : undefined
}
/> />
</div> </div>
</div> </div>

View File

@ -3,7 +3,7 @@ import type { Author, Reaction, Shout, Topic } from '../../../graphql/schema/cor
import { getPagePath } from '@nanostores/router' import { getPagePath } from '@nanostores/router'
import { Meta, Title } from '@solidjs/meta' import { Meta, Title } from '@solidjs/meta'
import { clsx } from 'clsx' import { clsx } from 'clsx'
import { For, Match, Show, Switch, createEffect, createMemo, createSignal, onMount, on } from "solid-js"; import { For, Match, Show, Switch, createEffect, createMemo, createSignal, on, onMount } from 'solid-js'
import { useFollowing } from '../../../context/following' import { useFollowing } from '../../../context/following'
import { useLocalize } from '../../../context/localize' import { useLocalize } from '../../../context/localize'

View File

@ -1,45 +1,45 @@
import { clsx } from "clsx"; import { clsx } from 'clsx'
import styles from "./BadgeDubscribeButton.module.scss"; import { Show, createMemo } from 'solid-js'
import { CheckButton } from "../CheckButton"; import { useFollowing } from '../../../context/following'
import { createMemo, Show } from "solid-js"; import { useLocalize } from '../../../context/localize'
import { Button } from "../Button"; import { Button } from '../Button'
import { Icon } from "../Icon"; import stylesButton from '../Button/Button.module.scss'
import stylesButton from "../Button/Button.module.scss"; import { CheckButton } from '../CheckButton'
import { useLocalize } from "../../../context/localize"; import { Icon } from '../Icon'
import { useFollowing } from "../../../context/following"; import styles from './BadgeDubscribeButton.module.scss'
type Props = { type Props = {
class?: string; class?: string
isSubscribed: boolean; isSubscribed: boolean
minimizeSubscribeButton?: boolean; minimizeSubscribeButton?: boolean
action: () => void; action: () => void
iconButtons?: boolean; iconButtons?: boolean
actionMessageType?: "subscribe" | "unsubscribe"; actionMessageType?: 'subscribe' | 'unsubscribe'
}; }
export const BadgeSubscribeButton = (props: Props) => { export const BadgeSubscribeButton = (props: Props) => {
const { t } = useLocalize(); const { t } = useLocalize()
const inActionText = createMemo(() => { const inActionText = createMemo(() => {
return props.actionMessageType === "subscribe" ? t("Subscribing...") : t("Unsubscribing..."); return props.actionMessageType === 'subscribe' ? t('Subscribing...') : t('Unsubscribing...')
}); })
return ( return (
<div class={props.class}> <div class={props.class}>
<Show <Show
when={!props.minimizeSubscribeButton} when={!props.minimizeSubscribeButton}
fallback={<CheckButton text={t("Follow")} checked={props.isSubscribed} onClick={props.action} />} fallback={<CheckButton text={t('Follow')} checked={props.isSubscribed} onClick={props.action} />}
> >
<Show <Show
when={props.isSubscribed} when={props.isSubscribed}
fallback={ fallback={
<Button <Button
variant={props.iconButtons ? "secondary" : "bordered"} variant={props.iconButtons ? 'secondary' : 'bordered'}
size="S" size="S"
value={ value={
<Show <Show
when={props.iconButtons} when={props.iconButtons}
fallback={props.actionMessageType ? inActionText() : t("Subscribe")} fallback={props.actionMessageType ? inActionText() : t('Subscribe')}
> >
<Icon name="author-subscribe" class={stylesButton.icon} /> <Icon name="author-subscribe" class={stylesButton.icon} />
</Show> </Show>
@ -54,7 +54,7 @@ export const BadgeSubscribeButton = (props: Props) => {
} }
> >
<Button <Button
variant={props.iconButtons ? "secondary" : "bordered"} variant={props.iconButtons ? 'secondary' : 'bordered'}
size="S" size="S"
value={ value={
<Show <Show
@ -64,8 +64,8 @@ export const BadgeSubscribeButton = (props: Props) => {
inActionText() inActionText()
) : ( ) : (
<> <>
<span class={styles.actionButtonLabel}>{t("Following")}</span> <span class={styles.actionButtonLabel}>{t('Following')}</span>
<span class={styles.actionButtonLabelHovered}>{t("Unfollow")}</span> <span class={styles.actionButtonLabelHovered}>{t('Unfollow')}</span>
</> </>
) )
} }
@ -83,5 +83,5 @@ export const BadgeSubscribeButton = (props: Props) => {
</Show> </Show>
</Show> </Show>
</div> </div>
); )
}; }

View File

@ -1,8 +1,8 @@
import { Accessor, JSX, createContext, createEffect, createSignal, useContext, createMemo } from "solid-js"; import { Accessor, JSX, createContext, createEffect, createMemo, createSignal, useContext } from 'solid-js'
import { createStore } from 'solid-js/store' import { createStore } from 'solid-js/store'
import { apiClient } from '../graphql/client/core' import { apiClient } from '../graphql/client/core'
import { Author, AuthorFollows, Community, FollowingEntity, Topic } from "../graphql/schema/core.gen"; import { Author, AuthorFollows, Community, FollowingEntity, Topic } from '../graphql/schema/core.gen'
import { useSession } from './session' import { useSession } from './session'
@ -60,24 +60,23 @@ export const FollowingProvider = (props: { children: JSX.Element }) => {
} }
createEffect(() => { createEffect(() => {
console.info('[context.following] subs:', subscriptions); console.info('[context.following] subs:', subscriptions)
}) })
const follow = async (what: FollowingEntity, slug: string) => { const follow = async (what: FollowingEntity, slug: string) => {
if (!author()) return; if (!author()) return
setSubscribeInAction({ slug, type: 'subscribe' }); setSubscribeInAction({ slug, type: 'subscribe' })
try { try {
const subscriptionData = await apiClient.follow({ what, slug }); const subscriptionData = await apiClient.follow({ what, slug })
setSubscriptions((prevSubscriptions) => { setSubscriptions((prevSubscriptions) => {
if (!prevSubscriptions[what]) prevSubscriptions[what] = []; if (!prevSubscriptions[what]) prevSubscriptions[what] = []
prevSubscriptions[what].push(subscriptionData); prevSubscriptions[what].push(subscriptionData)
return prevSubscriptions; return prevSubscriptions
}); })
} catch (error) { } catch (error) {
console.error(error); console.error(error)
} finally { } finally {
setSubscribeInAction(); // Сбрасываем состояние действия подписки. setSubscribeInAction() // Сбрасываем состояние действия подписки.
} }
} }
@ -93,7 +92,6 @@ export const FollowingProvider = (props: { children: JSX.Element }) => {
} }
} }
createEffect(() => { createEffect(() => {
if (author()) { if (author()) {
console.debug('[context.following] author update detect') console.debug('[context.following] author update detect')