Skip to content

Commit 65b2e0f

Browse files
Aslam97nikivdev
authored andcommitted
fix: Bug fixing & Enhancement (#161)
* chore: memoize sorted pages * chore: make link size more precise * fix(link): disable enter press on create mode * fix(onboarding): move is base logic and use escape for single quote * fix(page): on delete success redirect to pages * fix(sntry): sentry client error report * chore(page): dynamic focus on title/content * chore(link): tweak badge class * chore(link): use nuqs for handling create mode * fix(link): refs * feat(palette): implement new link
1 parent f0835d8 commit 65b2e0f

File tree

20 files changed

+182
-232
lines changed

20 files changed

+182
-232
lines changed

web/.env.example

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ NEXT_PUBLIC_JAZZ_PEER_URL="wss://"
1313

1414
RONIN_TOKEN=
1515

16-
SENTRY_DSN=
17-
SENTRY_PROJECT=
16+
NEXT_PUBLIC_SENTRY_DSN=
17+
NEXT_PUBLIC_SENTRY_ORG=
18+
NEXT_PUBLIC_SENTRY_PROJECT=
19+
1820
# IGNORE_BUILD_ERRORS=true

web/app/api/sentry-example-api/route.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

web/app/sentry-example-page/page.tsx

Lines changed: 0 additions & 79 deletions
This file was deleted.

web/components/custom/command-palette/command-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const createCommandGroups = (
7171
icon: "Plus",
7272
value: "Create New Link...",
7373
label: "Create New Link...",
74-
action: () => actions.navigateTo("/")
74+
action: () => actions.navigateTo("/links?create=true")
7575
}
7676
]
7777
},

