Skip to content

Commit

Permalink
Merge pull request #3870 from thematters/fix/add-article-to-collectio…
Browse files Browse the repository at this point in the history
…n-cache

fix(collection): correct local cache on adding articles to collection
  • Loading branch information
robertu7 authored Oct 6, 2023
2 parents ade15d6 + aa71c4e commit 3778930
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 30 deletions.
4 changes: 1 addition & 3 deletions src/components/CollectionDigest/Feed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type MemoizedCollectionDigestFeed = React.MemoExoticComponent<
fragments: typeof fragments
}

const CollectionDigestFeed = React.memo(
export const CollectionDigestFeed = React.memo(
BaseCollectionDigestFeed,
({ collection: prevCollection }, { collection }) => {
return (
Expand All @@ -134,5 +134,3 @@ const CollectionDigestFeed = React.memo(

CollectionDigestFeed.Placeholder = Placeholder
CollectionDigestFeed.fragments = fragments

export default CollectionDigestFeed
6 changes: 1 addition & 5 deletions src/components/CollectionDigest/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import Feed from './Feed'

export const CollectionDigest = {
Feed,
}
export * from './Feed'
4 changes: 1 addition & 3 deletions src/components/Dialogs/AddArticlesCollectionDialog/gql.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import gql from 'graphql-tag'

// circular dependencies? 👇
// import { ArticleDigestFeed } from '~/components'
import { ArticleDigestFeed } from '../../ArticleDigest/Feed'
import { ArticleDigestFeed } from '~/components/ArticleDigest/Feed'

export const fragments = {
user: gql`
Expand Down
4 changes: 2 additions & 2 deletions src/components/Dialogs/AddCollectionDialog/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FormattedMessage, useIntl } from 'react-intl'
import { KEYVALUE } from '~/common/enums'
import { toPath, validateCollectionTitle } from '~/common/utils'
import {
CollectionDigest,
CollectionDigestFeed,
Dialog,
Form,
LanguageContext,
Expand Down Expand Up @@ -38,7 +38,7 @@ const CREATE_COLLECTION = gql`
...CollectionDigestFeedCollection
}
}
${CollectionDigest.Feed.fragments.collection}
${CollectionDigestFeed.fragments.collection}
`

const AddCollectionDialogContent: React.FC<FormProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ const SelectDialogContent: React.FC<SelectDialogContentProps> = ({
const { data, loading } =
usePublicQuery<AddCollectionsArticleUserPublicQuery>(
ADD_COLLECTIONS_ARTICLE_USER_PUBLIC,
{
variables: { userName, id: articleId },
}
{ variables: { userName, id: articleId }, fetchPolicy: 'network-only' }
)

const user = data?.user
Expand Down
7 changes: 7 additions & 0 deletions src/components/Dialogs/AddCollectionsArticleDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const BaseAddCollectionsArticleDialog = ({
children,
articleId,
}: AddCollectionsArticleDialogProps) => {
// FIXME: circular dependencies
const { COLLECTION_DETAIL } = require('~/views/User/CollectionDetail/gql')

const viewer = useContext(ViewerContext)
const { getQuery } = useRoute()

Expand Down Expand Up @@ -77,6 +80,10 @@ const BaseAddCollectionsArticleDialog = ({
query: USER_COLLECTIONS,
variables: { userName: viewer.userName },
},
{
query: COLLECTION_DETAIL,
variables: { id: checked[0] },
},
],
})

Expand Down
10 changes: 5 additions & 5 deletions src/stories/components/CollectionDigest/Feed.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { MockedProvider } from '@apollo/react-testing'
import { ComponentMeta, ComponentStory } from '@storybook/react'
import React from 'react'

import { CollectionDigest } from '~/components'
import { CollectionDigestFeed } from '~/components'

import { MOCK_COLLECTION } from '../../mocks'

export default {
title: 'Components/CollectionDigest',
component: CollectionDigest.Feed,
} as ComponentMeta<typeof CollectionDigest.Feed>
component: CollectionDigestFeed,
} as ComponentMeta<typeof CollectionDigestFeed>

const Template: ComponentStory<typeof CollectionDigest.Feed> = (args) => (
const Template: ComponentStory<typeof CollectionDigestFeed> = (args) => (
<MockedProvider>
<CollectionDigest.Feed {...args} />
<CollectionDigestFeed {...args} />
</MockedProvider>
)

Expand Down
5 changes: 3 additions & 2 deletions src/views/User/CollectionDetail/CollectionArticles/gql.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import gql from 'graphql-tag'

import { ArticleDigestFeed, CollectionDigest } from '~/components'
import { ArticleDigestFeed } from '~/components/ArticleDigest/Feed'
import { CollectionDigestFeed } from '~/components/CollectionDigest/Feed'

export const fragments = {
collection: gql`
Expand All @@ -22,6 +23,6 @@ export const fragments = {
}
${ArticleDigestFeed.fragments.article.public}
${ArticleDigestFeed.fragments.article.private}
${CollectionDigest.Feed.fragments.collection}
${CollectionDigestFeed.fragments.collection}
`,
}
8 changes: 4 additions & 4 deletions src/views/User/Collections/Placeholder/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { CollectionDigest, List } from '~/components'
import { CollectionDigestFeed, List } from '~/components'

const Placeholder = () => {
return (
<List aria-busy="true" aria-live="polite">
<List.Item>
<CollectionDigest.Feed.Placeholder />
<CollectionDigestFeed.Placeholder />
</List.Item>
<List.Item>
<CollectionDigest.Feed.Placeholder />
<CollectionDigestFeed.Placeholder />
</List.Item>
<List.Item>
<CollectionDigest.Feed.Placeholder />
<CollectionDigestFeed.Placeholder />
</List.Item>
</List>
)
Expand Down
4 changes: 2 additions & 2 deletions src/views/User/Collections/UserCollections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PROFILE_COVER_DEFAULT from '@/public/static/images/profile-cover.png'
import { analytics, mergeConnections, stripSpaces } from '~/common/utils'
import {
AddCollectionDialog,
CollectionDigest,
CollectionDigestFeed,
Empty,
Head,
IconAdd20,
Expand Down Expand Up @@ -169,7 +169,7 @@ const UserCollections = () => {
<List>
{edges.map(({ node, cursor }, i) => (
<List.Item key={node.id}>
<CollectionDigest.Feed
<CollectionDigestFeed
collection={node}
onClick={() =>
analytics.trackEvent('click_feed', {
Expand Down
2 changes: 1 addition & 1 deletion src/views/User/Collections/gql.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gql from 'graphql-tag'

import CollectionDigestFeed from '~/components/CollectionDigest/Feed'
import { CollectionDigestFeed } from '~/components/CollectionDigest/Feed'

const fragments = gql`
fragment CollectionsUser on User {
Expand Down

1 comment on commit 3778930

@vercel
Copy link

@vercel vercel bot commented on 3778930 Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.