-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): update space document title, space document list (#50)
* Add Cover Photo for CoverPage * Update Document Title, and Add Left Side Document List
- Loading branch information
1 parent
2b7f327
commit 50ec1d0
Showing
14 changed files
with
830 additions
and
63 deletions.
There are no files selected for viewing
45 changes: 0 additions & 45 deletions
45
apps/ikigai/components/DocumentV2/DocumentBody/CoverPage.tsx
This file was deleted.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
apps/ikigai/components/DocumentV2/DocumentBody/CoverPage/CoverHeader.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,96 @@ | ||
import styled from "styled-components"; | ||
import { Trans } from "@lingui/macro"; | ||
import React from "react"; | ||
|
||
import { Button } from "components/common/Button"; | ||
import { DraggerStyled } from "components/common/FileUpload"; | ||
import { PictureIcon } from "components/common/IconSvg"; | ||
import useDocumentStore from "context/DocumentV2Store"; | ||
|
||
const CoverHeader = () => { | ||
const activeDocument = useDocumentStore((state) => state.activeDocument); | ||
|
||
return ( | ||
<Container> | ||
<DocumentPhotoCover> | ||
{activeDocument.coverPhotoUrl && ( | ||
<img src={activeDocument.coverPhotoUrl} alt="photoCover" /> | ||
)} | ||
<EditCoverButton size="large" icon={<PictureIcon />}> | ||
<Trans>Edit Cover</Trans> | ||
</EditCoverButton> | ||
</DocumentPhotoCover> | ||
</Container> | ||
); | ||
}; | ||
|
||
const Container = styled.div` | ||
width: 100%; | ||
min-height: 50px; | ||
`; | ||
|
||
const EditCoverButton = styled(Button)` | ||
&&& { | ||
box-shadow: rgba(15, 15, 15, 0.1) 0px 0px 0px 1px, | ||
rgba(15, 15, 15, 0.1) 0px 2px 4px; | ||
height: 34px; | ||
position: absolute; | ||
bottom: 16px; | ||
right: 16px; | ||
border: none; | ||
opacity: 0; | ||
font-size: 13px; | ||
font-weight: 500; | ||
transition: opacity 0.3s; | ||
.ant-btn-icon { | ||
margin-inline-end: 0px; | ||
} | ||
} | ||
`; | ||
|
||
const DocumentPhotoCover = styled.div` | ||
display: grid; | ||
width: 100%; | ||
height: 30vh; | ||
background-color: ${(props) => props.theme.colors.primary[5]}; | ||
position: relative; | ||
cursor: pointer; | ||
img { | ||
display: block; | ||
object-fit: cover; | ||
border-radius: 0px; | ||
width: 100%; | ||
height: 30vh; | ||
opacity: 1; | ||
object-position: center 50%; | ||
} | ||
&&& { | ||
span { | ||
font-size: 13px; | ||
font-weight: 500; | ||
} | ||
svg { | ||
height: 16px; | ||
margin-inline-end: 4px; | ||
} | ||
&:hover { | ||
${EditCoverButton} { | ||
opacity: 1; | ||
} | ||
} | ||
${DraggerStyled} { | ||
div { | ||
border: none; | ||
align-items: self-start; | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export default CoverHeader; |
90 changes: 90 additions & 0 deletions
90
apps/ikigai/components/DocumentV2/DocumentBody/CoverPage/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,90 @@ | ||
import { useEffect } from "react"; | ||
import { Divider, Input } from "antd"; | ||
import { t } from "@lingui/macro"; | ||
import styled from "styled-components"; | ||
import { useDebounce } from "ahooks"; | ||
import { useMutation } from "@apollo/client"; | ||
|
||
import { BreakPoints } from "styles/mediaQuery"; | ||
import useDocumentStore from "context/DocumentV2Store"; | ||
import CoverHeader from "./CoverHeader"; | ||
import { UPDATE_DOCUMENT } from "graphql/mutation/SpaceMutation"; | ||
import { handleError } from "graphql/ApolloClient"; | ||
import { UpdateDocumentData } from "graphql/types"; | ||
|
||
const CoverPage = () => { | ||
const [updateDocumentServer] = useMutation(UPDATE_DOCUMENT, { | ||
onError: handleError, | ||
}); | ||
const activeDocumentId = useDocumentStore((state) => state.activeDocumentId); | ||
const activeDocumentTitle = useDocumentStore( | ||
(state) => state.activeDocument?.title, | ||
); | ||
const activeDocument = useDocumentStore((state) => state.activeDocument); | ||
const updateActiveDocument = useDocumentStore( | ||
(state) => state.updateActiveDocument, | ||
); | ||
const updateSpaceDocument = useDocumentStore( | ||
(state) => state.updateSpaceDocument, | ||
); | ||
const debouncedTitle = useDebounce(activeDocumentTitle, { wait: 500 }); | ||
|
||
useEffect(() => { | ||
const updateDocumentData: UpdateDocumentData = { | ||
title: debouncedTitle || "", | ||
coverPhotoId: activeDocument.coverPhotoId, | ||
editorConfig: activeDocument.editorConfig, | ||
body: activeDocument.body, | ||
}; | ||
updateDocumentServer({ | ||
variables: { | ||
documentId: activeDocumentId, | ||
data: updateDocumentData, | ||
}, | ||
}); | ||
}, [debouncedTitle]); | ||
|
||
const changeTitle = (value: string) => { | ||
updateActiveDocument({ title: value }); | ||
updateSpaceDocument(activeDocumentId, { title: value }); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<CoverHeader /> | ||
<div style={{ padding: 20 }}> | ||
<DocumentTitle | ||
autoSize | ||
variant="borderless" | ||
maxLength={255} | ||
value={activeDocumentTitle} | ||
onChange={(e) => changeTitle(e.currentTarget.value)} | ||
placeholder={t`Untitled`} | ||
/> | ||
<Divider /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const DocumentTitle = styled(Input.TextArea)` | ||
&&& { | ||
font-size: 40px; | ||
font-weight: 700; | ||
padding-left: 0; | ||
overflow: hidden; | ||
line-height: normal; | ||
&:focus { | ||
outline: none !important; | ||
box-shadow: none !important; | ||
border-color: transparent !important; | ||
} | ||
${BreakPoints.tablet} { | ||
font-size: 32px; | ||
} | ||
} | ||
`; | ||
|
||
export default CoverPage; |
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
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
Oops, something went wrong.