-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
136 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import gql from 'graphql-tag' | ||
|
||
export const AUTHOR_SIDEBAR_COLLECTION = gql` | ||
query AuthorSidebarCollection($id: ID!, $after: String) { | ||
node(input: { id: $id }) { | ||
id | ||
... on Collection { | ||
id | ||
title | ||
description | ||
articles(input: { first: 40, after: $after }) { | ||
totalCount | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
edges { | ||
cursor | ||
node { | ||
id | ||
title | ||
cover | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` |
66 changes: 66 additions & 0 deletions
66
src/views/ArticleDetail/AuthorSidebar/Collection/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { toPath } from '~/common/utils' | ||
import { LinkWrapper, QueryError, Throw404, usePublicQuery } from '~/components' | ||
import { | ||
ArticleDetailPublicQuery, | ||
AuthorSidebarCollectionQuery, | ||
} from '~/gql/graphql' | ||
|
||
import { FeedPlaceholder } from '../Placeholder' | ||
import { AUTHOR_SIDEBAR_COLLECTION } from './gql' | ||
import styles from './styles.module.css' | ||
|
||
type CollectionProps = { | ||
collectionId: string | ||
article: ArticleDetailPublicQuery['article'] | ||
} | ||
|
||
export const Collection = ({ article, collectionId }: CollectionProps) => { | ||
/** | ||
* Data Fetching | ||
*/ | ||
const { data, loading, error } = usePublicQuery<AuthorSidebarCollectionQuery>( | ||
AUTHOR_SIDEBAR_COLLECTION, | ||
{ | ||
variables: { id: collectionId }, | ||
} | ||
) | ||
const collection = data?.node! | ||
|
||
/** | ||
* Render | ||
*/ | ||
if (loading) { | ||
return <FeedPlaceholder /> | ||
} | ||
|
||
if (error) { | ||
return <QueryError error={error} /> | ||
} | ||
|
||
if (!collection || collection.__typename !== 'Collection') { | ||
return <Throw404 /> | ||
} | ||
|
||
const collectionDetailPath = toPath({ | ||
page: 'collectionDetail', | ||
userName: article?.author.userName || '', | ||
collection: { | ||
id: collection.id, | ||
}, | ||
}) | ||
|
||
return ( | ||
<section className={styles.container}> | ||
<LinkWrapper {...collectionDetailPath}> | ||
<title>{collection.title}</title> | ||
</LinkWrapper> | ||
{collection.description && ( | ||
<LinkWrapper {...collectionDetailPath}> | ||
<section className={styles.description}> | ||
{collection.description} | ||
</section> | ||
</LinkWrapper> | ||
)} | ||
</section> | ||
) | ||
} |
26 changes: 26 additions & 0 deletions
26
src/views/ArticleDetail/AuthorSidebar/Collection/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.container { | ||
@mixin border-grey; | ||
|
||
display: flex; | ||
flex-direction: column; | ||
padding: var(--spacing-tight) var(--spacing-base); | ||
border-color: var(--color-grey-lighter-active); | ||
border-radius: 0.5rem; | ||
|
||
& title { | ||
@mixin line-clamp; | ||
|
||
-webkit-line-clamp: 2; | ||
margin-bottom: var(--spacing-x-tight); | ||
font-weight: var(--font-weight-medium); | ||
} | ||
|
||
& .description { | ||
@mixin line-clamp; | ||
|
||
-webkit-line-clamp: 4; | ||
margin-bottom: var(--spacing-tight); | ||
font-size: var(--font-size-xs); | ||
color: var(--color-grey-darker); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters