diff --git a/src/views/Me/DraftDetail/Sidebar/AddCover/index.tsx b/src/views/Me/DraftDetail/Sidebar/AddCover/index.tsx
index ef53e68c0b..5bf049bdb8 100644
--- a/src/views/Me/DraftDetail/Sidebar/AddCover/index.tsx
+++ b/src/views/Me/DraftDetail/Sidebar/AddCover/index.tsx
@@ -10,7 +10,10 @@ import { useMutation } from '~/components/GQL'
import Collapsable from '../Collapsable'
import styles from './styles.css'
-import { AddCoverDraft } from './__generated__/AddCoverDraft'
+import {
+ AddCoverDraft,
+ AddCoverDraft_assets
+} from './__generated__/AddCoverDraft'
import { UpdateDraftCover } from './__generated__/UpdateDraftCover'
const fragments = {
@@ -29,7 +32,7 @@ const fragments = {
}
const UPDATE_COVER = gql`
- mutation UpdateDraftCover($id: ID!, $coverAssetId: ID!) {
+ mutation UpdateDraftCover($id: ID!, $coverAssetId: ID) {
putDraft(input: { id: $id, coverAssetId: $coverAssetId }) {
id
...AddCoverDraft
@@ -40,47 +43,62 @@ const UPDATE_COVER = gql`
const CoverList = ({
draftId,
- update,
- updateHeaderState,
cover,
assets
}: {
draftId: string
- update: any
- updateHeaderState: any
cover: string | null
- assets: any
+ assets: AddCoverDraft_assets[]
}) => {
- const uniqAssets = _uniqBy(assets, 'path') as any
- return uniqAssets.map((asset: any, index: number) => {
- const css = classNames({
- 'cover-image': true,
- 'cover-selected': asset.path === cover
- })
- return (
-
{
- updateHeaderState({ type: 'draft', state: 'saving', draftId })
- try {
- await update({ variables: { id: draftId, coverAssetId: asset.id } })
- updateHeaderState({ type: 'draft', state: 'saved', draftId })
- } catch (error) {
- updateHeaderState({ type: 'draft', state: 'saveFailed', draftId })
- }
- }}
- >
-
-
- )
- })
+ const [update] = useMutation(UPDATE_COVER)
+ const { updateHeaderState } = useContext(HeaderContext)
+
+ const uniqAssets = _uniqBy(assets, 'path')
+
+ return (
+
+ {uniqAssets.map((asset, index) => {
+ const isSelected = asset.path === cover
+ const coverItemClass = classNames({
+ 'cover-image': true,
+ selected: isSelected
+ })
+
+ return (
+ {
+ updateHeaderState({ type: 'draft', state: 'saving', draftId })
+ try {
+ await update({
+ variables: {
+ id: draftId,
+ coverAssetId: asset.id
+ }
+ })
+ updateHeaderState({ type: 'draft', state: 'saved', draftId })
+ } catch (error) {
+ updateHeaderState({
+ type: 'draft',
+ state: 'saveFailed',
+ draftId
+ })
+ }
+ }}
+ >
+
+
+ )
+ })}
+
+ )
}
const AddCover = ({ draft }: { draft: AddCoverDraft }) => {
- const [update] = useMutation(UPDATE_COVER)
- const { updateHeaderState } = useContext(HeaderContext)
const { id: draftId, cover, assets } = draft
const imageAssets = assets.filter(
({ type }: { type: string }) => type === 'embed'
@@ -93,30 +111,27 @@ const AddCover = ({ draft }: { draft: AddCoverDraft }) => {
'u-area-disable': isPending || isPublished
})
- if (imageAssets.length <= 0) {
- return null
- }
-
return (
}
- defaultCollapsed={!hasAssets}
+ defaultCollapsed={false}
>
-
+ {hasAssets ? (
+
+ ) : (
+
+ )}
diff --git a/src/views/Me/DraftDetail/Sidebar/AddCover/styles.css b/src/views/Me/DraftDetail/Sidebar/AddCover/styles.css
index 594be8c64f..dc8625af1f 100644
--- a/src/views/Me/DraftDetail/Sidebar/AddCover/styles.css
+++ b/src/views/Me/DraftDetail/Sidebar/AddCover/styles.css
@@ -2,7 +2,6 @@
display: flex;
align-items: center;
- padding-bottom: 1rem;
overflow-x: scroll;
}
@@ -14,14 +13,15 @@
}
.cover-image {
- border: 4px solid var(--color-white);
- cursor: pointer;
display: inline-block;
margin-right: 1rem;
padding: 2.3125rem;
-}
-.cover-selected {
- border: 4px solid var(--color-matters-green);
- cursor: initial;
+ border: 4px solid var(--color-white);
+ cursor: pointer;
+
+ &.selected {
+ border-color: var(--color-matters-green);
+ cursor: initial;
+ }
}