Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
b98f85d8
Unverified
Commit
b98f85d8
authored
May 01, 2023
by
João Nuno Mota
Committed by
GitHub
May 01, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add infinite scroll for memos (#1614)
Add infinite scroll for memos on home
parent
3314fe8b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
3 deletions
+19
-3
MemoList.tsx
web/src/components/MemoList.tsx
+19
-3
No files found.
web/src/components/MemoList.tsx
View file @
b98f85d8
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
,
use
Ref
,
use
State
}
from
"react"
;
import
{
toast
}
from
"react-hot-toast"
;
import
{
toast
}
from
"react-hot-toast"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
useTranslation
}
from
"react-i18next"
;
import
{
useFilterStore
,
useMemoStore
,
useShortcutStore
,
useUserStore
}
from
"@/store/module"
;
import
{
useFilterStore
,
useMemoStore
,
useShortcutStore
,
useUserStore
}
from
"@/store/module"
;
...
@@ -86,6 +86,8 @@ const MemoList = () => {
...
@@ -86,6 +86,8 @@ const MemoList = () => {
unpinnedMemos.sort(memoSort);
unpinnedMemos.sort(memoSort);
const sortedMemos = pinnedMemos.concat(unpinnedMemos).filter((m) =
>
m.rowStatus === "NORMAL");
const sortedMemos = pinnedMemos.concat(unpinnedMemos).filter((m) =
>
m.rowStatus === "NORMAL");
const statusRef = useRef
<
HTMLDivElement
>
(null);
useEffect(() =
>
{
useEffect(() =
>
{
memoStore
memoStore
.
fetchMemos
()
.
fetchMemos
()
...
@@ -116,7 +118,21 @@ const MemoList = () => {
...
@@ -116,7 +118,21 @@ const MemoList = () => {
if
(
sortedMemos
.
length
<
DEFAULT_MEMO_LIMIT
)
{
if
(
sortedMemos
.
length
<
DEFAULT_MEMO_LIMIT
)
{
handleFetchMoreClick
();
handleFetchMoreClick
();
}
}
}
, [isFetching, isComplete, filter, sortedMemos.length]);
const
observer
=
new
IntersectionObserver
(([
entry
])
=>
{
if
(
entry
.
isIntersecting
)
{
handleFetchMoreClick
();
observer
.
unobserve
(
entry
.
target
);
}
});
if
(
statusRef
?.
current
)
{
observer
.
observe
(
statusRef
.
current
);
}
return
()
=>
{
if
(
statusRef
?.
current
)
{
observer
.
unobserve
(
statusRef
.
current
);
}
};
}
, [isFetching, isComplete, filter, sortedMemos.length, statusRef]);
const handleFetchMoreClick = async () =
>
{
const handleFetchMoreClick = async () =
>
{
try
{
try
{
...
@@ -142,7 +158,7 @@ const MemoList = () => {
...
@@ -142,7 +158,7 @@ const MemoList = () => {
<
p
className=
"status-text"
>
{
t
(
"memo.fetching-data"
)
}
</
p
>
<
p
className=
"status-text"
>
{
t
(
"memo.fetching-data"
)
}
</
p
>
</
div
>
</
div
>
)
:
(
)
:
(
<
div
className=
"status-text-container"
>
<
div
ref=
{
statusRef
}
className=
"status-text-container"
>
<
p
className=
"status-text"
>
<
p
className=
"status-text"
>
{
isComplete
?
(
{
isComplete
?
(
sortedMemos
.
length
===
0
?
(
sortedMemos
.
length
===
0
?
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment