Skip to content

Commit 4997016

Browse files
committed
add shell AddTagModal
1 parent cbb0f2c commit 4997016

File tree

4 files changed

+67
-16
lines changed

4 files changed

+67
-16
lines changed

explorer/components/DrawingPage/ActionsMenu.tsx

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@ import React from 'react'
22
import styled from 'styled-components'
33
import { navBarItemStyles } from './styles'
44
import { useCookies } from 'react-cookie'
5+
import { Drawing } from '../../types'
6+
import { AddTagModal } from './AddTagModal'
57

68
type Action = {
79
title: string
810
onClick: () => void
911
}
1012

11-
export const ActionsMenu: React.FC = () => {
13+
export const ActionsMenu: React.FC<{ drawing: Drawing }> = ({ drawing }) => {
1214
const [isActive, setIsActive] = React.useState(false)
1315
const [cookies] = useCookies(['feature__myTags'])
1416
const [actions, setActions] = React.useState<Action[]>([])
17+
const [isAddTagModalOpen, setIsAddTagModalOpen] = React.useState(false)
1518

16-
const addNewTag = { title: 'Add new tag', onClick: () => alert('add new tag') }
19+
const toggleAddTagModal = () => setIsAddTagModalOpen(!isAddTagModalOpen)
20+
const addNewTag = { title: 'Add hashtags', onClick: toggleAddTagModal }
1721

1822
React.useEffect(() => {
1923
const newActions = []
@@ -22,18 +26,21 @@ export const ActionsMenu: React.FC = () => {
2226
}, [cookies])
2327

2428
return (
25-
<Container title='Actions' onClick={() => setIsActive(!isActive)} isHidden={!actions.length}>
26-
<svg viewBox="0 0 24 24">
27-
<circle cx="5" cy="12" r="2" />
28-
<circle cx="12" cy="12" r="2" />
29-
<circle cx="19" cy="12" r="2" />
30-
</svg>
31-
<Popup isActive={isActive}>
32-
{actions.map(action => (
33-
<Item key={action.title}><a onClick={action.onClick}>{action.title}</a></Item>
34-
))}
35-
</Popup>
36-
</Container>
29+
<>
30+
<Container title='Actions' onClick={() => setIsActive(!isActive)} isHidden={!actions.length}>
31+
<svg viewBox="0 0 24 24">
32+
<circle cx="5" cy="12" r="2" />
33+
<circle cx="12" cy="12" r="2" />
34+
<circle cx="19" cy="12" r="2" />
35+
</svg>
36+
<Popup isActive={isActive}>
37+
{actions.map(action => (
38+
<Item key={action.title}><a onClick={action.onClick}>{action.title}</a></Item>
39+
))}
40+
</Popup>
41+
</Container>
42+
<AddTagModal drawing={drawing} isOpen={isAddTagModalOpen} closeModal={toggleAddTagModal} />
43+
</>
3744
)
3845
}
3946

@@ -61,4 +68,6 @@ const Popup = styled.div.attrs({ className: 'Explorer__ActionsMenu__Popup'})<{ i
6168
width: 200px;
6269
`
6370

64-
const Item = styled.div.attrs({ className: 'Explorer__ActionsMenu__Item'})``
71+
const Item = styled.div.attrs({ className: 'Explorer__ActionsMenu__Item'})`
72+
font-size: 24px;
73+
`
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react'
2+
import styled from 'styled-components'
3+
import { Drawing } from '../../types'
4+
import Modal from 'react-modal'
5+
6+
export const AddTagModal: React.FC<{ drawing: Drawing; isOpen: boolean; closeModal: () => void }> = ({
7+
drawing,
8+
isOpen,
9+
closeModal,
10+
}) => {
11+
const onNewTagSubmit: (e: React.FormEvent) => void = (e) => {
12+
e.preventDefault()
13+
}
14+
15+
return (
16+
<Modal
17+
isOpen={isOpen}
18+
onRequestClose={closeModal}
19+
>
20+
<CloseButton onClick={closeModal}>close</CloseButton>
21+
<Title>Add Hashtags</Title>
22+
<pre>{JSON.stringify(drawing, null, 2)}</pre>
23+
<form onSubmit={onNewTagSubmit}>
24+
New: <input /> <input type='submit' />
25+
</form>
26+
</Modal>
27+
)
28+
}
29+
30+
const CloseButton = styled.button.attrs({ classNames: 'Explorer__AddTagModal__CloseButton' })`
31+
font-size: 24px;
32+
position: absolute;
33+
right: 24px;
34+
top: 24px;
35+
`
36+
37+
const Title = styled.h1.attrs({ classNames: 'Explorer__AddTagModal__CloseButton' })`
38+
text-align: center;
39+
`

explorer/components/DrawingPage/DrawingPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const DrawingPage: React.FC<{ drawing: Drawing, year: number }> = ({ draw
5757
<Link href="/day/[id]" as={`/day/${drawing.date}`}>
5858
<DateLink title={`Drawings for ${drawing.date}`}><b>{drawing.date.slice(5)}</b></DateLink>
5959
</Link>
60-
<ActionsMenu />
60+
<ActionsMenu drawing={drawing} />
6161
<Link href="/drawing/[id]" as={`/drawing/${getNextSlug(drawing.slug)}`}>
6262
<ArrowButton title='Next'><RightArrow /></ArrowButton>
6363
</Link>

explorer/pages/_app.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { AppFlags } from '../components/AppFlags'
22
import { AppStyle } from '../components/AppStyle'
33
import { CookiesProvider } from 'react-cookie'
4+
import Modal from 'react-modal'
5+
6+
Modal.setAppElement('#__next')
47

58
export default function App({ Component, pageProps }) {
69
return (

0 commit comments

Comments
 (0)