Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Alsijil
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-Alsijil
Commits
1985c722
Commit
1985c722
authored
11 months ago
by
permcu
Browse files
Options
Downloads
Patches
Plain Diff
Improve intersect handler
The state is now in the handler
parent
1058b324
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!355
Implement infinite scrolling and by date navigation for coursebook
,
!350
Resolve "Add simple course book list"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue
+35
-41
35 additions, 41 deletions
...pps/alsijil/frontend/components/coursebook/Coursebook.vue
with
35 additions
and
41 deletions
aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue
+
35
−
41
View file @
1985c722
...
...
@@ -17,16 +17,13 @@
</
template
>
<
template
#default=
"{ items }"
>
<v-list-item
v-for=
"
{ date, docs,
first
, last } in groupDocsByDay(items)"
v-for=
"
{ date, docs,
idx
, last
Idx
} in groupDocsByDay(items)"
v-intersect="{
handler:
onI
ntersect,
handler:
i
ntersect
Handler(date, idx, lastIdx)
,
options: {
threshold: [0, 1]
}
threshold: [0, 1]
,
}
,
}"
:data-date="date.toISODate()"
:data-first="first"
:data-last="last"
two-line
:key="'day-' + date"
:id="'documentation_' + date.toISODate()"
...
...
@@ -191,27 +188,24 @@ export default {
this
.
dateEnd
=
date
.
plus
({
days
:
4
}
).
toISODate
();
}
,
groupDocsByDay
(
docs
)
{
// =>
{
dt
:
[
dt
doc
...
]
...
}
// =>
{
dt
:
{
date
:
dt
,
docs
:
doc
...
}
...
}
const
docsByDay
=
docs
.
reduce
((
byDay
,
doc
)
=>
{
// This works with dummy. Does actual doc have dateStart instead?
const
day
=
DateTime
.
fromISO
(
doc
.
datetimeStart
).
startOf
(
"
day
"
);
byDay
[
day
]
??=
{
date
:
day
,
docs
:
[]
,
first
:
false
,
last
:
false
}
;
byDay
[
day
]
[
'
docs
'
]
.
push
(
doc
);
byDay
[
day
]
??=
{
date
:
day
,
docs
:
[]
}
;
byDay
[
day
]
.
docs
.
push
(
doc
);
return
byDay
;
}
,
{
}
);
// => [[dt doc ...] ...]
// => [
{
date
:
dt
,
docs
:
doc
...,
idx
:
idx
,
lastIdx
:
last
-
idx
}
...]
// sorting is necessary since backend can send docs unordered
return
Object
.
keys
(
docsByDay
)
.
sort
()
.
map
((
key
,
i
,
{
length
}
)
=>
{
.
map
((
key
,
i
dx
,
{
length
}
)
=>
{
const
day
=
docsByDay
[
key
];
if
(
i
===
0
)
{
day
[
'
first
'
]
=
true
;
}
else
if
(
i
===
length
-
1
)
{
day
[
'
last
'
]
=
true
;
}
day
.
idx
=
idx
;
day
.
lastIdx
=
length
-
1
;
return
day
;
}
);
// sorting is necessary since backend can send docs unordered
}
,
// docsByDay:
{
dt
:
[
dt
doc
...]
...
}
fetchMore
(
from
,
to
)
{
...
...
@@ -232,31 +226,31 @@ export default {
setDate
(
date
)
{
this
.
$router
.
replace
({
hash
:
date
}
)
}
,
onIntersect
(
entries
,
observer
)
{
const
entry
=
entries
[
0
];
if
(
entry
.
isIntersecting
)
{
intersectHandler
(
date
,
idx
,
lastIdx
)
{
let
waiting
=
true
;
return
(
entries
)
=>
{
const
entry
=
entries
[
0
];
if
(
entry
.
isIntersecting
)
{
if
(
entry
.
boundingClientRect
.
top
<=
0
)
{
console
.
log
(
'
@
'
,
entry
.
target
.
dataset
.
d
ate
);
this
.
setDate
(
entry
.
target
.
dataset
.
d
ate
);
}
if
(
entry
.
boundingClientRect
.
top
<=
0
)
{
console
.
log
(
'
@
'
,
date
.
toISOD
ate
()
);
this
.
setDate
(
date
.
toISOD
ate
()
);
}
// load more
if
(
entry
.
target
.
dataset
.
first
)
{
console
.
log
(
'
load up
'
);
entry
.
target
.
dataset
.
first
=
false
;
const
date
=
DateTime
.
fromISO
(
entry
.
target
.
dataset
.
date
);
this
.
fetchMore
(
date
.
minus
({
days
:
4
}
).
toISODate
(),
date
.
minus
({
days
:
1
}
).
toISODate
());
}
else
if
(
entry
.
target
.
dataset
.
last
)
{
console
.
log
(
'
load down
'
);
entry
.
target
.
dataset
.
last
=
false
;
const
date
=
DateTime
.
fromISO
(
entry
.
target
.
dataset
.
date
);
this
.
fetchMore
(
date
.
plus
({
days
:
1
}
).
toISODate
(),
date
.
plus
({
days
:
5
}
).
toISODate
());
}
}
}
,
if
(
waiting
&&
idx
===
0
)
{
console
.
log
(
'
load up
'
,
date
.
toISODate
());
this
.
fetchMore
(
date
.
minus
({
days
:
4
}
).
toISODate
(),
date
.
minus
({
days
:
1
}
).
toISODate
());
waiting
=
false
;
}
else
if
(
waiting
&&
idx
===
lastIdx
)
{
console
.
log
(
'
load down
'
,
date
.
toISODate
());
this
.
fetchMore
(
date
.
plus
({
days
:
1
}
).
toISODate
(),
date
.
plus
({
days
:
5
}
).
toISODate
());
waiting
=
false
;
}
}
}
;
}
,
}
,
created
()
{
this
.
resetDate
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment