Formatting

main
Antonio De Lucreziis 2 years ago
parent 16233adcf1
commit 4a5994210e

@ -9,26 +9,25 @@ import { layoutIntervals } from '../../interval-layout.js'
export const WorkWeekGrid = ({ events, selection, setSelection, hideOtherCourses }) => {
const selectionSet = new Set(selection)
const colorList = [
'red',
'purple',
'blue',
'yellow',
'green',
'orange',
'lightblue',
];
const courses = _.uniqBy(!hideOtherCourses ? events : events.filter(e => selectionSet.has(e.id)), event => event.id);
const colors = Object.fromEntries(courses.map((course, index) => {
const colorList = ['red', 'purple', 'blue', 'yellow', 'green', 'orange', 'lightblue']
const courses = _.uniqBy(
!hideOtherCourses ? events : events.filter(e => selectionSet.has(e.id)),
event => event.id
)
const colors = Object.fromEntries(
courses.map((course, index) => {
return [
course.id,
[
colorList[index % colorList.length],
courses.length <= colorList.length ? '' : String.fromCharCode(65 + Math.floor(index / colorList.length))
courses.length <= colorList.length
? ''
: String.fromCharCode(65 + Math.floor(index / colorList.length)),
],
]
];
}));
})
)
const base = {
1: [],
@ -38,11 +37,11 @@ export const WorkWeekGrid = ({ events, selection, setSelection, hideOtherCourses
5: [],
}
const eventsByWeekday = {
... base,
... _.groupBy(
...base,
..._.groupBy(
!hideOtherCourses ? events : events.filter(e => selectionSet.has(e.id)),
event => event.start.getDay()
)
),
}
const dayIntervalLayout = _.mapValues(eventsByWeekday, events =>
@ -54,9 +53,11 @@ export const WorkWeekGrid = ({ events, selection, setSelection, hideOtherCourses
}))
)
)
const startsAndEnds = Object.entries(dayIntervalLayout).flatMap(([index, layout]) => layout.flatMap(events => events.map(event => [event.start, event.end])));
const minStart = Math.min(...startsAndEnds.map(([s, e]) => s)) / 60;
const maxEnd = Math.max(...startsAndEnds.map(([s, e]) => e)) / 60;
const startsAndEnds = Object.entries(dayIntervalLayout).flatMap(([index, layout]) =>
layout.flatMap(events => events.map(event => [event.start, event.end]))
)
const minStart = Math.min(...startsAndEnds.map(([s, e]) => s)) / 60
const maxEnd = Math.max(...startsAndEnds.map(([s, e]) => e)) / 60
// const timeStart = minStart < 9 ? 7 :
// minStart < 11 ? 9 :
// minStart < 13 ? 11 :
@ -71,19 +72,20 @@ export const WorkWeekGrid = ({ events, selection, setSelection, hideOtherCourses
// maxEnd > 11 ? 13 :
// maxEnd > 9 ? 11 :
// 9;
const timeStart = minStart < 9 ? 7 : 9;
const timeEnd = maxEnd > 18 ? 20 : 18;
const timeStart = minStart < 9 ? 7 : 9
const timeEnd = maxEnd > 18 ? 20 : 18
const daySizes = Object.entries(dayIntervalLayout).map(([index, layout]) => Math.max(1, layout.length));
const daySizes = Object.entries(dayIntervalLayout).map(([index, layout]) =>
Math.max(1, layout.length)
)
const dayOffsets = daySizes.map((v, i) => {
let sum = 0;
for(let j = 0; j < i; j++) {
sum += daySizes[j];
let sum = 0
for (let j = 0; j < i; j++) {
sum += daySizes[j]
}
return sum;
});
const daysLength = daySizes[4] + dayOffsets[4];
return sum
})
const daysLength = daySizes[4] + dayOffsets[4]
const [currentlyHovered, setCurrentlyHovered] = useState(null)
const element = useRef()
@ -111,41 +113,57 @@ export const WorkWeekGrid = ({ events, selection, setSelection, hideOtherCourses
return (
<div class="work-week-grid-view" ref={element}>
<div class="grid" style={{'--days-length': daysLength, '--time-length': timeEnd - timeStart}}>
{[7, 9, 11, 14, 16, 18].map(n =>
<div
class="grid"
style={{ '--days-length': daysLength, '--time-length': timeEnd - timeStart }}
>
{[7, 9, 11, 14, 16, 18].map(n => (
<>
{n + 2 > timeStart && n < timeEnd && (
<div class="time" style={{'--offset': n - timeStart + 2}}>{n}-{n+2}</div>
<div class="time" style={{ '--offset': n - timeStart + 2 }}>
{n}-{n + 2}
</div>
)}
</>
)}
))}
<div class="vline" style="--offset: 2"></div>
{[9, 11, 13, 14, 16, 18].map(n =>
{[9, 11, 13, 14, 16, 18].map(n => (
<>
{n > timeStart && n < timeEnd && (
<div class="vline" style={{'--offset': n - timeStart + 2}}></div>
<div class="vline" style={{ '--offset': n - timeStart + 2 }}></div>
)}
</>
)}
))}
<div class="day-name" style={{'--line': 2 + dayOffsets[0]}}>Lun</div>
<div class="day-name" style={{'--line': 2 + dayOffsets[1]}}>Mar</div>
<div class="day-name" style={{'--line': 2 + dayOffsets[2]}}>Mer</div>
<div class="day-name" style={{'--line': 2 + dayOffsets[3]}}>Gio</div>
<div class="day-name" style={{'--line': 2 + dayOffsets[4]}}>Ven</div>
<div class="day-name" style={{ '--line': 2 + dayOffsets[0] }}>
Lun
</div>
<div class="day-name" style={{ '--line': 2 + dayOffsets[1] }}>
Mar
</div>
<div class="day-name" style={{ '--line': 2 + dayOffsets[2] }}>
Mer
</div>
<div class="day-name" style={{ '--line': 2 + dayOffsets[3] }}>
Gio
</div>
<div class="day-name" style={{ '--line': 2 + dayOffsets[4] }}>
Ven
</div>
<div class="hline" style={{'--line': 2 + dayOffsets[0]}}></div>
<div class="hline" style={{'--line': 2 + dayOffsets[1]}}></div>
<div class="hline" style={{'--line': 2 + dayOffsets[2]}}></div>
<div class="hline" style={{'--line': 2 + dayOffsets[3]}}></div>
<div class="hline" style={{'--line': 2 + dayOffsets[4]}}></div>
<div class="hline" style={{ '--line': 2 + dayOffsets[0] }}></div>
<div class="hline" style={{ '--line': 2 + dayOffsets[1] }}></div>
<div class="hline" style={{ '--line': 2 + dayOffsets[2] }}></div>
<div class="hline" style={{ '--line': 2 + dayOffsets[3] }}></div>
<div class="hline" style={{ '--line': 2 + dayOffsets[4] }}></div>
{Object.entries(dayIntervalLayout).map(([index, layout]) => (
<>
{layout.map((events, stackIndex) => (
<>
{events.map(event => (
<div class={
<div
class={
'event' +
(currentlyHovered === event.data.id
? ' highlight'
@ -154,12 +172,16 @@ export const WorkWeekGrid = ({ events, selection, setSelection, hideOtherCourses
}
data-event-id={event.data.id}
style={{
'--line': 2 + dayOffsets[index-1] + stackIndex,
'--line': 2 + dayOffsets[index - 1] + stackIndex,
'--offset': event.start / 60 - timeStart + 2,
'--length': (event.end - event.start) / 60,
'--color': `var(--bubble-${colors[event.data.id][0]})`,
'--border-color': `var(--bubble-border-${colors[event.data.id][0]})`,
'--highlight-color': `var(--bubble-highlight-${colors[event.data.id][0]})`
'--border-color': `var(--bubble-border-${
colors[event.data.id][0]
})`,
'--highlight-color': `var(--bubble-highlight-${
colors[event.data.id][0]
})`,
}}
onClick={() => {
if (!selectionSet.has(event.data.id))
@ -171,9 +193,12 @@ export const WorkWeekGrid = ({ events, selection, setSelection, hideOtherCourses
}}
>
{colors[event.data.id][1] !== '' && (
<div className="distinguisher">{`(${colors[event.data.id][1]})`}</div>
<div className="distinguisher">{`(${
colors[event.data.id][1]
})`}</div>
)}
{event.data.aula}</div>
{event.data.aula}
</div>
))}
</>
))}
@ -183,10 +208,11 @@ export const WorkWeekGrid = ({ events, selection, setSelection, hideOtherCourses
<div class="legend">
{courses.map(course => (
<>
<div class="color"
<div
class="color"
style={{
'--color': `var(--bubble-${colors[course.id][0]})`,
'--border-color': `var(--bubble-border-${colors[course.id][0]})`
'--border-color': `var(--bubble-border-${colors[course.id][0]})`,
}}
>
{colors[course.id][1]}

Loading…
Cancel
Save