modify user query (#248)

This commit is contained in:
Ilya Y 2023-10-05 07:24:01 +03:00 committed by GitHub
parent fac6422f2a
commit 9e5b468914
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 19 additions and 8 deletions

View File

@ -17,9 +17,8 @@ type Props = {
export const AuthorBadge = (props: Props) => { export const AuthorBadge = (props: Props) => {
const [isSubscribing, setIsSubscribing] = createSignal(false) const [isSubscribing, setIsSubscribing] = createSignal(false)
const { const {
isAuthenticated,
session, session,
actions: { loadSession } actions: { loadSession, requireAuthentication }
} = useSession() } = useSession()
const { t } = useLocalize() const { t } = useLocalize()
@ -37,6 +36,11 @@ export const AuthorBadge = (props: Props) => {
await loadSession() await loadSession()
setIsSubscribing(false) setIsSubscribing(false)
} }
const handleSubscribe = (really: boolean) => {
requireAuthentication(() => {
subscribe(really)
}, 'subscribe')
}
return ( return (
<div class={clsx(styles.AuthorBadge)}> <div class={clsx(styles.AuthorBadge)}>
@ -51,10 +55,10 @@ export const AuthorBadge = (props: Props) => {
</div> </div>
} }
> >
<div class={clsx('text-truncate', styles.bio)}>{props.author.bio}</div> <div class={clsx('text-truncate', styles.bio)} innerHTML={props.author.bio} />
</Show> </Show>
</a> </a>
<Show when={isAuthenticated() && props.author.slug !== session().user.slug}> <Show when={props.author.slug !== session()?.user.slug}>
<div class={styles.actions}> <div class={styles.actions}>
<Show <Show
when={!props.minimizeSubscribeButton} when={!props.minimizeSubscribeButton}
@ -62,7 +66,7 @@ export const AuthorBadge = (props: Props) => {
<CheckButton <CheckButton
text={t('Follow')} text={t('Follow')}
checked={subscribed()} checked={subscribed()}
onClick={() => subscribe(!subscribed)} onClick={() => handleSubscribe(!subscribed())}
/> />
} }
> >
@ -73,15 +77,15 @@ export const AuthorBadge = (props: Props) => {
variant="primary" variant="primary"
size="S" size="S"
value={isSubscribing() ? t('...subscribing') : t('Subscribe')} value={isSubscribing() ? t('...subscribing') : t('Subscribe')}
onClick={() => subscribe(true)} onClick={() => handleSubscribe(true)}
/> />
} }
> >
<Button <Button
onClick={() => subscribe(false)}
variant="secondary" variant="secondary"
size="S" size="S"
value={t('You are subscribed')} value={t('You are subscribed')}
onClick={() => handleSubscribe(false)}
/> />
</Show> </Show>
</Show> </Show>

View File

@ -32,6 +32,7 @@ export default gql`
name name
slug slug
userpic userpic
createdAt
} }
createdAt createdAt
publishedAt publishedAt

View File

@ -8,6 +8,7 @@ export default gql`
name name
userpic userpic
bio bio
createdAt
stat { stat {
shouts shouts
} }

View File

@ -8,6 +8,7 @@ export default gql`
name name
userpic userpic
bio bio
createdAt
stat { stat {
shouts shouts
} }

View File

@ -8,6 +8,7 @@ export default gql`
name name
bio bio
userpic userpic
createdAt
stat { stat {
shouts shouts
followers followers

View File

@ -10,7 +10,7 @@ export default gql`
userpic userpic
# communities # communities
links links
# createdAt createdAt
lastSeen lastSeen
# ratings { # ratings {
# rater # rater

View File

@ -28,6 +28,7 @@ export default gql`
name name
slug slug
userpic userpic
createdAt
} }
createdAt createdAt
publishedAt publishedAt

View File

@ -22,6 +22,7 @@ export default gql`
name name
slug slug
userpic userpic
createdAt
} }
createdAt createdAt
publishedAt publishedAt

View File

@ -17,6 +17,7 @@ export default gql`
name name
slug slug
userpic userpic
createdAt
} }
createdAt createdAt
updatedAt updatedAt