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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
|
import * as React from 'react';
import { observer } from 'mobx-react';
import { observable, action, runInAction } from 'mobx';
import "./SearchBox.scss";
import "./IconBar.scss";
import * as anime from 'animejs';
import { DocTypes } from '../../documents/Documents';
import { faSearch, faFilePdf, faFilm, faImage, faObjectGroup, faStickyNote, faMusic, faLink, faChartBar, faGlobeAsia, faBan } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { library, icon } from '@fortawesome/fontawesome-svg-core';
import * as _ from "lodash";
import $ from 'jquery';
library.add(faSearch);
library.add(faObjectGroup);
library.add(faImage);
library.add(faStickyNote);
library.add(faFilePdf);
library.add(faFilm);
library.add(faMusic);
library.add(faLink);
library.add(faChartBar);
library.add(faGlobeAsia);
library.add(faBan);
export interface IconBarProps {
updateIcon(icons: string[]): void;
// getSelectedTypes(): string[];
// getRemovedTypes(): string[];
getIcons(): string[]
allIcons: string[];
updateSelected(list: any[]): void;
}
@observer
export class IconBar extends React.Component<IconBarProps> {
static Instance: IconBar;
@observable noneRef = React.createRef<HTMLDivElement>();
@observable colRef = React.createRef<HTMLDivElement>();
@observable imgRef = React.createRef<HTMLDivElement>();
@observable textRef = React.createRef<HTMLDivElement>();
@observable pdfRef = React.createRef<HTMLDivElement>();
@observable vidRef = React.createRef<HTMLDivElement>();
@observable audioRef = React.createRef<HTMLDivElement>();
@observable linkRef = React.createRef<HTMLDivElement>();
@observable histRef = React.createRef<HTMLDivElement>();
@observable webRef = React.createRef<HTMLDivElement>();
@observable allRefs: React.RefObject<HTMLDivElement>[] = [this.colRef, this.imgRef, this.textRef, this.pdfRef, this.vidRef, this.audioRef, this.linkRef, this.histRef, this.webRef];
@observable originalSelected: string[];
// @observable originalSelectedNodes: string[] = this.props.getSelectedTypes();
// @observable originalRemovedNodes: string[] = this.props.getSelectedTypes();
@observable removeType: boolean = false;
@observable added: any[];
@observable removed: any[];
@observable selected: any[];
constructor(props: IconBarProps) {
super(props);
IconBar.Instance = this;
this.added = [];
this.removed = [];
this.selected = [];
this.originalSelected = this.props.getIcons();
// console.log("ICONS")
// console.log(this.props.getIcons())
console.log(this.originalSelected)
}
@action
downKeyHandler = (e: KeyboardEvent) => {
if (e.key !== "Control") return;
this.removeType = true;
e.preventDefault();
e.stopPropagation();
document.body.style.cursor = "not-allowed";
}
@action
upKeyHandler = (e: KeyboardEvent) => {
e.preventDefault();
e.stopPropagation();
this.removeType = false;
document.body.style.cursor = "default";
}
componentWillMount() {
document.removeEventListener("keydown", this.downKeyHandler);
document.addEventListener("keydown", this.downKeyHandler);
document.removeEventListener("keyup", this.upKeyHandler);
document.addEventListener("keyup", this.upKeyHandler);
}
componentWillUnMount() {
document.removeEventListener("keyup", this.upKeyHandler);
document.removeEventListener("keydown", this.downKeyHandler);
}
componentDidMount = () => {
//i KNOW this is bad i just can't get this to re render eeeeeeeek
this.forceUpdate();
}
@action.bound
resetIconFilters = () => {
this.unselectAllRefs();
// lmao sorry
this.forceUpdate();
}
//gets ref associated with given string
@action.bound
getRef = (value: string) => {
let toReturn;
switch (value) {
case (DocTypes.NONE):
toReturn = this.noneRef.current;
break;
case (DocTypes.AUDIO):
toReturn = this.audioRef.current;
break;
case (DocTypes.COL):
toReturn = this.colRef.current;
break;
case (DocTypes.HIST):
toReturn = this.histRef.current;
break;
case (DocTypes.IMG):
toReturn = this.imgRef.current;
break;
case (DocTypes.LINK):
toReturn = this.linkRef.current;
break;
case (DocTypes.PDF):
toReturn = this.pdfRef.current;
break;
case (DocTypes.TEXT):
toReturn = this.textRef.current;
break;
case (DocTypes.VID):
toReturn = this.vidRef.current;
break;
case (DocTypes.WEB):
toReturn = this.webRef.current;
break;
default:
toReturn = null;
break;
}
return toReturn;
}
@action.bound
unselectAllRefs() {
this.resetDataRemoved();
this.resetDataSelected();
this.removed = [];
this.added = [];
}
@action.bound
resetDataSelected() {
this.allRefs.forEach(element => {
if (element.current) {
element.current.setAttribute("data-selected", "false");
}
});
}
@action.bound
resetDataRemoved() {
this.allRefs.forEach(element => {
if (element.current) {
element.current.setAttribute("data-removed", "false");
}
});
}
@action.bound
alternateSelectedRef(ref: HTMLDivElement | React.RefObject<HTMLDivElement>) {
let newRef: HTMLDivElement | null;
if (!(ref instanceof HTMLDivElement)) { newRef = ref.current; }
else { newRef = ref; }
if (newRef) {
if (newRef.getAttribute("data-selected") === "true") {
newRef.setAttribute("data-selected", "false");
}
else {
newRef.setAttribute("data-selected", "true");
}
}
}
@action.bound
setToRemove(ref: HTMLDivElement | React.RefObject<HTMLDivElement>) {
let newRef: HTMLDivElement | null;
if (!(ref instanceof HTMLDivElement)) { newRef = ref.current; }
else { newRef = ref; }
if (newRef) newRef.setAttribute("data-removed", "true");
}
@action.bound
setToAdd(ref: HTMLDivElement | React.RefObject<HTMLDivElement>) {
let newRef: HTMLDivElement | null;
if (!(ref instanceof HTMLDivElement)) { newRef = ref.current; }
else { newRef = ref; }
if (newRef) newRef.setAttribute("data-removed", "false");
}
//TODO: this needs help
@action.bound
onClick = (value: string) => {
let icons: string[] = this.props.getIcons();
let ref: any = this.getRef(value);
// if(ref) this.alternateSelectedRef(ref);
if (value === DocTypes.NONE) {
icons = this.props.allIcons;
// if its none, change the color of all the other circles
this.resetIconFilters();
}
//if type should be removed
if (this.removeType) {
if (this.added.length !== 0) {
icons = this.props.allIcons;
this.resetIconFilters();
this.added = [];
icons = _.without(icons, value);
this.removed.push(ref);
this.setToRemove(ref)
ref.setAttribute("data-selected", "true")
}
else {
//if it's included in the list, remove it
if (icons.includes(value)) {
icons = _.without(icons, value);
this.removed.push(ref);
this.setToRemove(ref);
ref.setAttribute("data-selected", "true")
}
//if it's not included, add it back
else {
icons.push(value);
//take it out of removed list
this.removed = _.without(this.removed, this.getRef(value));
ref.setAttribute("data-selected", "false")
}
}
this.selected = this.removed;
}
//if type should be added
else {
if (this.removed.length !== 0) {
icons = this.props.allIcons;
this.resetIconFilters();
this.removed = [];
icons = [value];
this.added.push(ref);
this.setToAdd(ref)
ref.setAttribute("data-selected", "true")
}
else {
//if its included in the list, remove it
if (icons.includes(value)) {
icons = _.without(icons, value);
this.added = _.without(this.added, this.getRef(value))
ref.setAttribute("data-selected", "false")
}
//if its not included in the list, add it
else {
icons.push(value);
this.added.push(ref)
this.setToAdd(ref)
ref.setAttribute("data-selected", "true")
}
}
this.selected = this.added;
}
this.props.updateIcon(icons);
this.props.updateSelected(this.selected);
//ok i know that this is bad but i dont know how else to get it to rerender and change the classname,
//any help here is greatly appreciated thanks frens
this.forceUpdate();
}
//checks if option is selected based on the attribute data-selected
//this is for visual purposes
@action.bound
isRefSelected = (ref: HTMLDivElement | React.RefObject<HTMLDivElement>) => {
let newRef: HTMLDivElement | null;
if (!(ref instanceof HTMLDivElement)) { newRef = ref.current; }
else { newRef = ref; }
if (newRef) {
if (newRef.getAttribute("data-selected") === "true") {
return true;
}
return false;
}
}
//checks attribues of ref to return whether or not a type should be specifically included in the search
@action.bound
getInitialSelectedStatus = (type: string) => {
console.log(this.originalSelected)
if (this.originalSelected.includes(type)) {
return "true";
}
return "false";
}
//checks attributes of ref to return whether or not it should be excluded from search results
//this is for visual purposes
@action.bound
isRemoved = (ref: HTMLDivElement | React.RefObject<HTMLDivElement>) => {
let newRef: HTMLDivElement | null;
if (!(ref instanceof HTMLDivElement)) { newRef = ref.current; }
else { newRef = ref; }
if (newRef) {
if (newRef.getAttribute("data-removed") === "true") {
return true;
}
return false;
}
}
//gets status upon mounting if a doc type should be removed from the results
@action.bound
getInitialRemovedStatus = (type: string) => {
if (!this.originalSelected.includes(type)) {
return "true";
}
return "false";
}
render() {
return (
<div>
<div className="filter icon-title">Filter by type of node</div>
<div className="filter icon-bar">
<div className="filter type-outer">
<div className={"type-icon none not-selected"}
ref={this.noneRef}
data-selected={"false"}
data-removed={"false"}
onClick={() => { this.onClick(DocTypes.NONE); }}>
<FontAwesomeIcon className="fontawesome-icon" style={{ order: -2 }} icon={faBan} />
</div>
<div className="filter-description">Clear</div>
</div>
<div className="type-outer">
<div className={"type-icon filter " + (this.isRefSelected(this.pdfRef) ? "selected " + (this.isRemoved(this.pdfRef) ? "removed" : "add") : "not-selected")}
ref={this.pdfRef}
data-selected={this.getInitialSelectedStatus(DocTypes.PDF)}
data-removed={this.getInitialRemovedStatus(DocTypes.PDF)}
onClick={() => { this.onClick(DocTypes.PDF); }}>
<FontAwesomeIcon className="fontawesome-icon filter" style={{ order: 0 }} icon={faFilePdf} />
</div>
<div className="filter-description">{DocTypes.PDF}</div>
</div>
<div className="type-outer">
<div className={"type-icon filter " + (this.isRefSelected(this.histRef) ? "selected " + (this.isRemoved(this.histRef) ? "removed" : "add") : "not-selected")}
ref={this.histRef}
data-selected={this.getInitialSelectedStatus(DocTypes.HIST)}
data-removed={this.getInitialRemovedStatus(DocTypes.HIST)}
onClick={() => { this.onClick(DocTypes.HIST); }}>
<FontAwesomeIcon className="fontawesome-icon filter" style={{ order: 1 }} icon={faChartBar} />
</div>
<div className="filter-description">{DocTypes.HIST}</div>
</div>
<div className="type-outer">
<div className={"type-icon filter " + (this.isRefSelected(this.colRef) ? "selected " + (this.isRemoved(this.colRef) ? "removed" : "add") : "not-selected")}
ref={this.colRef}
data-selected={this.getInitialSelectedStatus(DocTypes.COL)}
data-removed={this.getInitialRemovedStatus(DocTypes.COL)}
onClick={() => { this.onClick(DocTypes.COL); }}>
<FontAwesomeIcon className="fontawesome-icon filter" style={{ order: 2 }} icon={faObjectGroup} />
</div>
<div className="filter-description">{DocTypes.COL}</div>
</div>
<div className="type-outer">
<div className={"type-icon filter " + (this.isRefSelected(this.imgRef) ? "selected " + (this.isRemoved(this.imgRef) ? "removed" : "add") : "not-selected")}
ref={this.imgRef}
data-selected={this.getInitialSelectedStatus(DocTypes.IMG)}
data-removed={this.getInitialRemovedStatus(DocTypes.IMG)}
onClick={() => { this.onClick(DocTypes.IMG); }}>
<FontAwesomeIcon className="fontawesome-icon filter" style={{ order: 3 }} icon={faImage} />
</div>
<div className="filter-description">{DocTypes.IMG}</div>
</div>
<div className="type-outer">
<div className={"type-icon filter " + (this.isRefSelected(this.vidRef) ? "selected " + (this.isRemoved(this.vidRef) ? "removed" : "add") : "not-selected")}
ref={this.vidRef}
data-selected={this.getInitialSelectedStatus(DocTypes.VID)}
data-removed={this.getInitialRemovedStatus(DocTypes.VID)}
onClick={() => { this.onClick(DocTypes.VID); }}>
<FontAwesomeIcon className="fontawesome-icon filter" style={{ order: 4 }} icon={faFilm} />
</div>
<div className="filter-description">{DocTypes.VID}</div>
</div>
<div className="type-outer">
<div className={"type-icon filter " + (this.isRefSelected(this.webRef) ? "selected " + (this.isRemoved(this.webRef) ? "removed" : "add") : "not-selected")}
ref={this.webRef}
data-selected={this.getInitialSelectedStatus(DocTypes.WEB)}
data-removed={this.getInitialRemovedStatus(DocTypes.WEB)}
onClick={() => { this.onClick(DocTypes.WEB); }}>
<FontAwesomeIcon className="fontawesome-icon filter" style={{ order: 5 }} icon={faGlobeAsia} />
</div>
<div className="filter-description">{DocTypes.WEB}</div>
</div>
<div className="type-outer">
<div className={"type-icon filter " + (this.isRefSelected(this.linkRef) ? "selected " + (this.isRemoved(this.linkRef) ? "removed" : "add") : "not-selected")}
ref={this.linkRef}
data-selected={this.getInitialSelectedStatus(DocTypes.LINK)}
data-removed={this.getInitialRemovedStatus(DocTypes.LINK)}
onClick={() => { this.onClick(DocTypes.LINK); }}>
<FontAwesomeIcon className="fontawesome-icon filter" style={{ order: 6 }} icon={faLink} />
</div>
<div className="filter-description">{DocTypes.LINK}</div>
</div>
<div className="type-outer">
<div className={"type-icon filter " + (this.isRefSelected(this.audioRef) ? "selected " + (this.isRemoved(this.audioRef) ? "removed" : "add") : "not-selected")}
ref={this.audioRef}
data-selected={this.getInitialSelectedStatus(DocTypes.AUDIO)}
data-removed={this.getInitialRemovedStatus(DocTypes.AUDIO)}
onClick={() => { this.onClick(DocTypes.AUDIO); }}>
<FontAwesomeIcon className="fontawesome-icon filter" style={{ order: 7 }} icon={faMusic} />
</div>
<div className="filter-description">{DocTypes.AUDIO}</div>
</div>
<div className="type-outer">
<div className={"type-icon filter " + (this.isRefSelected(this.textRef) ? "selected " + (this.isRemoved(this.textRef) ? "removed" : "add") : "not-selected")}
ref={this.textRef}
data-selected={this.getInitialSelectedStatus(DocTypes.TEXT)}
data-removed={this.getInitialRemovedStatus(DocTypes.TEXT)}
onClick={() => { this.onClick(DocTypes.TEXT); }}>
<FontAwesomeIcon className="fontawesome-icon filter" style={{ order: 8 }} icon={faStickyNote} />
</div>
<div className="filter-description">{DocTypes.TEXT}</div>
</div>
</div>
</div>
);
}
}
|