blob: cbcc980a97bde77a5b466243344e3f57e024edd7 (
plain)
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
|
import { computed, makeObservable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { dateRangeStrToDates, emptyFunction, returnTrue } from '../../../Utils';
import { Doc, DocListCast } from '../../../fields/Doc';
import { StrCast } from '../../../fields/Types';
import { CollectionStackingView } from './CollectionStackingView';
import { CollectionSubView } from './CollectionSubView';
@observer
export class CollectionCalendarView extends CollectionSubView() {
constructor(props: any) {
super(props);
makeObservable(this);
}
componentDidMount(): void {}
componentWillUnmount(): void {}
@computed get allCalendars() {
return this.childDocs; // returns a list of docs (i.e. calendars)
}
removeCalendar = () => {};
addCalendar = (doc: Doc | Doc[], annotationKey?: string | undefined): boolean => {
// bring up calendar modal with option to create a calendar
return true;
};
_stackRef = React.createRef<CollectionStackingView>();
panelHeight = () => {
return this._props.PanelHeight() - 40; // this should be the height of the stacking view. For now, it's the hieight of the calendar view minus 40 to allow for a title
};
// most recent calendar should come first
sortByMostRecentDate = (calendarA: Doc, calendarB: Doc) => {
const aDateRangeStr = StrCast(DocListCast(calendarA.data).lastElement()?.date_range);
const bDateRangeStr = StrCast(DocListCast(calendarB.data).lastElement()?.date_range);
const [aFromDate, aToDate] = dateRangeStrToDates(aDateRangeStr);
const [bFromDate, bToDate] = dateRangeStrToDates(bDateRangeStr);
if (aFromDate > bFromDate) {
return -1; // a comes first
} else if (aFromDate < bFromDate) {
return 1; // b comes first
} else {
// start dates are the same
if (aToDate > bToDate) {
return -1; // a comes first
} else if (aToDate < bToDate) {
return 1; // b comes first
} else {
return 0; // same start and end dates
}
}
};
screenToLocalTransform = () =>
this._props
.ScreenToLocalTransform()
.translate(Doc.NativeWidth(this.Document), 0)
.scale(this._props.NativeDimScaling?.() || 1);
get calendarsKey() {
return this._props.fieldKey;
}
render() {
return (
<div className="collectionCalendarView">
<CollectionStackingView
{...this._props}
setContentViewBox={emptyFunction}
ref={this._stackRef}
PanelHeight={this.panelHeight}
PanelWidth={this._props.PanelWidth}
// childFilters={this.childFilters} DO I NEED THIS?
sortFunc={this.sortByMostRecentDate}
setHeight={undefined}
isAnnotationOverlay={false}
// select={emptyFunction} What does this mean?
isAnyChildContentActive={returnTrue} // ??
// childDocumentsActive={}
// whenChildContentsActiveChanged={}
childHideDecorationTitle={false}
removeDocument={this.removeDocument} // will calendar automatically be removed from myCalendars
moveDocument={this.moveDocument}
addDocument={this.addCalendar}
ScreenToLocalTransform={this.screenToLocalTransform}
renderDepth={this._props.renderDepth + 1}
fieldKey={this.calendarsKey}
/>
</div>
);
}
}
|