-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
209 lines (200 loc) · 6.67 KB
/
Copy pathtest.js
File metadata and controls
209 lines (200 loc) · 6.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import { useState } from 'react'
import { useQuery } from '@apollo/client'
import { useRouter } from 'next/router'
import Modal from 'react-modal'
import { activeCategoryVar, activeSideBarVar } from '../lib/withApollo'
import {
Button,
TodoListOptionsBox,
AddTodoListModal,
AddTodoModal,
Loading
} from './index'
import { Cross, Plus } from './icons/index'
import {
TodoLists as TODO_LISTS_QUERY,
ActiveCategory as ACTIVE_CATEGORY,
ActiveSideBar as ACTIVE_SIDEBAR
} from '../queries/index'
const TodoLists = ({ getTodos }) => {
const { loading, error, data } = useQuery(TODO_LISTS_QUERY)
if (loading || !data) return <Loading />
if (error) return 'Error'
const {
data: { activeCategory }
} = useQuery(ACTIVE_CATEGORY)
const {
data: { activeSideBar }
} = useQuery(ACTIVE_SIDEBAR)
const [modalIsOpen, setModalIsOpen] = useState(false)
const openModal = () => {
setModalIsOpen(true)
}
const closeModal = () => {
setModalIsOpen(false)
}
const router = useRouter()
return (
<div
className={`${
activeSideBar ? 'inline-block' : 'hidden'
} mr-8 md:mr-0 w-full md:flex md:flex-col h-screen flex-none top-0 bg-purple-900`}
>
<div className='bg-purple-900 flex-grow-0 px-2 border-b flex justify-between'>
<h1 className='text-white text-xl my-3'>Lists</h1>
<div
className='h-8 w-8 cursor-pointer hover:text-white text-gray-200 md:hidden'
onClick={() => activeSideBarVar(false)}
>
<Cross />
</div>
</div>
<div className='h-full flex-grow overflow-y-hidden relative'>
<div className='absolute inset-0 overflow-y-auto scrollbar-thin scrollbar-thumb-gray-500 scrollbar-track-gray-300 scrollbar-thumb-rounded'>
<ul className='px-2 pb-2'>
<div
className={`${activeCategory === 'Oldest' &&
'font-bold'} cursor-pointer py-1 px-1 hover:bg-purple-800`}
onClick={() => {
getTodos({ variables: { oldest: true } })
activeSideBarVar(false)
activeCategoryVar('Oldest')
router.push(`/`, undefined, {
shallow: true
})
}}
>
<span
className={`${activeCategory === 'Oldest' &&
'font-bold'} cursor-pointer flex text-md hover:text-white text-gray-200`}
>
Oldest
</span>
</div>
<div
className='cursor-pointer py-1 px-1 hover:bg-purple-800'
onClick={() => {
getTodos({ variables: { newest: true } })
activeSideBarVar(false)
activeCategoryVar('Newest')
router.push(`/`, undefined, {
shallow: true
})
}}
>
<span
className={`${activeCategory === 'Newest' &&
'font-bold'} cursor-pointer flex text-md hover:text-white text-gray-200`}
>
Newest
</span>
</div>
<div
className='cursor-pointer py-1 px-1 hover:bg-purple-800'
onClick={() => {
getTodos({ variables: { pinned: true } })
activeSideBarVar(false)
activeCategoryVar('Pinned')
router.push(`/`, undefined, {
shallow: true
})
}}
>
<span
className={`${activeCategory === 'Pinned' &&
'font-bold'} cursor-pointer flex text-md hover:text-white text-gray-200`}
>
Pinned
</span>
</div>
{data.todoLists.map(todoList => (
<TodoList
key={todoList.id}
activeCategory={activeCategory}
getTodos={getTodos}
todoList={todoList}
/>
))}
</ul>
<div className='mt-3 ml-3'>
<Button onClick={openModal}>New todolist</Button>
<Modal
className='bg-white outline-none bottom-0 left-0 absolute rounded-t-lg border-2 px-2'
isOpen={modalIsOpen}
onRequestClose={closeModal}
contentLabel='Example Modal'
closeTimeoutMS={500}
>
<AddTodoListModal closeModal={closeModal} />
</Modal>
</div>
</div>
</div>
</div>
)
}
const TodoList = ({ todoList, activeCategory, getTodos }) => {
const router = useRouter()
const [modalIsOpen, setModalIsOpen] = useState(false)
const openModal = () => {
setModalIsOpen(true)
}
const closeModal = () => {
setModalIsOpen(false)
}
return (
<React.Fragment>
{!todoList.deleted && (
<div
className='cursor-pointer py-1 px-1 hover:bg-purple-800'
key={todoList.id}
>
<div className='flex justify-between'>
<span
onClick={() => {
getTodos({ variables: { id: todoList.id } })
activeSideBarVar(false)
activeCategoryVar(todoList.name)
router.push(`/todos/${todoList.id}`, undefined, {
shallow: true
})
}}
className={`${activeCategory === todoList.name && 'font-bold'}
cursor-pointer overflow-hidden whitespace-nowrap overflow-ellipsis text-md hover:text-white text-gray-200`}
>
# {todoList.name}
</span>
<div className='flex'>
<div
className='cursor-pointer mt-1 h-5 w-5 hover:text-white text-gray-300'
onClick={openModal}
>
<Plus />
</div>
<Modal
closeTimeoutMS={500}
className='bg-white outline-none inset-x-0 bottom-0 m-auto absolute w-full rounded-t-lg lg:w-2/5 border-2 px-2'
isOpen={modalIsOpen}
onRequestClose={closeModal}
contentLabel='Example Modal'
>
<AddTodoModal
closeModal={closeModal}
id={todoList.id}
name={todoList.name}
/>
</Modal>
<div className='px-2 text-md text-right hover:text-white text-gray-300'>
{todoList.activeTodosVolume}
</div>
<div>
<TodoListOptionsBox todoList={todoList} />
</div>
</div>
</div>
</div>
)}
</React.Fragment>
)
}
export default TodoLists