Skip to content

Commit a23dbb6

Browse files
committed
remove unused exports flagged by knip
1 parent 35c0069 commit a23dbb6

10 files changed

Lines changed: 14 additions & 312 deletions

File tree

src/app/features/assistant/parts/user-question-confirmation.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState } from "react"
22
import { T, useIntl } from "#shared/intl/setup"
3-
import { useForm } from "react-hook-form"
3+
import { useForm, useWatch } from "react-hook-form"
44
import { zodResolver } from "@hookform/resolvers/zod"
55
import { z } from "zod"
66
import { Button } from "#shared/ui/button"
@@ -51,6 +51,11 @@ function UserQuestionConfirmation({
5151
defaultValues: { selectedValue: "" },
5252
})
5353

54+
let selectedValue = useWatch({
55+
control: form.control,
56+
name: "selectedValue",
57+
})
58+
5459
let handleAnswer = async (answer: boolean | string, answerLabel?: string) => {
5560
setIsResponding(true)
5661
try {
@@ -184,7 +189,7 @@ function UserQuestionConfirmation({
184189
type="button"
185190
variant="default"
186191
onClick={form.handleSubmit(handleSubmitForm)}
187-
disabled={isResponding || !form.watch("selectedValue")}
192+
disabled={isResponding || !selectedValue}
188193
className="flex-1 md:flex-none"
189194
>
190195
<T k="tool.userQuestion.submit" />

src/app/features/people/lib/invite.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export type { InviteData }
2-
export { parseInviteHash, getOrRestoreInviteData, clearPendingInvite }
2+
export { parseInviteHash, getOrRestoreInviteData }
33

44
let PENDING_INVITE_KEY = "tilly:pending-invite"
55

@@ -40,7 +40,3 @@ function getOrRestoreInviteData(): InviteData | null {
4040

4141
return null
4242
}
43-
44-
function clearPendingInvite() {
45-
localStorage.removeItem(PENDING_INVITE_KEY)
46-
}

src/app/features/people/lib/list-utilities.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
export {
22
useAvailableLists,
3-
extractListFilterFromQuery,
4-
setListFilterInQuery,
53
removeHashtagFromSummary,
64
addHashtagToSummary,
7-
replaceHashtagInSummary,
85
extractHashtags,
96
hasHashtag,
107
}
@@ -39,17 +36,6 @@ function useAvailableLists(people: PersonWithSummary[]): AvailableList[] {
3936
return hashtags
4037
}
4138

42-
function extractListFilterFromQuery(query: string): string | null {
43-
let match = query.match(/^(#[a-zA-Z0-9_]+)\s*/)
44-
return match ? match[1].toLowerCase() : null
45-
}
46-
47-
function setListFilterInQuery(query: string, filter: string | null): string {
48-
let withoutFilter = query.replace(/^#[a-zA-Z0-9_]+\s*/, "").trim()
49-
if (!filter) return withoutFilter
50-
return `${filter} ${withoutFilter}`.trim()
51-
}
52-
5339
function removeHashtagFromSummary(
5440
summary: string | undefined,
5541
hashtag: string,
@@ -70,16 +56,6 @@ function addHashtagToSummary(
7056
return current ? `${current} ${hashtag}` : hashtag
7157
}
7258

73-
function replaceHashtagInSummary(
74-
summary: string | undefined,
75-
oldTag: string,
76-
newTag: string,
77-
): string {
78-
if (!summary) return ""
79-
let escaped = oldTag.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
80-
return summary.replace(new RegExp(`${escaped}(?=\\s|$)`, "gi"), newTag).trim()
81-
}
82-
8359
function extractHashtags(summary?: string): string[] {
8460
if (!summary) return []
8561
let matches = summary.match(/(?:^|\s)(#[a-zA-Z0-9_]+)/g)

src/app/features/reminders/parts/reminder-toolbar.tsx

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useId, useState, type ReactNode, type RefObject } from "react"
1+
import { useId, type ReactNode, type RefObject } from "react"
22
import { HugeiconsIcon } from "@hugeicons/react"
33
import {
44
Add01Icon,
@@ -14,23 +14,8 @@ import {
1414
InputGroupButton,
1515
InputGroupInput,
1616
} from "#shared/ui/input-group"
17-
import {
18-
DropdownMenu,
19-
DropdownMenuContent,
20-
DropdownMenuGroup,
21-
DropdownMenuLabel,
22-
DropdownMenuRadioGroup,
23-
DropdownMenuRadioItem,
24-
DropdownMenuTrigger,
25-
} from "#shared/ui/dropdown-menu"
26-
import { Sliders } from "react-bootstrap-icons"
2717

28-
export {
29-
ReminderToolbar,
30-
ReminderSearch,
31-
ReminderStatusFilter,
32-
NewReminderButton,
33-
}
18+
export { ReminderToolbar, ReminderSearch, NewReminderButton }
3419

3520
function ReminderToolbar({ children }: { children?: ReactNode }) {
3621
return (
@@ -92,61 +77,6 @@ function ReminderSearch({
9277
)
9378
}
9479

95-
type StatusFilter = "active" | "done" | "deleted"
96-
97-
function ReminderStatusFilter({
98-
value,
99-
onChange,
100-
}: {
101-
value: StatusFilter
102-
onChange: (value: StatusFilter) => void
103-
}) {
104-
let t = useIntl()
105-
let [open, setOpen] = useState(false)
106-
107-
let isFiltered = value !== "active"
108-
109-
let statusOptions = [
110-
{ value: "active", label: t("filter.status.active") },
111-
{ value: "done", label: t("filter.status.done") },
112-
{ value: "deleted", label: t("filter.status.deleted") },
113-
]
114-
115-
return (
116-
<DropdownMenu open={open} onOpenChange={setOpen}>
117-
<DropdownMenuTrigger
118-
render={
119-
<InputGroupButton
120-
variant={isFiltered ? "secondary" : "ghost"}
121-
size="icon-xs"
122-
onClick={() => setOpen(true)}
123-
aria-label={t("filter.status")}
124-
>
125-
<Sliders />
126-
</InputGroupButton>
127-
}
128-
/>
129-
<DropdownMenuContent align="end" className="w-auto">
130-
<DropdownMenuGroup>
131-
<DropdownMenuLabel>
132-
<T k="filter.status" />
133-
</DropdownMenuLabel>
134-
</DropdownMenuGroup>
135-
<DropdownMenuRadioGroup
136-
value={value}
137-
onValueChange={v => onChange(v as StatusFilter)}
138-
>
139-
{statusOptions.map(option => (
140-
<DropdownMenuRadioItem key={option.value} value={option.value}>
141-
{option.label}
142-
</DropdownMenuRadioItem>
143-
))}
144-
</DropdownMenuRadioGroup>
145-
</DropdownMenuContent>
146-
</DropdownMenu>
147-
)
148-
}
149-
15080
function NewReminderButton({ onClick }: { onClick: () => void }) {
15181
return (
15282
<Button onClick={onClick}>
Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
import { Account, Group, type co, type ID, deleteCoValues } from "jazz-tools"
2-
import { NotificationSettings } from "#shared/schema/user"
3-
import { ServerAccount } from "#shared/schema/server"
4-
5-
export {
6-
migrateNotificationSettings,
7-
addServerToGroup,
8-
copyNotificationSettingsData,
9-
}
10-
export type { MigrationContext, NotificationSettingsInput }
1+
export { copyNotificationSettingsData }
2+
export type { NotificationSettingsInput }
113

124
type NotificationSettingsInput = {
135
version: 1
@@ -24,11 +16,6 @@ type NotificationSettingsInput = {
2416
}>
2517
}
2618

27-
type MigrationContext = {
28-
loadAs: Account
29-
rootLanguage?: "de" | "en"
30-
}
31-
3219
type NotificationSettingsLike = {
3320
timezone?: string
3421
notificationTime?: string
@@ -65,68 +52,3 @@ function copyNotificationSettingsData(
6552
})),
6653
}
6754
}
68-
69-
async function migrateNotificationSettings(
70-
oldSettings: co.loaded<typeof NotificationSettings>,
71-
serverAccountId: string,
72-
context: MigrationContext,
73-
): Promise<{
74-
newSettings: co.loaded<typeof NotificationSettings>
75-
cleanup: () => Promise<void>
76-
}> {
77-
let group = Group.create()
78-
79-
await addServerToGroup(group, serverAccountId, context)
80-
81-
let settingsData = copyNotificationSettingsData(
82-
oldSettings,
83-
context.rootLanguage,
84-
)
85-
86-
let newSettings = NotificationSettings.create(settingsData, { owner: group })
87-
88-
let cleanup = async () => {
89-
let owner = oldSettings.$jazz.owner
90-
if (owner instanceof Group) {
91-
let hasAdminPermission = owner.members.some(
92-
m =>
93-
m.account?.$jazz.id === context.loadAs.$jazz.id && m.role === "admin",
94-
)
95-
if (!hasAdminPermission) {
96-
console.error(
97-
"[NotificationSettingsMigration] Caller lacks admin permission on owning group",
98-
)
99-
throw new Error("Caller lacks admin permission on owning group")
100-
}
101-
}
102-
103-
try {
104-
await deleteCoValues(NotificationSettings, oldSettings.$jazz.id)
105-
} catch (error) {
106-
console.error(
107-
"[NotificationSettingsMigration] Failed to delete old settings:",
108-
error,
109-
)
110-
throw error
111-
}
112-
}
113-
114-
return { newSettings, cleanup }
115-
}
116-
117-
async function addServerToGroup(
118-
group: Group,
119-
serverAccountId: string,
120-
context: MigrationContext,
121-
): Promise<void> {
122-
let serverAccount = await ServerAccount.load(
123-
serverAccountId as ID<typeof ServerAccount>,
124-
{ loadAs: context.loadAs },
125-
)
126-
127-
if (!serverAccount || !serverAccount.$isLoaded) {
128-
throw new Error("Failed to load server account")
129-
}
130-
131-
group.addMember(serverAccount, "writer")
132-
}

src/app/features/settings/lib/push-notifications.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { tryCatch } from "#shared/lib/trycatch"
44

55
export {
66
subscribeToPushNotifications,
7-
unsubscribeFromPushNotifications,
87
requestNotificationPermission,
98
getNotificationPermission,
109
arrayBufferToBase64,
@@ -95,33 +94,6 @@ async function subscribeToPushNotifications(): Promise<{
9594
}
9695
}
9796

98-
async function unsubscribeFromPushNotifications(): Promise<boolean> {
99-
let registrationResult = await tryCatch(getServiceWorkerRegistration())
100-
if (!registrationResult.ok) {
101-
return false
102-
}
103-
104-
let registration = registrationResult.data
105-
if (!registration) {
106-
return false
107-
}
108-
109-
let subscriptionResult = await tryCatch(
110-
registration.pushManager.getSubscription(),
111-
)
112-
if (!subscriptionResult.ok) {
113-
return false
114-
}
115-
116-
let subscription = subscriptionResult.data
117-
if (subscription) {
118-
let unsubscribeResult = await tryCatch(subscription.unsubscribe())
119-
return unsubscribeResult.ok ? unsubscribeResult.data : false
120-
}
121-
122-
return false
123-
}
124-
12597
function arrayBufferToBase64(buffer: ArrayBuffer): string {
12698
let bytes = new Uint8Array(buffer)
12799
let binary = ""

src/shared/lib/co-list-utils.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
export {
2-
getCoListLength,
32
getLoadedCoListValues,
4-
hasCoListRefById,
53
removeCoListRefsById,
64
removeCoValueRefsByLoadingStates,
75
removeDeletedCoValueRefs,
86
}
97

10-
function getCoListLength(list: unknown): number {
11-
return hasCoListShape(list) ? list.length : 0
12-
}
13-
148
function getLoadedCoListValues<T extends { $isLoaded?: boolean }>(
159
list: unknown,
1610
): Array<T & { $isLoaded: true }> {
@@ -48,15 +42,6 @@ function removeCoValueRefsByLoadingStates(
4842
}
4943
}
5044

51-
function hasCoListRefById(list: unknown, id: string): boolean {
52-
if (!hasCoListShape(list)) return false
53-
let listAny = list as unknown as Array<{ $jazz?: { id?: string } } | null>
54-
for (let item of listAny) {
55-
if (item?.$jazz?.id === id) return true
56-
}
57-
return false
58-
}
59-
6045
function removeCoListRefsById(list: unknown, id: string): void {
6146
if (!hasMutableCoListShape(list)) return
6247
let listAny = list as unknown as Array<{ $jazz?: { id?: string } } | null>

src/shared/lib/viewport-utils.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,7 @@
1-
import { useEffect, useState } from "react"
2-
3-
export { calculateEagerLoadCount, useVisualViewportHeight }
1+
export { calculateEagerLoadCount }
42

53
function calculateEagerLoadCount(): number {
64
if (typeof window === "undefined") return 6
75

86
return Math.ceil(window.innerHeight / 96)
97
}
10-
11-
function useVisualViewportHeight(): number {
12-
let [height, setHeight] = useState(() =>
13-
typeof window !== "undefined" && window.visualViewport
14-
? window.visualViewport.height
15-
: typeof window !== "undefined"
16-
? window.innerHeight
17-
: 0,
18-
)
19-
20-
useEffect(() => {
21-
if (typeof window === "undefined" || !window.visualViewport) return
22-
23-
let viewport = window.visualViewport
24-
25-
function handleResize() {
26-
setHeight(viewport.height)
27-
}
28-
29-
viewport.addEventListener("resize", handleResize)
30-
return () => viewport.removeEventListener("resize", handleResize)
31-
}, [])
32-
33-
return height
34-
}

0 commit comments

Comments
 (0)