Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview: Video optimistic updates #6358

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
454e4d3
ProveChannelOwnership
WRadoslaw May 11, 2024
50a4902
CheckEmailConfirmation
WRadoslaw May 11, 2024
6a7aeb8
EmailVerified
WRadoslaw May 11, 2024
bb1bd9a
CreatePassword
WRadoslaw May 13, 2024
9357742
SeedGeneration and CreatePassword fixes
WRadoslaw May 13, 2024
a7e3bdb
WaitingModal
WRadoslaw May 13, 2024
723be41
ProvideEmailForLink
WRadoslaw May 13, 2024
18e3334
Create email setup flow
ikprk May 13, 2024
8b2acd6
Post verification flow
ikprk May 15, 2024
d1df74f
inital email send implementation
ikprk May 18, 2024
db6b211
Initial acc cration step
ikprk May 20, 2024
b80062a
Finalize internal account creation
ikprk May 22, 2024
075dd77
Small account setup fixes
ikprk May 23, 2024
4227f5e
Initial setup for external wallets
ikprk May 23, 2024
b93f2ed
Fix infinite loop
ikprk May 27, 2024
d2ed9e5
Merge branch 'dev' into fix/auth-flow-code
ikprk May 29, 2024
8e62637
Add alert to show email confirmation link
ikprk May 29, 2024
4706e44
Add optimistic video reactions
ikprk May 27, 2024
74a38b6
Add initial implementation for comment optimistic actions
ikprk May 29, 2024
fb34feb
Initial changes for comments reactions
ikprk Jun 3, 2024
735b40e
Improve comments layout
ikprk Jun 3, 2024
fe71b70
Fix first comment reaction update
ikprk Jun 3, 2024
94f0050
Lock regen
ikprk Jun 3, 2024
f0b7e3e
build fix
ikprk Jun 3, 2024
6d900a9
Avoid refetch on comment reactions
ikprk Jun 3, 2024
9174a8c
Disallow certain actions if comment is unconfirmed
ikprk Jun 3, 2024
8bc7854
New comment transition tryout
ikprk Jun 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/atlas/codegen.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { CodegenConfig } from '@graphql-codegen/cli'

import { customSchemaLoader } from './scripts/customSchemaLoader'

const ENV = process.env.VITE_DEFAULT_DATA_ENV?.toUpperCase() || process.env.VITE_ENV?.toUpperCase() || 'PRODUCTION'
// const ENV = process.env.VITE_DEFAULT_DATA_ENV?.toUpperCase() || process.env.VITE_ENV?.toUpperCase() || 'PRODUCTION'
const ENV = 'NEXT'
const schemaUrl = process.env[`VITE_${ENV}_ORION_URL`]
if (!schemaUrl) throw new Error(`VITE_${ENV}_ORION_URL is not defined`)

Expand Down
18 changes: 17 additions & 1 deletion packages/atlas/src/api/client/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FieldPolicy, FieldReadFunction } from '@apollo/client/cache/inmemory/po
import { offsetLimitPagination, relayStylePagination } from '@apollo/client/utilities'
import { parseISO } from 'date-fns'

import { QueryCommentReactionsConnectionArgs } from '../../../../atlas-meta-server/src/api/__generated__/sdk'
import {
Query,
QueryChannelsConnectionArgs,
Expand Down Expand Up @@ -119,7 +120,19 @@ const getCommentKeyArgs = (
const parentCommentId = args?.where?.parentComment?.id_eq
const videoId = args?.where?.video?.id_eq ?? ctx.variables?.videoId
const orderBy = args?.orderBy || []
return `${parentCommentId}:${videoId}:${orderBy}`
return `parentId-${parentCommentId}-:id-${videoId}-:${orderBy}`
}

const getCommentReactionsKeyArgs = (
args: Partial<QueryCommentReactionsConnectionArgs> | null,
ctx: {
variables?: Record<string, unknown>
}
) => {
const memberId = args?.where?.member?.id_eq
const videoId = args?.where?.video?.id_eq ?? ctx.variables?.videoId
const orderBy = args?.orderBy || []
return `memberId-${memberId}-:videoId-${videoId}-:${orderBy}`
}

const createDateHandler = () => ({
Expand Down Expand Up @@ -216,6 +229,9 @@ const queryCacheFields: CachePolicyFields<keyof Query> = {
return existing?.slice(offset, offset + limit)
},
},
commentReactions: {
...offsetLimitPagination(getCommentReactionsKeyArgs),
},
commentsConnection: relayStylePagination(getCommentKeyArgs),
channelById: (existing, { toReference, args }) => {
return (
Expand Down
12 changes: 9 additions & 3 deletions packages/atlas/src/api/hooks/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const useComment = (
}
}

export type UserCommentReactions = Record<string, number[]>
export type UserCommentReactions = Record<string, { reactionId: number; reactionServerId: string }[]>
export const useUserCommentsReactions = (videoId?: string | null, memberId?: string | null) => {
const { data } = useGetUserCommentsReactionsQuery({
variables: {
Expand All @@ -42,9 +42,15 @@ export const useUserCommentsReactions = (videoId?: string | null, memberId?: str

return useMemo(
() => ({
userReactions: data?.commentReactions.reduce<Record<string, number[]>>((acc, item) => {
userReactions: data?.commentReactions.reduce<UserCommentReactions>((acc, item) => {
if (item) {
acc[item.comment.id] = [...(acc[item.comment.id] ? acc[item.comment.id] : []), item.reactionId]
acc[item.comment.id] = [
...(acc[item.comment.id] ? acc[item.comment.id] : []),
{
reactionId: item.reactionId,
reactionServerId: item.id,
},
]
}
return acc
}, {}),
Expand Down
38 changes: 38 additions & 0 deletions packages/atlas/src/api/hooks/useCommentSectionComments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { QueryHookOptions } from '@apollo/client'

import { UNCONFIRMED } from '@/hooks/useOptimisticActions'
import { createLookup } from '@/utils/data'

import {
GetUserCommentsAndVideoCommentsConnectionQuery,
GetUserCommentsAndVideoCommentsConnectionQueryVariables,
useGetUserCommentsAndVideoCommentsConnectionQuery,
} from '../queries/__generated__/comments.generated'

export const useCommentSectionComments = (
variables?: GetUserCommentsAndVideoCommentsConnectionQueryVariables,
opts?: QueryHookOptions<
GetUserCommentsAndVideoCommentsConnectionQuery,
GetUserCommentsAndVideoCommentsConnectionQueryVariables
>
) => {
const { data, loading, ...rest } = useGetUserCommentsAndVideoCommentsConnectionQuery({ ...opts, variables })
const userComments = data?.userComments
const userCommentLookup = data?.userComments && createLookup(data?.userComments)
const unconfirmedComments = data?.videoCommentsConnection.edges
.map((edge) => edge.node)
.filter((node) => node.id.includes(UNCONFIRMED))
const unconfirmedCommentLookup = unconfirmedComments && createLookup(unconfirmedComments)

const videoComments = data?.videoCommentsConnection?.edges
.map((edge) => edge.node)
.filter((comment) => userCommentLookup && !userCommentLookup[comment.id] && !unconfirmedCommentLookup?.[comment.id])

return {
userComments,
comments: data ? [...(unconfirmedComments || []), ...(userComments || []), ...(videoComments || [])] : undefined,
loading: loading,
pageInfo: data?.videoCommentsConnection?.pageInfo,
...rest,
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading