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
7189ba40
Unverified
Commit
7189ba40
authored
Aug 05, 2023
by
boojack
Committed by
GitHub
Aug 05, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add lazy rendering in home page (#2085)
parent
218159bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
2 deletions
+36
-2
Memo.tsx
web/src/components/Memo.tsx
+35
-1
MemoList.tsx
web/src/components/MemoList.tsx
+1
-1
No files found.
web/src/components/Memo.tsx
View file @
7189ba40
...
...
@@ -27,10 +27,11 @@ interface Props {
showFull
?:
boolean
;
showVisibility
?:
boolean
;
showRelatedMemos
?:
boolean
;
lazyRendering
?:
boolean
;
}
const
Memo
:
React
.
FC
<
Props
>
=
(
props
:
Props
)
=>
{
const
{
memo
,
showCreator
,
showFull
,
showVisibility
,
showRelatedMemos
}
=
props
;
const
{
memo
,
showCreator
,
showFull
,
showVisibility
,
showRelatedMemos
,
lazyRendering
}
=
props
;
const
{
i18n
}
=
useTranslation
();
const
t
=
useTranslate
();
const
filterStore
=
useFilterStore
();
...
...
@@ -38,6 +39,7 @@ const Memo: React.FC<Props> = (props: Props) => {
const
memoStore
=
useMemoStore
();
const
memoCacheStore
=
useMemoCacheStore
();
const
userV1Store
=
useUserV1Store
();
const
[
shouldRender
,
setShouldRender
]
=
useState
<
boolean
>
(
lazyRendering
?
false
:
true
);
const
[
createdTimeStr
,
setCreatedTimeStr
]
=
useState
<
string
>
(
getRelativeTimeString
(
memo
.
displayTs
));
const
[
relatedMemoList
,
setRelatedMemoList
]
=
useState
<
Memo
[]
>
([]);
const
memoContainerRef
=
useRef
<
HTMLDivElement
>
(
null
);
...
...
@@ -77,6 +79,29 @@ const Memo: React.FC<Props> = (props: Props) => {
};
},
[
i18n
.
language
]);
// Lazy rendering.
useEffect
(()
=>
{
if
(
shouldRender
)
{
return
;
}
const
root
=
document
.
body
.
querySelector
(
"#root"
);
if
(
root
)
{
const
checkShouldRender
=
()
=>
{
if
(
root
.
scrollTop
+
window
.
innerHeight
>
(
memoContainerRef
.
current
?.
offsetTop
||
0
))
{
setShouldRender
(
true
);
root
.
removeEventListener
(
"scroll"
,
checkShouldRender
);
return
true
;
}
};
if
(
checkShouldRender
())
{
return
;
}
root
.
addEventListener
(
"scroll"
,
checkShouldRender
);
}
},
[
lazyRendering
]);
const
handleTogglePinMemoBtnClick
=
async
()
=>
{
try
{
if
(
memo
.
pinned
)
{
...
...
@@ -221,6 +246,15 @@ const Memo: React.FC<Props> = (props: Props) => {
}
};
if
(
!
shouldRender
)
{
return
(
<
div
className=
{
`memo-wrapper min-h-[128px] ${"memos-" + memo.id} ${memo.pinned && !readonly ? "pinned" : ""}`
}
ref=
{
memoContainerRef
}
></
div
>
);
}
return
(
<>
<
div
className=
{
`memo-wrapper ${"memos-" + memo.id} ${memo.pinned && !readonly ? "pinned" : ""}`
}
ref=
{
memoContainerRef
}
>
...
...
web/src/components/MemoList.tsx
View file @
7189ba40
...
...
@@ -149,7 +149,7 @@ const MemoList: React.FC<Props> = (props: Props) => {
return (
<
div
className=
"memo-list-container"
>
{
sortedMemos
.
map
((
memo
)
=>
(
<
Memo
key=
{
`${memo.id}-${memo.displayTs}`
}
memo=
{
memo
}
showVisibility
showCreator=
{
showCreator
}
/>
<
Memo
key=
{
`${memo.id}-${memo.displayTs}`
}
memo=
{
memo
}
lazyRendering
showVisibility
showCreator=
{
showCreator
}
/>
))
}
{
isFetching
?
(
<
div
className=
"status-text-container fetching-tip"
>
...
...
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