-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboard.js
313 lines (286 loc) · 6.42 KB
/
board.js
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
// Guidelines
// boardStore (no need for groupStore, taskStore), boardService
// *. Support saving the entire board and also on the task level,
// *. No need for saving an activities array per task,
// *. those activities are easily filtered from the board activities
// *. activites - when board is updated, the frontend does not send the activities
// array within the board
// instead it only sends a new activity object: {txt, boardId, groupId, taskId}
// the backend adds this activity to the board with $push and can also emit socket notificatios
// *. D & D Guidelines - vue-smooth-dnd / vuedraggable / react-beutiful-dnd
// *. Same model for Monday style app (do not implement a generic columns feature)
// *. We do not handle concurrent editing - needs versioning
// Rendering performance:
// Store Mutation - saveBoard
// As start - you can replace the entire board
// Later, support switching a specific task
// <BoardDetails> => <BoardGroup v-for / map>
// <BoardGroup> => <TaskPreview v-for / map>
// <TaskDetails> (supports edit)
// To facilitate working in a team, you can
// initially make this a seperate route
// (later on we can place it in a modal and nested route)
// Activities are board / group / task related
// The comment feature can be implemented with activity
const activity = {
id: makeId(),
txt: 'Changed Color',
createdAt: Date.now(),
byMember: userService.getLoggedinUser(),
group: group, // optional
task: task, // optional
}
// Store - saveTask
function storeSaveTask(boardId, groupId, task, activity) {
board = boardService.saveTask(boardId, groupId, task, activity)
// commit(ACTION) // dispatch(ACTION)
}
// boardService
function saveTask(boardId, groupId, task, activity) {
const board = getById(boardId)
// PUT /api/board/b123/task/t678
// TODO: find the task, and update
board.activities.unshift(activity)
saveBoard(board)
// return board
// return task
}
const board = {
_id: 'b101',
title: 'Robot dev proj',
isStarred: false,
archivedAt: 1589983468418,
createdBy: {
id: 'u101',
fullname: 'Abi Abambi',
imgUrl: 'http://some-img',
},
style: {
backgroundImage: 'https://cdn.pixabay.com/photo/2017/11/29/18/54/leaf-2986837_1280.jpg',
backgroundColor: '#61bd4f',
},
labels: [
{
id: 'l101',
title: 'Done',
color: '#61bd4f',
},
{
id: 'l102',
title: 'Progress',
color: '#61bd33',
},
],
members: [
{
id: 'u101',
fullname: 'Tal Taltal',
imgUrl: 'https://www.google.com',
},
{
id: 'u102',
fullname: 'Josh Ga',
imgUrl: 'https://www.google.com',
},
],
groups: [
{
id: 'g101',
title: 'Group 1',
archivedAt: 1589983468418,
tasks: [
{
id: 'c101',
title: 'Replace logo',
labels: [],
members: [],
attachments: [],
comments: [],
cover: '',
dueDate: '',
},
{
id: 'c102',
title: 'Add Samples',
},
],
style: {},
},
{
id: 'g102',
title: 'Group 2',
tasks: [
{
id: 'c103',
title: 'Do that',
archivedAt: 1589983468418,
},
{
id: 'c104',
title: 'Help me',
status: 'inProgress', // monday / both
priority: 'high', // monday / both
dueDate: '2024-09-24',
description: 'description',
comments: [
// in Trello this is easier implemented as an activity
{
id: 'ZdPnm',
title: 'also @yaronb please CR this',
createdAt: 1590999817436,
byMember: {
id: 'u101',
fullname: 'Tal Tarablus',
imgUrl: '',
},
},
],
checklists: [
{
id: 'YEhmF',
title: 'Checklist',
todos: [
{
id: '212jX',
title: 'To Do 1',
isDone: false,
},
],
},
],
memberIds: ['u101'],
labelIds: ['l101', 'l102'],
byMember: {
id: 'u101',
fullname: 'Tal Tarablus',
imgUrl: '',
},
style: {
backgroundColor: '#26de81',
},
},
],
style: {},
},
],
activities: [
{
id: 'a101',
title: 'Changed Color',
createdAt: 154514,
byMember: {
id: 'u101',
fullname: 'Abi Abambi',
imgUrl: 'http://some-img',
},
group: {
id: 'g101',
title: 'Urgent Stuff',
},
task: {
id: 'c101',
title: 'Replace Logo',
},
},
],
}
const user = {
_id: 'u101',
fullname: 'Abi Abambi',
username: '[email protected]',
password: 'aBambi123',
imgUrl: 'http://some-img.jpg',
mentions: [
{
//optional
id: 'm101',
boardId: 'm101',
taskId: 't101',
},
],
}
// <LabelPicker info={} onUpdate={} />
// <MemberPicker info={} onUpdate={} />
// <DatePicker info={} onUpdate={} />
// <DynamicPicker info={} onUpdate={} >
// For Monday Mostly:
// Dynamic Components:
function updateTask(cmpType, data) {
// Switch by cmpType
// case MEMBERS:
// task.members = data
// activity = boardService.getEmptyActivity()
// activity.txt = `Members changed for task ${}`
// activity.task = '{mini-task}'
// case STATUS:
// task.status = data
// dispatch to store: updateTask(task, activity)
}
const cmp1 = {
type: 'StatusPicker',
info: {
selectedStatus: 'pending',
statuses: [{}, {}],
},
}
const cmp2 = {
type: 'MemberPicker',
info: {
selectedMembers: ['m1', 'm2'],
members: ['m1', 'm2', 'm3'],
},
}
const cmp3 = {
type: 'DatePicker',
info: {
selectedDate: '2022-09-07',
},
}
// Code Ideas in React
export function TaskPreview({ task }) {
const cmpsOrder = ['StatusPicker', 'MemberPicker', 'DatePicker', 'PriorityPicker']
return (
<section>
<h5>{task.txt}</h5>
{cmpsOrder.map((cmp, idx) => {
return (
<DynamicCmp
cmp={cmp}
key={idx}
onUpdate={data => {
console.log('Updating: ', cmp, 'with data:', data)
// make a copy, update the task, create an action
// Call action: updateTask(task, action)
}}
/>
)
})}
</section>
)
}
// modal
export function DynamicCmp({ cmp, info, onUpdate }) {
switch (cmp) {
case 'StatusPicker':
return <StatusPicker info={info} onUpdate={onUpdate} />
case 'MemberPicker':
return <MemberPicker info={info} onUpdate={onUpdate} />
default:
return <p>UNKNOWN {cmp}</p>
}
}
// Vue.js Syntax:
// <TaskPreview> => <tr>
// <td v-for="(cmpType) in cmpsOrder">
// <Component :is="cmpType" :info="getCmpInfo(cmpType)" @updated="updateTask(cmpType, $event)">
// </td>
// </tr>
const UIIService = {
like: {
icon: 'far fa-heart',
color: 'red',
},
}
function getUi(key) {
return UIIService[key]
}