schema-updates
Some checks are pending
deploy / test (push) Waiting to run
deploy / deploy (push) Blocked by required conditions

This commit is contained in:
Untone 2023-11-30 11:07:31 +03:00
parent 1159adc6ff
commit 7b3ab33481
15 changed files with 84 additions and 35 deletions

View File

@ -18,7 +18,7 @@ type Props = {
export const CommentRatingControl = (props: Props) => { export const CommentRatingControl = (props: Props) => {
const { t } = useLocalize() const { t } = useLocalize()
const { user } = useSession() const { author } = useSession()
const { const {
actions: { showSnackbar }, actions: { showSnackbar },
} = useSnackbar() } = useSnackbar()
@ -31,13 +31,13 @@ export const CommentRatingControl = (props: Props) => {
Object.values(reactionEntities).some( Object.values(reactionEntities).some(
(r) => (r) =>
r.kind === reactionKind && r.kind === reactionKind &&
r.created_by.slug === user()?.slug && r.created_by.slug === author()?.slug &&
r.shout.id === props.comment.shout.id && r.shout.id === props.comment.shout.id &&
r.reply_to === props.comment.id, r.reply_to === props.comment.id,
) )
const isUpvoted = createMemo(() => checkReaction(ReactionKind.Like)) const isUpvoted = createMemo(() => checkReaction(ReactionKind.Like))
const isDownvoted = createMemo(() => checkReaction(ReactionKind.Dislike)) const isDownvoted = createMemo(() => checkReaction(ReactionKind.Dislike))
const canVote = createMemo(() => user()?.slug !== props.comment.created_by.slug) const canVote = createMemo(() => author()?.slug !== props.comment.created_by.slug)
const commentRatingReactions = createMemo(() => const commentRatingReactions = createMemo(() =>
Object.values(reactionEntities).filter( Object.values(reactionEntities).filter(
@ -52,7 +52,7 @@ export const CommentRatingControl = (props: Props) => {
const reactionToDelete = Object.values(reactionEntities).find( const reactionToDelete = Object.values(reactionEntities).find(
(r) => (r) =>
r.kind === reactionKind && r.kind === reactionKind &&
r.created_by.slug === user()?.slug && r.created_by.slug === author()?.slug &&
r.shout.id === props.comment.shout.id && r.shout.id === props.comment.shout.id &&
r.reply_to === props.comment.id, r.reply_to === props.comment.id,
) )
@ -86,7 +86,7 @@ export const CommentRatingControl = (props: Props) => {
<div class={styles.commentRating}> <div class={styles.commentRating}>
<button <button
role="button" role="button"
disabled={!canVote() || !user()} disabled={!canVote() || !author()}
onClick={() => handleRatingChange(true)} onClick={() => handleRatingChange(true)}
class={clsx(styles.commentRatingControl, styles.commentRatingControlUp, { class={clsx(styles.commentRatingControl, styles.commentRatingControlUp, {
[styles.voted]: isUpvoted(), [styles.voted]: isUpvoted(),
@ -112,7 +112,7 @@ export const CommentRatingControl = (props: Props) => {
</Popup> </Popup>
<button <button
role="button" role="button"
disabled={!canVote() || !user()} disabled={!canVote() || !author()}
onClick={() => handleRatingChange(false)} onClick={() => handleRatingChange(false)}
class={clsx(styles.commentRatingControl, styles.commentRatingControlDown, { class={clsx(styles.commentRatingControl, styles.commentRatingControlDown, {
[styles.voted]: isDownvoted(), [styles.voted]: isDownvoted(),

View File

@ -43,7 +43,7 @@ type Props = {
} }
export const CommentsTree = (props: Props) => { export const CommentsTree = (props: Props) => {
const { session } = useSession() const { author } = useSession()
const { t } = useLocalize() const { t } = useLocalize()
const [commentsOrder, setCommentsOrder] = createSignal<CommentsOrder>('createdAt') const [commentsOrder, setCommentsOrder] = createSignal<CommentsOrder>('createdAt')
const [newReactions, setNewReactions] = createSignal<Reaction[]>([]) const [newReactions, setNewReactions] = createSignal<Reaction[]>([])
@ -85,7 +85,7 @@ export const CommentsTree = (props: Props) => {
setCookie() setCookie()
} else if (currentDate.getTime() > dateFromLocalStorage) { } else if (currentDate.getTime() > dateFromLocalStorage) {
const newComments = comments().filter((c) => { const newComments = comments().filter((c) => {
if (c.reply_to || c.created_by.slug === session()?.user.slug) { if (c.reply_to || c.created_by.slug === author()?.slug) {
return return
} }
const created = c.created_at const created = c.created_at

View File

@ -61,7 +61,7 @@ export const FullArticle = (props: Props) => {
const { t, formatDate } = useLocalize() const { t, formatDate } = useLocalize()
const { const {
user, author,
isAuthenticated, isAuthenticated,
actions: { requireAuthentication }, actions: { requireAuthentication },
} = useSession() } = useSession()
@ -72,7 +72,7 @@ export const FullArticle = (props: Props) => {
const mainTopic = createMemo(() => (props.article.topics.length > 0 ? props.article.topics[0] : null)) const mainTopic = createMemo(() => (props.article.topics.length > 0 ? props.article.topics[0] : null))
const canEdit = () => props.article.authors?.some((a) => a.slug === user()?.slug) const canEdit = () => props.article.authors?.some((a) => a.slug === author()?.slug)
const handleBookmarkButtonClick = (ev) => { const handleBookmarkButtonClick = (ev) => {
requireAuthentication(() => { requireAuthentication(() => {

View File

@ -20,7 +20,7 @@ interface ShoutRatingControlProps {
export const ShoutRatingControl = (props: ShoutRatingControlProps) => { export const ShoutRatingControl = (props: ShoutRatingControlProps) => {
const { t } = useLocalize() const { t } = useLocalize()
const { const {
user, author,
actions: { requireAuthentication }, actions: { requireAuthentication },
} = useSession() } = useSession()
@ -33,7 +33,7 @@ export const ShoutRatingControl = (props: ShoutRatingControlProps) => {
Object.values(reactionEntities).some( Object.values(reactionEntities).some(
(r) => (r) =>
r.kind === reactionKind && r.kind === reactionKind &&
r.created_by.slug === user()?.slug && r.created_by.slug === author()?.slug &&
r.shout.id === props.shout.id && r.shout.id === props.shout.id &&
!r.reply_to, !r.reply_to,
) )
@ -55,7 +55,7 @@ export const ShoutRatingControl = (props: ShoutRatingControlProps) => {
const reactionToDelete = Object.values(reactionEntities).find( const reactionToDelete = Object.values(reactionEntities).find(
(r) => (r) =>
r.kind === reactionKind && r.kind === reactionKind &&
r.created_by.slug === user()?.slug && r.created_by.slug === author()?.slug &&
r.shout.id === props.shout.id && r.shout.id === props.shout.id &&
!r.reply_to, !r.reply_to,
) )

View File

@ -73,7 +73,7 @@ const providers: Record<string, HocuspocusProvider> = {}
export const Editor = (props: Props) => { export const Editor = (props: Props) => {
const { t } = useLocalize() const { t } = useLocalize()
const { user } = useSession() const { author } = useSession()
const [isCommonMarkup, setIsCommonMarkup] = createSignal(false) const [isCommonMarkup, setIsCommonMarkup] = createSignal(false)
const [shouldShowTextBubbleMenu, setShouldShowTextBubbleMenu] = createSignal(false) const [shouldShowTextBubbleMenu, setShouldShowTextBubbleMenu] = createSignal(false)
@ -234,8 +234,8 @@ export const Editor = (props: Props) => {
CollaborationCursor.configure({ CollaborationCursor.configure({
provider: providers[docName], provider: providers[docName],
user: { user: {
name: user().name, name: author().name,
color: uniqolor(user().slug).color, color: uniqolor(author().slug).color,
}, },
}), }),
Placeholder.configure({ Placeholder.configure({

View File

@ -85,7 +85,7 @@ const getTitleAndSubtitle = (
export const ArticleCard = (props: ArticleCardProps) => { export const ArticleCard = (props: ArticleCardProps) => {
const { t, lang, formatDate } = useLocalize() const { t, lang, formatDate } = useLocalize()
const { user } = useSession() const { author } = useSession()
const mainTopic = props.article.topics[0] const mainTopic = props.article.topics[0]
const formattedDate = createMemo<string>(() => { const formattedDate = createMemo<string>(() => {
@ -94,7 +94,8 @@ export const ArticleCard = (props: ArticleCardProps) => {
const { title, subtitle } = getTitleAndSubtitle(props.article) const { title, subtitle } = getTitleAndSubtitle(props.article)
const canEdit = () => props.article.authors?.some((a) => a.slug === user()?.slug) const canEdit = () =>
props.article.authors?.some((a) => a.slug === author()?.slug) || props.article.created_by == author().id
const { changeSearchParam } = useRouter() const { changeSearchParam } = useRouter()
const scrollToComments = (event) => { const scrollToComments = (event) => {

View File

@ -19,15 +19,9 @@ import { ConfirmModal } from '../ConfirmModal'
import { HeaderAuth } from '../HeaderAuth' import { HeaderAuth } from '../HeaderAuth'
import { Modal } from '../Modal' import { Modal } from '../Modal'
import { Snackbar } from '../Snackbar' import { Snackbar } from '../Snackbar'
import { Link } from './Link' import { Link } from './Link'
import styles from './Header.module.scss'
import { apiClient } from '../../../utils/apiClient'
import { RANDOM_TOPICS_COUNT } from '../../Views/Home'
import { Link } from './Link'
import { Subscribe } from '../../_shared/Subscribe'
import { SearchModal } from '../SearchModal/SearchModal' import { SearchModal } from '../SearchModal/SearchModal'
import styles from './Header.module.scss'
type Props = { type Props = {
title?: string title?: string

View File

@ -9,7 +9,15 @@ import { Reaction, ReactionBy, ReactionInput, ReactionKind } from '../graphql/sc
type ReactionsContextType = { type ReactionsContextType = {
reactionEntities: Record<number, Reaction> reactionEntities: Record<number, Reaction>
actions: { actions: {
loadReactionsBy: ({ by, limit }: { by: ReactionBy; limit?: number }) => Promise<Reaction[]> loadReactionsBy: ({
by,
limit,
offset,
}: {
by: ReactionBy
limit?: number
offset?: number
}) => Promise<Reaction[]>
createReaction: (reaction: ReactionInput) => Promise<void> createReaction: (reaction: ReactionInput) => Promise<void>
updateReaction: (id: number, reaction: ReactionInput) => Promise<void> updateReaction: (id: number, reaction: ReactionInput) => Promise<void>
deleteReaction: (id: number) => Promise<void> deleteReaction: (id: number) => Promise<void>
@ -28,11 +36,13 @@ export const ReactionsProvider = (props: { children: JSX.Element }) => {
const loadReactionsBy = async ({ const loadReactionsBy = async ({
by, by,
limit, limit,
offset,
}: { }: {
by: ReactionBy by: ReactionBy
limit?: number limit?: number
offset?: number
}): Promise<Reaction[]> => { }): Promise<Reaction[]> => {
const reactions = await apiClient.getReactionsBy({ by, limit }) const reactions = await apiClient.getReactionsBy({ by, limit, offset })
const newReactionEntities = reactions.reduce((acc, reaction) => { const newReactionEntities = reactions.reduce((acc, reaction) => {
acc[reaction.id] = reaction acc[reaction.id] = reaction
return acc return acc

View File

@ -183,9 +183,9 @@ export const apiClient = {
return resp.data.load_shouts_feed return resp.data.load_shouts_feed
}, },
getReactionsBy: async ({ by, limit }: { by: ReactionBy; limit?: number }) => { getReactionsBy: async ({ by, limit, offset }: { by: ReactionBy; limit?: number; offset?: number }) => {
const resp = await publicGraphQLClient const resp = await publicGraphQLClient
.query(reactionsLoadBy, { by, limit: limit ?? 1000, offset: 0 }) .query(reactionsLoadBy, { by, limit: limit ?? 1000, offset: offset ?? 0 })
.toPromise() .toPromise()
return resp.data.load_reactions_by return resp.data.load_reactions_by
}, },

View File

@ -14,8 +14,21 @@ export default gql`
cover cover
body body
media media
created_by {
id
name
slug
pic
created_at
}
updated_by {
id
name
slug
pic
created_at
}
# community # community
# mainTopic
topics { topics {
id id
title title
@ -35,6 +48,7 @@ export default gql`
created_at created_at
} }
created_at created_at
updated_at
published_at published_at
stat { stat {
viewed viewed

View File

@ -12,8 +12,13 @@ export default gql`
layout layout
cover cover
lead lead
# community created_by {
# mainTopic id
name
slug
pic
created_at
}
topics { topics {
id id
title title

View File

@ -10,7 +10,13 @@ export default gql`
layout layout
cover cover
# community # community
# mainTopic created_by {
id
name
slug
pic
created_at
}
media media
topics { topics {
id id

View File

@ -10,7 +10,13 @@ export default gql`
layout layout
cover cover
# community # community
# mainTopic created_by {
id
name
slug
pic
created_at
}
topics { topics {
id id
title title

View File

@ -9,7 +9,13 @@ export default gql`
slug slug
cover cover
# community # community
# mainTopic created_by {
id
name
slug
pic
created_at
}
topics { topics {
# id # id
title title

View File

@ -15,6 +15,13 @@ export default gql`
body body
slug slug
} }
created_by {
id
name
slug
pic
created_at
}
authors { authors {
id id
name name