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
271a8c8c
Commit
271a8c8c
authored
Feb 24, 2025
by
Johnny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: home layout
parent
9107a941
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
98 additions
and
200 deletions
+98
-200
ExploreSidebar.tsx
web/src/components/ExploreSidebar/ExploreSidebar.tsx
+0
-39
ExploreSidebarDrawer.tsx
web/src/components/ExploreSidebar/ExploreSidebarDrawer.tsx
+0
-38
index.ts
web/src/components/ExploreSidebar/index.ts
+0
-4
HomeSidebar.tsx
web/src/components/HomeSidebar/HomeSidebar.tsx
+2
-2
HomeLayout.tsx
web/src/layouts/HomeLayout.tsx
+38
-0
SuspenseWrapper.tsx
web/src/layouts/SuspenseWrapper.tsx
+0
-13
Explore.tsx
web/src/pages/Explore.tsx
+17
-42
Home.tsx
web/src/pages/Home.tsx
+21
-46
index.tsx
web/src/router/index.tsx
+20
-16
No files found.
web/src/components/ExploreSidebar/ExploreSidebar.tsx
deleted
100644 → 0
View file @
9107a941
import
useDebounce
from
"react-use/lib/useDebounce"
;
import
SearchBar
from
"@/components/SearchBar"
;
import
{
useUserStatsStore
}
from
"@/store/v1"
;
import
{
cn
}
from
"@/utils"
;
import
TagsSection
from
"../HomeSidebar/TagsSection"
;
import
MemoFilters
from
"../MemoFilters"
;
import
StatisticsView
from
"../StatisticsView"
;
interface
Props
{
className
?:
string
;
}
const
ExploreSidebar
=
(
props
:
Props
)
=>
{
const
userStatsStore
=
useUserStatsStore
();
useDebounce
(
async
()
=>
{
await
userStatsStore
.
listUserStats
();
},
300
,
[
userStatsStore
.
stateId
],
);
return
(
<
aside
className=
{
cn
(
"relative w-full h-auto max-h-screen overflow-auto hide-scrollbar flex flex-col justify-start items-start"
,
props
.
className
,
)
}
>
<
SearchBar
/>
<
MemoFilters
/>
<
StatisticsView
/>
<
TagsSection
readonly=
{
true
}
/>
</
aside
>
);
};
export
default
ExploreSidebar
;
web/src/components/ExploreSidebar/ExploreSidebarDrawer.tsx
deleted
100644 → 0
View file @
9107a941
import
{
Drawer
}
from
"@mui/joy"
;
import
{
Button
}
from
"@usememos/mui"
;
import
{
SearchIcon
}
from
"lucide-react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useLocation
}
from
"react-router-dom"
;
import
ExploreSidebar
from
"./ExploreSidebar"
;
const
ExploreSidebarDrawer
=
()
=>
{
const
location
=
useLocation
();
const
[
open
,
setOpen
]
=
useState
(
false
);
useEffect
(()
=>
{
setOpen
(
false
);
},
[
location
.
pathname
]);
const
toggleDrawer
=
(
inOpen
:
boolean
)
=>
(
event
:
React
.
KeyboardEvent
|
React
.
MouseEvent
)
=>
{
if
(
event
.
type
===
"keydown"
&&
((
event
as
React
.
KeyboardEvent
).
key
===
"Tab"
||
(
event
as
React
.
KeyboardEvent
).
key
===
"Shift"
))
{
return
;
}
setOpen
(
inOpen
);
};
return
(
<>
<
Button
variant=
"plain"
className=
"!bg-transparent px-2"
onClick=
{
toggleDrawer
(
true
)
}
>
<
SearchIcon
className=
"w-5 h-auto dark:text-gray-400"
/>
</
Button
>
<
Drawer
anchor=
"right"
size=
"sm"
open=
{
open
}
onClose=
{
toggleDrawer
(
false
)
}
>
<
div
className=
"w-full h-full px-4 bg-zinc-100 dark:bg-zinc-900"
>
<
ExploreSidebar
className=
"py-4"
/>
</
div
>
</
Drawer
>
</>
);
};
export
default
ExploreSidebarDrawer
;
web/src/components/ExploreSidebar/index.ts
deleted
100644 → 0
View file @
9107a941
import
ExploreSidebar
from
"./ExploreSidebar"
;
import
ExploreSidebarDrawer
from
"./ExploreSidebarDrawer"
;
export
{
ExploreSidebar
,
ExploreSidebarDrawer
};
web/src/components/HomeSidebar/HomeSidebar.tsx
View file @
271a8c8c
import
useDebounce
from
"react-use/lib/useDebounce"
;
import
useDebounce
from
"react-use/lib/useDebounce"
;
import
SearchBar
from
"@/components/SearchBar"
;
import
SearchBar
from
"@/components/SearchBar"
;
import
StatisticsView
from
"@/components/StatisticsView"
;
import
useCurrentUser
from
"@/hooks/useCurrentUser"
;
import
useCurrentUser
from
"@/hooks/useCurrentUser"
;
import
{
useMemoList
,
useUserStatsStore
}
from
"@/store/v1"
;
import
{
useMemoList
,
useUserStatsStore
}
from
"@/store/v1"
;
import
{
cn
}
from
"@/utils"
;
import
{
cn
}
from
"@/utils"
;
import
MemoFilters
from
"../MemoFilters"
;
import
MemoFilters
from
"../MemoFilters"
;
import
StatisticsView
from
"../StatisticsView"
;
import
ShortcutsSection
from
"./ShortcutsSection"
;
import
ShortcutsSection
from
"./ShortcutsSection"
;
import
TagsSection
from
"./TagsSection"
;
import
TagsSection
from
"./TagsSection"
;
...
@@ -30,7 +30,7 @@ const HomeSidebar = (props: Props) => {
...
@@ -30,7 +30,7 @@ const HomeSidebar = (props: Props) => {
<
SearchBar
/>
<
SearchBar
/>
<
MemoFilters
/>
<
MemoFilters
/>
<
StatisticsView
/>
<
StatisticsView
/>
<
ShortcutsSection
/>
{
currentUser
&&
<
ShortcutsSection
/>
}
<
TagsSection
/>
<
TagsSection
/>
</
aside
>
</
aside
>
);
);
...
...
web/src/layouts/HomeLayout.tsx
0 → 100644
View file @
271a8c8c
import
{
observer
}
from
"mobx-react-lite"
;
import
{
Outlet
}
from
"react-router-dom"
;
import
{
HomeSidebar
,
HomeSidebarDrawer
}
from
"@/components/HomeSidebar"
;
import
MobileHeader
from
"@/components/MobileHeader"
;
import
useResponsiveWidth
from
"@/hooks/useResponsiveWidth"
;
import
{
cn
}
from
"@/utils"
;
const
HomeLayout
=
observer
(()
=>
{
const
{
md
,
lg
}
=
useResponsiveWidth
();
return
(
<
section
className=
"@container w-full min-h-full flex flex-col justify-start items-center"
>
{
!
md
&&
(
<
MobileHeader
>
<
HomeSidebarDrawer
/>
</
MobileHeader
>
)
}
<
div
className=
{
cn
(
"w-full min-h-full flex flex-row justify-start items-start"
)
}
>
{
md
&&
(
<
div
className=
{
cn
(
"sticky top-0 left-0 shrink-0 h-[100svh] transition-all"
,
"border-r border-gray-200 dark:border-zinc-800"
,
lg
?
"px-5 w-72"
:
"px-4 w-56"
,
)
}
>
<
HomeSidebar
className=
{
cn
(
"py-6"
)
}
/>
</
div
>
)
}
<
div
className=
{
cn
(
"w-full mx-auto px-4 sm:px-6 sm:pt-3 md:pt-6 pb-8"
,
md
&&
"max-w-3xl"
)
}
>
<
Outlet
/>
</
div
>
</
div
>
</
section
>
);
});
export
default
HomeLayout
;
web/src/layouts/SuspenseWrapper.tsx
deleted
100644 → 0
View file @
9107a941
import
{
Suspense
}
from
"react"
;
import
{
Outlet
}
from
"react-router-dom"
;
import
Loading
from
"@/pages/Loading"
;
const
SuspenseWrapper
=
()
=>
{
return
(
<
Suspense
fallback=
{
<
Loading
/>
}
>
<
Outlet
/>
</
Suspense
>
);
};
export
default
SuspenseWrapper
;
web/src/pages/Explore.tsx
View file @
271a8c8c
import
dayjs
from
"dayjs"
;
import
dayjs
from
"dayjs"
;
import
{
useMemo
}
from
"react"
;
import
{
useMemo
}
from
"react"
;
import
{
ExploreSidebar
,
ExploreSidebarDrawer
}
from
"@/components/ExploreSidebar"
;
import
MemoView
from
"@/components/MemoView"
;
import
MemoView
from
"@/components/MemoView"
;
import
MobileHeader
from
"@/components/MobileHeader"
;
import
PagedMemoList
from
"@/components/PagedMemoList"
;
import
PagedMemoList
from
"@/components/PagedMemoList"
;
import
useCurrentUser
from
"@/hooks/useCurrentUser"
;
import
useCurrentUser
from
"@/hooks/useCurrentUser"
;
import
useResponsiveWidth
from
"@/hooks/useResponsiveWidth"
;
import
{
useMemoFilterStore
}
from
"@/store/v1"
;
import
{
useMemoFilterStore
}
from
"@/store/v1"
;
import
{
Direction
,
State
}
from
"@/types/proto/api/v1/common"
;
import
{
Direction
,
State
}
from
"@/types/proto/api/v1/common"
;
import
{
Memo
}
from
"@/types/proto/api/v1/memo_service"
;
import
{
Memo
}
from
"@/types/proto/api/v1/memo_service"
;
import
{
cn
}
from
"@/utils"
;
const
Explore
=
()
=>
{
const
Explore
=
()
=>
{
const
{
md
,
lg
}
=
useResponsiveWidth
();
const
user
=
useCurrentUser
();
const
user
=
useCurrentUser
();
const
memoFilterStore
=
useMemoFilterStore
();
const
memoFilterStore
=
useMemoFilterStore
();
...
@@ -49,44 +44,24 @@ const Explore = () => {
...
@@ -49,44 +44,24 @@ const Explore = () => {
},
[
user
,
memoFilterStore
.
filters
,
memoFilterStore
.
orderByTimeAsc
]);
},
[
user
,
memoFilterStore
.
filters
,
memoFilterStore
.
orderByTimeAsc
]);
return
(
return
(
<
section
className=
"@container w-full min-h-full flex flex-col justify-start items-center"
>
<>
{
!
md
&&
(
<
div
className=
"flex flex-col justify-start items-start w-full max-w-full"
>
<
MobileHeader
>
<
PagedMemoList
<
ExploreSidebarDrawer
/>
renderer=
{
(
memo
:
Memo
)
=>
<
MemoView
key=
{
`${memo.name}-${memo.updateTime}`
}
memo=
{
memo
}
showCreator
showVisibility
compact
/>
}
</
MobileHeader
>
listSort=
{
(
memos
:
Memo
[])
=>
)
}
memos
<
div
className=
{
cn
(
"w-full min-h-full flex flex-row justify-start items-start"
)
}
>
.
filter
((
memo
)
=>
memo
.
state
===
State
.
NORMAL
)
{
md
&&
(
.
sort
((
a
,
b
)
=>
<
div
memoFilterStore
.
orderByTimeAsc
className=
{
cn
(
?
dayjs
(
a
.
displayTime
).
unix
()
-
dayjs
(
b
.
displayTime
).
unix
()
"sticky top-0 left-0 shrink-0 h-[100svh] transition-all"
,
:
dayjs
(
b
.
displayTime
).
unix
()
-
dayjs
(
a
.
displayTime
).
unix
(),
"border-r border-gray-200 dark:border-zinc-800"
,
)
lg
?
"px-5 w-72"
:
"px-4 w-56"
,
}
)
}
direction=
{
memoFilterStore
.
orderByTimeAsc
?
Direction
.
ASC
:
Direction
.
DESC
}
>
oldFilter=
{
memoListFilter
}
<
ExploreSidebar
className=
{
cn
(
"py-6"
)
}
/>
/>
</
div
>
)
}
<
div
className=
{
cn
(
"w-full mx-auto px-4 sm:px-6 sm:pt-3 md:pt-6 pb-8"
,
md
&&
"max-w-3xl"
)
}
>
<
div
className=
"flex flex-col justify-start items-start w-full max-w-full"
>
<
PagedMemoList
renderer=
{
(
memo
:
Memo
)
=>
<
MemoView
key=
{
`${memo.name}-${memo.updateTime}`
}
memo=
{
memo
}
showCreator
showVisibility
compact
/>
}
listSort=
{
(
memos
:
Memo
[])
=>
memos
.
filter
((
memo
)
=>
memo
.
state
===
State
.
NORMAL
)
.
sort
((
a
,
b
)
=>
memoFilterStore
.
orderByTimeAsc
?
dayjs
(
a
.
displayTime
).
unix
()
-
dayjs
(
b
.
displayTime
).
unix
()
:
dayjs
(
b
.
displayTime
).
unix
()
-
dayjs
(
a
.
displayTime
).
unix
(),
)
}
direction=
{
memoFilterStore
.
orderByTimeAsc
?
Direction
.
ASC
:
Direction
.
DESC
}
oldFilter=
{
memoListFilter
}
/>
</
div
>
</
div
>
</
div
>
</
div
>
</
section
>
</>
);
);
};
};
...
...
web/src/pages/Home.tsx
View file @
271a8c8c
import
dayjs
from
"dayjs"
;
import
dayjs
from
"dayjs"
;
import
{
observer
}
from
"mobx-react-lite"
;
import
{
observer
}
from
"mobx-react-lite"
;
import
{
useMemo
}
from
"react"
;
import
{
useMemo
}
from
"react"
;
import
{
HomeSidebar
,
HomeSidebarDrawer
}
from
"@/components/HomeSidebar"
;
import
MemoEditor
from
"@/components/MemoEditor"
;
import
MemoEditor
from
"@/components/MemoEditor"
;
import
MemoView
from
"@/components/MemoView"
;
import
MemoView
from
"@/components/MemoView"
;
import
MobileHeader
from
"@/components/MobileHeader"
;
import
PagedMemoList
from
"@/components/PagedMemoList"
;
import
PagedMemoList
from
"@/components/PagedMemoList"
;
import
useCurrentUser
from
"@/hooks/useCurrentUser"
;
import
useCurrentUser
from
"@/hooks/useCurrentUser"
;
import
useResponsiveWidth
from
"@/hooks/useResponsiveWidth"
;
import
{
useMemoFilterStore
}
from
"@/store/v1"
;
import
{
useMemoFilterStore
}
from
"@/store/v1"
;
import
{
userStore
}
from
"@/store/v2"
;
import
{
userStore
}
from
"@/store/v2"
;
import
{
Direction
,
State
}
from
"@/types/proto/api/v1/common"
;
import
{
Direction
,
State
}
from
"@/types/proto/api/v1/common"
;
import
{
Memo
}
from
"@/types/proto/api/v1/memo_service"
;
import
{
Memo
}
from
"@/types/proto/api/v1/memo_service"
;
import
{
cn
}
from
"@/utils"
;
const
Home
=
observer
(()
=>
{
const
Home
=
observer
(()
=>
{
const
{
md
,
lg
}
=
useResponsiveWidth
();
const
user
=
useCurrentUser
();
const
user
=
useCurrentUser
();
const
memoFilterStore
=
useMemoFilterStore
();
const
memoFilterStore
=
useMemoFilterStore
();
const
selectedShortcut
=
userStore
.
state
.
shortcuts
.
find
((
shortcut
)
=>
shortcut
.
id
===
memoFilterStore
.
shortcut
);
const
selectedShortcut
=
userStore
.
state
.
shortcuts
.
find
((
shortcut
)
=>
shortcut
.
id
===
memoFilterStore
.
shortcut
);
...
@@ -53,48 +48,28 @@ const Home = observer(() => {
...
@@ -53,48 +48,28 @@ const Home = observer(() => {
},
[
user
,
memoFilterStore
.
filters
,
memoFilterStore
.
orderByTimeAsc
]);
},
[
user
,
memoFilterStore
.
filters
,
memoFilterStore
.
orderByTimeAsc
]);
return
(
return
(
<
section
className=
"@container w-full min-h-full flex flex-col justify-start items-center"
>
<>
{
!
md
&&
(
<
MemoEditor
className=
"mb-2"
cacheKey=
"home-memo-editor"
/>
<
MobileHeader
>
<
div
className=
"flex flex-col justify-start items-start w-full max-w-full"
>
<
HomeSidebarDrawer
/>
<
PagedMemoList
</
MobileHeader
>
renderer=
{
(
memo
:
Memo
)
=>
<
MemoView
key=
{
`${memo.name}-${memo.displayTime}`
}
memo=
{
memo
}
showVisibility
showPinned
compact
/>
}
)
}
listSort=
{
(
memos
:
Memo
[])
=>
<
div
className=
{
cn
(
"w-full min-h-full flex flex-row justify-start items-start"
)
}
>
memos
{
md
&&
(
.
filter
((
memo
)
=>
memo
.
state
===
State
.
NORMAL
)
<
div
.
sort
((
a
,
b
)
=>
className=
{
cn
(
memoFilterStore
.
orderByTimeAsc
"sticky top-0 left-0 shrink-0 h-[100svh] transition-all"
,
?
dayjs
(
a
.
displayTime
).
unix
()
-
dayjs
(
b
.
displayTime
).
unix
()
"border-r border-gray-200 dark:border-zinc-800"
,
:
dayjs
(
b
.
displayTime
).
unix
()
-
dayjs
(
a
.
displayTime
).
unix
(),
lg
?
"px-5 w-72"
:
"px-4 w-56"
,
)
)
}
.
sort
((
a
,
b
)
=>
Number
(
b
.
pinned
)
-
Number
(
a
.
pinned
))
>
}
<
HomeSidebar
className=
{
cn
(
"py-6"
)
}
/>
owner=
{
user
.
name
}
</
div
>
direction=
{
memoFilterStore
.
orderByTimeAsc
?
Direction
.
ASC
:
Direction
.
DESC
}
)
}
filter=
{
selectedShortcut
?.
filter
||
""
}
<
div
className=
{
cn
(
"w-full mx-auto px-4 sm:px-6 sm:pt-3 md:pt-6 pb-8"
,
md
&&
"max-w-3xl"
)
}
>
oldFilter=
{
memoListFilter
}
<
MemoEditor
className=
"mb-2"
cacheKey=
"home-memo-editor"
/>
/>
<
div
className=
"flex flex-col justify-start items-start w-full max-w-full"
>
<
PagedMemoList
renderer=
{
(
memo
:
Memo
)
=>
<
MemoView
key=
{
`${memo.name}-${memo.displayTime}`
}
memo=
{
memo
}
showVisibility
showPinned
compact
/>
}
listSort=
{
(
memos
:
Memo
[])
=>
memos
.
filter
((
memo
)
=>
memo
.
state
===
State
.
NORMAL
)
.
sort
((
a
,
b
)
=>
memoFilterStore
.
orderByTimeAsc
?
dayjs
(
a
.
displayTime
).
unix
()
-
dayjs
(
b
.
displayTime
).
unix
()
:
dayjs
(
b
.
displayTime
).
unix
()
-
dayjs
(
a
.
displayTime
).
unix
(),
)
.
sort
((
a
,
b
)
=>
Number
(
b
.
pinned
)
-
Number
(
a
.
pinned
))
}
owner=
{
user
.
name
}
direction=
{
memoFilterStore
.
orderByTimeAsc
?
Direction
.
ASC
:
Direction
.
DESC
}
filter=
{
selectedShortcut
?.
filter
||
""
}
oldFilter=
{
memoListFilter
}
/>
</
div
>
</
div
>
</
div
>
</
div
>
</
section
>
</>
);
);
});
});
...
...
web/src/router/index.tsx
View file @
271a8c8c
import
{
createBrowserRouter
}
from
"react-router-dom"
;
import
{
createBrowserRouter
}
from
"react-router-dom"
;
import
App
from
"@/App"
;
import
App
from
"@/App"
;
import
HomeLayout
from
"@/layouts/HomeLayout"
;
import
RootLayout
from
"@/layouts/RootLayout"
;
import
RootLayout
from
"@/layouts/RootLayout"
;
import
SuspenseWrapper
from
"@/layouts/SuspenseWrapper"
;
import
About
from
"@/pages/About"
;
import
About
from
"@/pages/About"
;
import
AdminSignIn
from
"@/pages/AdminSignIn"
;
import
AdminSignIn
from
"@/pages/AdminSignIn"
;
import
Archived
from
"@/pages/Archived"
;
import
Archived
from
"@/pages/Archived"
;
...
@@ -37,7 +37,6 @@ const router = createBrowserRouter([
...
@@ -37,7 +37,6 @@ const router = createBrowserRouter([
children
:
[
children
:
[
{
{
path
:
Routes
.
AUTH
,
path
:
Routes
.
AUTH
,
element
:
<
SuspenseWrapper
/>,
children
:
[
children
:
[
{
{
path
:
""
,
path
:
""
,
...
@@ -62,8 +61,25 @@ const router = createBrowserRouter([
...
@@ -62,8 +61,25 @@ const router = createBrowserRouter([
element
:
<
RootLayout
/>,
element
:
<
RootLayout
/>,
children
:
[
children
:
[
{
{
path
:
""
,
element
:
<
HomeLayout
/>,
element
:
<
Home
/>,
children
:
[
{
path
:
""
,
element
:
<
Home
/>,
},
{
path
:
Routes
.
EXPLORE
,
element
:
<
Explore
/>,
},
{
path
:
Routes
.
ARCHIVED
,
element
:
<
Archived
/>,
},
{
path
:
"u/:username"
,
element
:
<
UserProfile
/>,
},
],
},
},
{
{
path
:
Routes
.
RESOURCES
,
path
:
Routes
.
RESOURCES
,
...
@@ -73,26 +89,14 @@ const router = createBrowserRouter([
...
@@ -73,26 +89,14 @@ const router = createBrowserRouter([
path
:
Routes
.
INBOX
,
path
:
Routes
.
INBOX
,
element
:
<
Inboxes
/>,
element
:
<
Inboxes
/>,
},
},
{
path
:
Routes
.
ARCHIVED
,
element
:
<
Archived
/>,
},
{
{
path
:
Routes
.
SETTING
,
path
:
Routes
.
SETTING
,
element
:
<
Setting
/>,
element
:
<
Setting
/>,
},
},
{
path
:
Routes
.
EXPLORE
,
element
:
<
Explore
/>,
},
{
{
path
:
"memos/:uid"
,
path
:
"memos/:uid"
,
element
:
<
MemoDetail
/>,
element
:
<
MemoDetail
/>,
},
},
{
path
:
"u/:username"
,
element
:
<
UserProfile
/>,
},
{
{
path
:
Routes
.
ABOUT
,
path
:
Routes
.
ABOUT
,
element
:
<
About
/>,
element
:
<
About
/>,
...
...
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