web/components/custom/learn-anything-onboarding.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ export function LearnAnythingOnboarding() {
2626
const [isFetching, setIsFetching] = useState(true)
2727
const [isExisting, setIsExisting] = useState(false)
2828

29-
if (pathname === "/") return null
30-
3129
useEffect(() => {
3230
const loadUser = async () => {
3331
try {
@@ -41,10 +39,10 @@ export function LearnAnythingOnboarding() {
4139
}
4240
}
4341

44-
if (!hasVisited) {
42+
if (!hasVisited && pathname !== "/") {
4543
loadUser()
4644
}
47-
}, [hasVisited, setIsOpen])
45+
}, [hasVisited, pathname, setIsOpen])
4846

4947
const handleClose = () => {
5048
setIsOpen(false)
@@ -68,8 +66,8 @@ export function LearnAnythingOnboarding() {
6866
<p className="font-medium">Existing Customer Notice</p>
6967
<p>
7068
We noticed you are an existing Learn Anything customer. We sincerely apologize for any broken experience
71-
you may have encountered on the old website. We've been working hard on this new version, which
72-
addresses previous issues and offers more features. As an early customer, you're locked in at the{" "}
69+
you may have encountered on the old website. We&apos;ve been working hard on this new version, which
70+
addresses previous issues and offers more features. As an early customer, you&apos;re locked in at the{" "}
7371
<strong>$3</strong> price for our upcoming pro version. Thank you for your support!
7472
</p>
7573
</>
@@ -85,8 +83,8 @@ export function LearnAnythingOnboarding() {
8583
<li>Update your learning status on a topic</li>
8684
</ul>
8785
<p>
88-
If you have any questions, don't hesitate to reach out. Click on question mark button in the bottom right
89-
corner and enter your message.
86+
If you have any questions, don&apos;t hesitate to reach out. Click on question mark button in the bottom
87+
right corner and enter your message.
9088
</p>
9189
</AlertDialogDescription>
9290

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
import React from "react"
22
import Link from "next/link"
3-
import { usePathname, useRouter } from "next/navigation"
3+
import { usePathname } from "next/navigation"
44
import { useAccount } from "@/lib/providers/jazz-provider"
55
import { cn } from "@/lib/utils"
66
import { PersonalLinkLists } from "@/lib/schema/personal-link"
77
import { useQueryState, parseAsStringLiteral } from "nuqs"
88
import { LEARNING_STATES } from "@/lib/constants"
99

10-
export const LinkSection: React.FC<{ pathname: string }> = ({ pathname }) => {
10+
const ALL_STATES = [{ label: "All", value: "all", icon: "List", className: "text-foreground" }, ...LEARNING_STATES]
11+
const ALL_STATES_STRING = ALL_STATES.map(ls => ls.value)
12+
13+
interface LinkSectionProps {
14+
pathname: string
15+
}
16+
17+
export const LinkSection: React.FC<LinkSectionProps> = ({ pathname }) => {
1118
const { me } = useAccount({
1219
root: {
1320
personalLinks: []
1421
}
1522
})
1623

17-
const linkCount = me?.root.personalLinks?.length || 0
18-
const isActive = pathname === "/links"
19-
2024
if (!me) return null
2125

26+
const linkCount = me.root.personalLinks?.length || 0
27+
const isActive = pathname === "/links"
28+
2229
return (
2330
<div className="group/pages flex flex-col gap-px py-2">
2431
<LinkSectionHeader linkCount={linkCount} isActive={isActive} />
@@ -34,20 +41,19 @@ interface LinkSectionHeaderProps {
3441

3542
const LinkSectionHeader: React.FC<LinkSectionHeaderProps> = ({ linkCount }) => {
3643
const pathname = usePathname()
37-
const [state] = useQueryState("state", parseAsStringLiteral(LEARNING_STATES.map(ls => ls.value)))
38-
const isLinksActive = pathname.startsWith("/links") && !state
44+
const [state] = useQueryState("state", parseAsStringLiteral(ALL_STATES_STRING))
45+
const isLinksActive = pathname.startsWith("/links") && (!state || state === "all")
3946

4047
return (
41-
<div className="flex gap-px rounded-md">
48+
<div
49+
className={cn(
50+
"flex min-h-[30px] items-center gap-px rounded-md",
51+
isLinksActive ? "bg-accent text-accent-foreground" : "hover:bg-accent hover:text-accent-foreground"
52+
)}
53+
>
4254
<Link
4355
href="/links"
44-
className={cn(
45-
"flex size-6 flex-1 items-center justify-start rounded-md px-2",
46-
"focus-visible:outline-none focus-visible:ring-0",
47-
isLinksActive
48-
? "bg-accent text-accent-foreground items-center justify-center py-3"
49-
: "hover:bg-accent hover:text-accent-foreground"
50-
)}
56+
className="flex flex-1 items-center justify-start rounded-md px-2 py-1 focus-visible:outline-none focus-visible:ring-0"
5157
>
5258
<p className="flex w-full items-center text-xs font-medium">
5359
Links
@@ -66,24 +72,29 @@ const List: React.FC<ListProps> = ({ personalLinks }) => {
6672
const pathname = usePathname()
6773
const [state] = useQueryState("state", parseAsStringLiteral(LEARNING_STATES.map(ls => ls.value)))
6874

69-
const toLearnCount = personalLinks.filter(link => link?.learningState === "wantToLearn").length
70-
const learningCount = personalLinks.filter(link => link?.learningState === "learning").length
71-
const learnedCount = personalLinks.filter(link => link?.learningState === "learned").length
72-
73-
const isActive = (checkState: string) => {
74-
return pathname === "/links" && state === checkState
75+
const linkCounts = {
76+
wantToLearn: personalLinks.filter(link => link?.learningState === "wantToLearn").length,
77+
learning: personalLinks.filter(link => link?.learningState === "learning").length,
78+
learned: personalLinks.filter(link => link?.learningState === "learned").length
7579
}
7680

81+
const isActive = (checkState: string) => pathname === "/links" && state === checkState
82+
7783
return (
7884
<div className="flex flex-col gap-px">
7985
<ListItem
8086
label="To Learn"
8187
href="/links?state=wantToLearn"
82-
count={toLearnCount}
88+
count={linkCounts.wantToLearn}
8389
isActive={isActive("wantToLearn")}
8490
/>
85-
<ListItem label="Learning" href="/links?state=learning" count={learningCount} isActive={isActive("learning")} />
86-
<ListItem label="Learned" href="/links?state=learned" count={learnedCount} isActive={isActive("learned")} />
91+
<ListItem
92+
label="Learning"
93+
href="/links?state=learning"
94+
count={linkCounts.learning}
95+
isActive={isActive("learning")}
96+
/>
97+
<ListItem label="Learned" href="/links?state=learned" count={linkCounts.learned} isActive={isActive("learned")} />
8798
</div>
8899
)
89100
}
@@ -95,26 +106,23 @@ interface ListItemProps {
95106
isActive: boolean
96107
}
97108

98-
const ListItem: React.FC<ListItemProps> = ({ label, href, count, isActive }) => {
99-
return (
100-
<div className="group/reorder-page relative">
101-
<div className="group/topic-link relative flex min-w-0 flex-1">
102-
<Link
103-
href={href}
104-
className={cn(
105-
"relative flex h-8 w-full items-center gap-2 rounded-md p-1.5 font-medium",
106-
isActive ? "bg-accent text-accent-foreground" : "hover:bg-accent hover:text-accent-foreground"
107-
)}
108-
>
109-
<div className="flex max-w-full flex-1 items-center gap-1.5 truncate text-sm">
110-
<p className={cn("truncate opacity-95 group-hover/topic-link:opacity-100")}>{label}</p>
111-
</div>
112-
</Link>
113-
114-
{count > 0 && (
115-
<span className="absolute right-2 top-1/2 z-[1] -translate-y-1/2 rounded p-1 text-sm">{count}</span>
109+
const ListItem: React.FC<ListItemProps> = ({ label, href, count, isActive }) => (
110+
<div className="group/reorder-page relative">
111+
<div className="group/topic-link relative flex min-w-0 flex-1">
112+
<Link
113+
href={href}
114+
className={cn(
115+
"relative flex h-8 w-full items-center gap-2 rounded-md p-1.5 font-medium",
116+
isActive ? "bg-accent text-accent-foreground" : "hover:bg-accent hover:text-accent-foreground"
116117
)}
117-
</div>
118+
>
119+
<div className="flex max-w-full flex-1 items-center gap-1.5 truncate text-sm">
120+
<p className={cn("truncate opacity-95 group-hover/topic-link:opacity-100")}>{label}</p>
121+
</div>
122+
</Link>
123+
{count > 0 && (
124+
<span className="absolute right-2 top-1/2 z-[1] -translate-y-1/2 rounded p-1 text-sm">{count}</span>
125+
)}
118126
</div>
119-
)
120-
}
127+
</div>
128+
)

web/components/custom/sidebar/partial/page-section.tsx

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react"
1+
import React, { useMemo } from "react"
22
import { useAtom } from "jotai"
33
import { usePathname, useRouter } from "next/navigation"
44
import { useAccount } from "@/lib/providers/jazz-provider"
@@ -9,7 +9,6 @@ import { Button } from "@/components/ui/button"
99
import { LaIcon } from "@/components/custom/la-icon"
1010
import { toast } from "sonner"
1111
import Link from "next/link"
12-
import { useEffect } from "react"
1312
import {
1413
DropdownMenu,
1514
DropdownMenuContent,
@@ -54,14 +53,14 @@ export const PageSection: React.FC<{ pathname?: string }> = ({ pathname }) => {
5453
}
5554
})
5655

57-
const [sort, setSort] = useAtom(pageSortAtom)
58-
const [show, setShow] = useAtom(pageShowAtom)
59-
60-
const pageCount = me?.root.personalPages?.length || 0
61-
const isActive = pathname === "/pages"
56+
const [sort] = useAtom(pageSortAtom)
57+
const [show] = useAtom(pageShowAtom)
6258

6359
if (!me) return null
6460

61+
const pageCount = me.root.personalPages?.length || 0
62+
const isActive = pathname === "/pages"
63+
6564
return (
6665
<div className="group/pages flex flex-col gap-px py-2">
6766
<PageSectionHeader pageCount={pageCount} isActive={isActive} />
@@ -142,24 +141,19 @@ interface PageListProps {
142141
show: ShowOption
143142
}
144143

145-
const PageList: React.FC<PageListProps> = ({ personalPages }) => {
144+
const PageList: React.FC<PageListProps> = ({ personalPages, sort, show }) => {
146145
const pathname = usePathname()
147146

148-
const [sortCriteria] = useAtom(pageSortAtom)
149-
const [showCount] = useAtom(pageShowAtom)
150-
151-
const sortedPages = [...personalPages]
152-
.sort((a, b) => {
153-
switch (sortCriteria) {
154-
case "title":
147+
const sortedPages = useMemo(() => {
148+
return [...personalPages]
149+
.sort((a, b) => {
150+
if (sort === "title") {
155151
return (a?.title ?? "").localeCompare(b?.title ?? "")
156-
case "recent":
157-
return (b?.updatedAt?.getTime() ?? 0) - (a?.updatedAt?.getTime() ?? 0)
158-
default:
159-
return 0
160-
}
161-
})
162-
.slice(0, showCount === 0 ? personalPages.length : showCount)
152+
}
153+
return (b?.updatedAt?.getTime() ?? 0) - (a?.updatedAt?.getTime() ?? 0)
154+
})
155+
.slice(0, show === 0 ? personalPages.length : show)
156+
}, [personalPages, sort, show])
163157

164158
return (
165159
<div className="flex flex-col gap-px">
@@ -185,7 +179,7 @@ const PageListItem: React.FC<PageListItemProps> = ({ page, isActive }) => (
185179
{ "bg-accent text-accent-foreground": isActive }
186180
)}
187181
>
188-
<div className="flex max-w-full flex-1 items-center gap-1.5 truncate text-sm">
182+
<div className="flex max-w-[calc(100%-1rem)] flex-1 items-center gap-1.5 truncate text-sm">
189183
<LaIcon name="FileText" className="flex-shrink-0 opacity-60" />
190184
<p className="truncate opacity-95 group-hover/sidebar-link:opacity-100">{page.title || "Untitled"}</p>
191185
</div>

0 commit comments

Comments
 (0)