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
c240b705
Commit
c240b705
authored
Jan 22, 2026
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add enabled option to useInfiniteMemos and PagedMemoList for conditional fetching
parent
956ae0eb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
12 deletions
+17
-12
PagedMemoList.tsx
web/src/components/PagedMemoList/PagedMemoList.tsx
+10
-7
useMemoQueries.ts
web/src/hooks/useMemoQueries.ts
+4
-3
Home.tsx
web/src/pages/Home.tsx
+3
-2
No files found.
web/src/components/PagedMemoList/PagedMemoList.tsx
View file @
c240b705
...
...
@@ -27,6 +27,7 @@ interface Props {
filter
?:
string
;
pageSize
?:
number
;
showCreator
?:
boolean
;
enabled
?:
boolean
;
}
function
useAutoFetchWhenNotScrollable
({
...
...
@@ -88,13 +89,15 @@ const PagedMemoList = (props: Props) => {
// Show memo editor only on the root route
const
showMemoEditor
=
Boolean
(
matchPath
(
Routes
.
ROOT
,
window
.
location
.
pathname
));
// Use React Query's infinite query for pagination
const
{
data
,
fetchNextPage
,
hasNextPage
,
isFetchingNextPage
,
isLoading
}
=
useInfiniteMemos
(
{
const
{
data
,
fetchNextPage
,
hasNextPage
,
isFetchingNextPage
,
isLoading
}
=
useInfiniteMemos
(
{
state
:
props
.
state
||
State
.
NORMAL
,
orderBy
:
props
.
orderBy
||
"display_time desc"
,
filter
:
props
.
filter
,
pageSize
:
props
.
pageSize
||
DEFAULT_LIST_MEMOS_PAGE_SIZE
,
});
},
{
enabled
:
props
.
enabled
??
true
},
);
// Flatten pages into a single array of memos
const
memos
=
useMemo
(()
=>
data
?.
pages
.
flatMap
((
page
)
=>
page
.
memos
)
||
[],
[
data
]);
...
...
web/src/hooks/useMemoQueries.ts
View file @
c240b705
...
...
@@ -26,7 +26,7 @@ export function useMemos(request: Partial<ListMemosRequest> = {}) {
});
}
export
function
useInfiniteMemos
(
request
:
Partial
<
ListMemosRequest
>
=
{})
{
export
function
useInfiniteMemos
(
request
:
Partial
<
ListMemosRequest
>
=
{}
,
options
?:
{
enabled
?:
boolean
}
)
{
return
useInfiniteQuery
({
queryKey
:
memoKeys
.
list
(
request
),
queryFn
:
async
({
pageParam
})
=>
{
...
...
@@ -40,8 +40,9 @@ export function useInfiniteMemos(request: Partial<ListMemosRequest> = {}) {
},
initialPageParam
:
""
,
getNextPageParam
:
(
lastPage
)
=>
lastPage
.
nextPageToken
||
undefined
,
staleTime
:
1000
*
60
,
// Consider data fresh for 1 minute
gcTime
:
1000
*
60
*
5
,
// Keep unused data in cache for 5 minutes
staleTime
:
1000
*
60
,
gcTime
:
1000
*
60
*
5
,
enabled
:
options
?.
enabled
??
true
,
});
}
...
...
web/src/pages/Home.tsx
View file @
c240b705
...
...
@@ -3,20 +3,20 @@ import MemoView from "@/components/MemoView";
import
PagedMemoList
from
"@/components/PagedMemoList"
;
import
{
useMemoFilters
,
useMemoSorting
}
from
"@/hooks"
;
import
useCurrentUser
from
"@/hooks/useCurrentUser"
;
import
{
useInstance
}
from
"@/contexts/InstanceContext"
;
import
{
State
}
from
"@/types/proto/api/v1/common_pb"
;
import
{
Memo
}
from
"@/types/proto/api/v1/memo_service_pb"
;
const
Home
=
()
=>
{
const
user
=
useCurrentUser
();
const
{
isInitialized
}
=
useInstance
();
// Build filter using unified hook
const
memoFilter
=
useMemoFilters
({
creatorName
:
user
?.
name
,
includeShortcuts
:
true
,
includePinned
:
true
,
});
// Get sorting logic using unified hook
const
{
listSort
,
orderBy
}
=
useMemoSorting
({
pinnedFirst
:
true
,
state
:
State
.
NORMAL
,
...
...
@@ -31,6 +31,7 @@ const Home = () => {
listSort=
{
listSort
}
orderBy=
{
orderBy
}
filter=
{
memoFilter
}
enabled=
{
isInitialized
&&
!!
user
}
// Wait for contexts to stabilize before fetching
/>
</
div
>
);
...
...
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