Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beta.ordbok.uib.no
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Språksamlingane
beta.ordbok.uib.no
Commits
1ac1cd87
Commit
1ac1cd87
authored
3 years ago
by
Henrik Askjer
Browse files
Options
Downloads
Patches
Plain Diff
implement lazy loading when scrolling
parent
2f285daa
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/DictionaryView.vue
+51
-14
51 additions, 14 deletions
src/components/DictionaryView.vue
with
51 additions
and
14 deletions
src/components/DictionaryView.vue
+
51
−
14
View file @
1ac1cd87
...
@@ -33,9 +33,6 @@
...
@@ -33,9 +33,6 @@
<Autocomplete
v-on:submit=
"select_result"
:api=
"get_search_endpoint"
>
<Autocomplete
v-on:submit=
"select_result"
:api=
"get_search_endpoint"
>
</Autocomplete>
</Autocomplete>
</div>
</div>
<div
id=
"spinner"
v-if=
"waiting"
>
<v-progress-circular
indeterminate
color=
"secondary"
size=
"120"
></v-progress-circular>
</div>
<SearchResults
:results_bm=
"search_results.bm"
<SearchResults
:results_bm=
"search_results.bm"
:results_nn=
"search_results.nn"
:results_nn=
"search_results.nn"
:lang=
"lang"
:lang=
"lang"
...
@@ -43,7 +40,10 @@
...
@@ -43,7 +40,10 @@
:meta=
"this.article_info.meta"
:meta=
"this.article_info.meta"
@
article-click=
"article_link_click"
@
article-click=
"article_link_click"
@
details-click=
"details_click"
@
details-click=
"details_click"
v-if=
"total_results() && ! waiting && ! article"
/>
v-if=
"total_results() && ! article"
/>
<div
id=
"spinner"
v-if=
"waiting"
>
<v-progress-circular
indeterminate
color=
"secondary"
size=
"120"
></v-progress-circular>
</div>
<div
id=
"single_article_container"
v-if=
"article"
>
<div
id=
"single_article_container"
v-if=
"article"
>
<div
class=
"return_to_results"
v-if=
"total_results"
>
<div
class=
"return_to_results"
v-if=
"total_results"
>
<router-link
:to=
"article.source"
@
click.native=
"return_to_results()"
>
<router-link
:to=
"article.source"
@
click.native=
"return_to_results()"
>
...
@@ -165,9 +165,12 @@ function load_articles(self, query, offset, n, dict) {
...
@@ -165,9 +165,12 @@ function load_articles(self, query, offset, n, dict) {
else
if
(
offset
+
n
>
article_IDs
.
length
)
{
else
if
(
offset
+
n
>
article_IDs
.
length
)
{
n
=
n
+
(
article_IDs
.
length
-
n
)
n
=
n
+
(
article_IDs
.
length
-
n
)
}
}
console
.
log
(
"
n, offset
"
,
n
,
offset
)
if
(
n
>
0
)
{
if
(
n
>
0
&&
(
self
.
lang
==
dict
||
self
.
lang
==
"
bm,nn
"
))
{
article_IDs
=
article_IDs
.
slice
(
offset
,
n
)
article_IDs
=
article_IDs
.
slice
(
offset
,
offset
+
n
)
console
.
log
(
"
ARTICLES
"
,
dict
,
article_IDs
)
console
.
log
(
"
OFFSET offset+N
"
,
offset
,
offset
+
n
)
return
Promise
.
all
(
article_IDs
.
map
((
article_id
)
=>
{
return
Promise
.
all
(
article_IDs
.
map
((
article_id
)
=>
{
return
axios
.
get
(
`
${
ARTICLE_ENDPOINT
}${
dict
}
/article/
${
article_id
}
.json`
)
return
axios
.
get
(
`
${
ARTICLE_ENDPOINT
}${
dict
}
/article/
${
article_id
}
.json`
)
...
@@ -179,7 +182,7 @@ function load_articles(self, query, offset, n, dict) {
...
@@ -179,7 +182,7 @@ function load_articles(self, query, offset, n, dict) {
})
})
})
})
self
.
article
=
null
self
.
article
=
null
if
(
!
results
.
length
)
{
if
(
!
results
.
length
&&
offset
==
0
)
{
if
(
query
.
match
)
{
if
(
query
.
match
)
{
self
.
error
=
[]
self
.
error
=
[]
if
(
self
.
lang
!==
'
bm
'
)
{
if
(
self
.
lang
!==
'
bm
'
)
{
...
@@ -200,10 +203,13 @@ function load_articles(self, query, offset, n, dict) {
...
@@ -200,10 +203,13 @@ function load_articles(self, query, offset, n, dict) {
self
.
error
=
null
self
.
error
=
null
}
}
if
(
offset
==
0
)
{
if
(
offset
==
0
)
{
console
.
log
(
"
REPLACING
"
)
self
.
search_results
[
dict
]
=
results
self
.
search_results
[
dict
]
=
results
}
}
else
{
else
{
self
.
search_results
[
dict
]
=
self
.
search_results
[
dict
].
concat
(
results
)
console
.
log
(
"
APPENDING
"
)
self
.
search_results
[
dict
]
=
self
.
search_results
[
dict
].
concat
(
results
)
console
.
log
(
self
.
search_results
)
}
}
})
})
.
catch
(
error
=>
{
.
catch
(
error
=>
{
...
@@ -211,21 +217,27 @@ function load_articles(self, query, offset, n, dict) {
...
@@ -211,21 +217,27 @@ function load_articles(self, query, offset, n, dict) {
self
.
connection_error
(
error
)
self
.
connection_error
(
error
)
})
})
}
}
else
{
return
Promise
.
resolve
()
}
}
}
function
navigate_to_query
(
self
,
word
)
{
function
navigate_to_query
(
self
,
word
)
{
self
.
waiting_for_articles
=
true
self
.
waiting_for_articles
=
true
let
query
=
self
.
event
?
self
.
event
:
{
q
:
word
}
let
query
=
self
.
event
?
self
.
event
:
{
q
:
word
}
self
.
query
=
query
// Get article IDs
// Get article IDs
api
.
get
(
'
articles?
'
,
{
params
:
{
w
:
query
.
match
||
query
.
q
,
dict
:
self
.
lang
,
scope
:
"
w
"
}}).
then
((
response
)
=>
{
api
.
get
(
'
articles?
'
,
{
params
:
{
w
:
query
.
match
||
query
.
q
,
dict
:
self
.
lang
,
scope
:
"
w
"
}}).
then
((
response
)
=>
{
self
.
article_info
=
response
.
data
self
.
article_info
=
response
.
data
self
.
search_results
=
{}
self
.
search_results
=
{}
let
article_queries
=
[]
Promise
.
all
([
if
(
self
.
lang
==
"
bm
"
||
self
.
lang
==
"
bm,nn
"
)
article_queries
.
push
(
load_articles
(
self
,
query
,
0
,
10
,
"
bm
"
)
)
load_articles
(
self
,
query
,
0
,
10
,
"
bm
"
)
,
if
(
self
.
lang
==
"
nn
"
||
self
.
lang
==
"
bm,nn
"
)
article_queries
.
push
(
load_articles
(
self
,
query
,
0
,
10
,
"
nn
"
)
)
load_articles
(
self
,
query
,
0
,
10
,
"
nn
"
)
Promise
.
all
(
article_queries
)
]
)
.
then
(()
=>
{
.
then
(()
=>
{
self
.
waiting_for_articles
=
false
self
.
waiting_for_articles
=
false
history
.
replaceState
({
history
.
replaceState
({
...
@@ -259,7 +271,9 @@ export default {
...
@@ -259,7 +271,9 @@ export default {
monthly_nn
:
null
,
monthly_nn
:
null
,
event
:
null
,
event
:
null
,
previous
:
this
.
$route
.
fullPath
,
previous
:
this
.
$route
.
fullPath
,
article_info
:
null
article_info
:
null
,
page
:
1
,
max_scroll
:
0
}
}
},
},
computed
:
{
computed
:
{
...
@@ -414,6 +428,29 @@ export default {
...
@@ -414,6 +428,29 @@ export default {
}
}
}
}
window
.
onscroll
=
()
=>
{
console
.
log
(
document
.
body
.
scrollHeight
-
window
.
window
.
innerHeight
)
console
.
log
(
"
yof, max
"
,
window
.
pageYOffset
,
this
.
max_scroll
)
if
(
window
.
pageYOffset
>
this
.
max_scroll
&&
window
.
pageYOffset
>
(
document
.
body
.
scrollHeight
-
window
.
window
.
innerHeight
*
2
))
{
this
.
max_scroll
=
document
.
body
.
scrollHeight
-
window
.
window
.
innerHeight
-
1
console
.
log
(
"
MAX
"
,
this
.
max_scroll
)
let
offset
=
10
*
this
.
page
this
.
page
+=
1
if
(
!
this
.
waiting_for_articles
)
{
self
.
waiting_for_articles
=
true
console
.
log
(
"
PARAMS
"
,
this
.
query
.
q
,
offset
,
10
)
Promise
.
all
([
load_articles
(
this
,
this
.
query
,
offset
,
10
,
"
bm
"
),
load_articles
(
this
,
this
.
query
,
offset
,
10
,
"
nn
"
)
]).
then
(()
=>
{
console
.
log
(
"
SUCCESS
"
)
self
.
waiting_for_articles
=
false
})
}
}
}
}
}
}
}
</
script
>
</
script
>
...
...
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