From b25686a540bba6da65d2cd63aa0db9d21a677a18 Mon Sep 17 00:00:00 2001 From: velopert Date: Tue, 24 Mar 2020 23:11:56 +0900 Subject: [PATCH] Create back button on WriteFooter - Close #90 --- src/components/write/WriteFooter.tsx | 54 ++++++++++++++++--- .../write/__tests__/WriteFooter.test.tsx | 10 +++- .../__snapshots__/WriteFooter.test.tsx.snap | 42 +++++++++++---- .../write/MarkdownEditorContainer.tsx | 5 ++ .../write/__tests__/ActiveEditor.test.tsx | 9 ++-- .../__snapshots__/ActiveEditor.test.tsx.snap | 50 ++++++++++++----- 6 files changed, 137 insertions(+), 33 deletions(-) diff --git a/src/components/write/WriteFooter.tsx b/src/components/write/WriteFooter.tsx index b8614ea5..942199a6 100644 --- a/src/components/write/WriteFooter.tsx +++ b/src/components/write/WriteFooter.tsx @@ -1,6 +1,9 @@ import * as React from 'react'; import styled from 'styled-components'; import Button from '../common/Button'; +import { MdArrowBack } from 'react-icons/md'; +import media from '../../lib/styles/media'; +import { useHistory } from 'react-router-dom'; const WriteFooterBlock = styled.div` padding-left: 1rem; @@ -10,6 +13,11 @@ const WriteFooterBlock = styled.div` box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.1); background: rgba(255, 255, 255, 0.85); display: flex; + justify-content: space-between; + align-items: center; +`; + +const Group = styled.div` justify-content: flex-end; align-items: center; `; @@ -22,25 +30,59 @@ const StyledButton = styled(Button)` } `; +const BackButton = styled.button` + height: 2.5rem; + padding: 0.5rem 1rem; + align-items: center; + background: none; + border-radius: 4px; + cursor: pointer; + border: none; + display: flex; + outline: none; + &:hover, + &:focus { + background: rgba(0, 0, 0, 0.05); + } + svg { + font-size: 1.25rem; + margin-right: 0.5rem; + } + span { + font-size: 1.125rem; + ${media.xsmall} { + display: none; + } + } +`; + export interface WriteFooterProps { onTempSave: (notify?: boolean) => void; onPublish: () => void; + onGoBack: () => void; edit: boolean; } const WriteFooter: React.FC = ({ + onGoBack, onTempSave, onPublish, edit, }) => { return ( - onTempSave(true)}> - 임시저장 - - - {edit ? '수정하기' : '출간하기'} - + + + 나가기 + + + onTempSave(true)}> + 임시저장 + + + {edit ? '수정하기' : '출간하기'} + + ); }; diff --git a/src/components/write/__tests__/WriteFooter.test.tsx b/src/components/write/__tests__/WriteFooter.test.tsx index 55847a19..46a6aeb0 100644 --- a/src/components/write/__tests__/WriteFooter.test.tsx +++ b/src/components/write/__tests__/WriteFooter.test.tsx @@ -5,6 +5,8 @@ import WriteFooter, { WriteFooterProps } from '../WriteFooter'; describe('WriteFooter', () => { const setup = (props: Partial = {}) => { const initialProps: WriteFooterProps = { + edit: false, + onGoBack: () => {}, onPublish: () => {}, onTempSave: () => {}, }; @@ -12,6 +14,7 @@ describe('WriteFooter', () => { const buttons = { tempSave: utils.getByText('임시저장'), publish: utils.getByText(/(출간|수정)하기/), + goBack: utils.getByText('나가기'), }; return { ...utils, @@ -28,12 +31,15 @@ describe('WriteFooter', () => { it('buttons are working properly', () => { const onPublish = jest.fn(); const onTempSave = jest.fn(); - const utils = setup({ onPublish, onTempSave }); - const { tempSave, publish } = utils.buttons; + const onGoBack = jest.fn(); + const utils = setup({ onPublish, onTempSave, onGoBack }); + const { tempSave, publish, goBack } = utils.buttons; fireEvent.click(tempSave); expect(onTempSave).toBeCalled(); fireEvent.click(publish); expect(onPublish).toBeCalled(); + fireEvent.click(goBack); + expect(onGoBack).toBeCalled(); }); it('changes button text when edit is true', () => { const { buttons } = setup({ diff --git a/src/components/write/__tests__/__snapshots__/WriteFooter.test.tsx.snap b/src/components/write/__tests__/__snapshots__/WriteFooter.test.tsx.snap index c08fc065..3ef4c439 100644 --- a/src/components/write/__tests__/__snapshots__/WriteFooter.test.tsx.snap +++ b/src/components/write/__tests__/__snapshots__/WriteFooter.test.tsx.snap @@ -3,20 +3,44 @@ exports[`WriteFooter matches snapshot 1`] = `
- + + +
`; diff --git a/src/containers/write/MarkdownEditorContainer.tsx b/src/containers/write/MarkdownEditorContainer.tsx index 7aa9a25e..f32574ca 100644 --- a/src/containers/write/MarkdownEditorContainer.tsx +++ b/src/containers/write/MarkdownEditorContainer.tsx @@ -69,6 +69,10 @@ const MarkdownEditorContainer: React.FC = () => { body: initialBody, }); + const onGoBack = () => { + history.goBack(); + }; + useEffect(() => { setLastSavedData({ title: initialTitle, @@ -270,6 +274,7 @@ const MarkdownEditorContainer: React.FC = () => { } diff --git a/src/containers/write/__tests__/ActiveEditor.test.tsx b/src/containers/write/__tests__/ActiveEditor.test.tsx index ca16a64b..51469dd7 100644 --- a/src/containers/write/__tests__/ActiveEditor.test.tsx +++ b/src/containers/write/__tests__/ActiveEditor.test.tsx @@ -2,13 +2,16 @@ import * as React from 'react'; import ActiveEditor, { ActiveEditorProps } from '../ActiveEditor'; import renderWithProviders from '../../../lib/renderWithProviders'; import { HelmetProvider } from 'react-helmet-async'; +import { MemoryRouter } from 'react-router-dom'; describe('ActiveEditor', () => { const setup = (props: Partial = {}) => { const utils = renderWithProviders( - - - , + + + + + , ); return { ...utils, diff --git a/src/containers/write/__tests__/__snapshots__/ActiveEditor.test.tsx.snap b/src/containers/write/__tests__/__snapshots__/ActiveEditor.test.tsx.snap index f5f2978b..023b96f0 100644 --- a/src/containers/write/__tests__/__snapshots__/ActiveEditor.test.tsx.snap +++ b/src/containers/write/__tests__/__snapshots__/ActiveEditor.test.tsx.snap @@ -346,20 +346,44 @@ exports[`ActiveEditor matches snapshot 1`] = ` style="width: 50%;" >
- + + +
@@ -370,17 +394,17 @@ exports[`ActiveEditor matches snapshot 1`] = ` style="background-color: rgb(251, 253, 252);" >