Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: firestore unexpected error #10

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions apps/web/app/components/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Card, CardBody, CardHeader } from '@nextui-org/react'
import { type ReminderSetting, type User, config } from '@synk-cal/core'
import { type ReminderSetting, type User } from '@synk-cal/core'
import { UserInfo } from '~/components/UserInfo'

import { Button, Input, Select, SelectItem } from '@nextui-org/react'
Expand All @@ -10,26 +10,23 @@ type Props = {
user: User
reminders: readonly ReminderSetting[]
onChange: (reminders: ReminderSetting[]) => void
notifyBeforeOptions?: number[]
className?: string
}

const NOTIFY_BEFORE_OPTIONS = config.REMINDER_MINUTES_BEFORE_OPTIONS.map((value) => {
if (value < 60) {
return { value, unit: 'min' as const, amount: value }
} else if (value < 1440) {
return { value, unit: 'hour' as const, amount: value / 60 }
} else {
return { value, unit: 'day' as const, amount: value / 1440 }
}
})

const unitInJapanese = {
min: '分',
hour: '時間',
day: '日',
} as const

export function ReminderSettings({ user, reminders, onChange, className }: Props) {
export function ReminderSettings({
user,
reminders,
onChange,
notifyBeforeOptions = [5, 10, 15, 30, 60, 120, 180, 360, 720, 1440],
className,
}: Props) {
const addReminder = () => {
const newReminder: ReminderSetting = {
id: crypto.randomUUID(),
Expand Down Expand Up @@ -82,7 +79,15 @@ export function ReminderSettings({ user, reminders, onChange, className }: Props
selectedKeys={[reminder.minutesBefore.toString()]}
className="max-w-[200px]"
onChange={(e) => updateReminder(reminder.id ?? i, Number(e.target.value))}
items={NOTIFY_BEFORE_OPTIONS}
items={notifyBeforeOptions.map((value) => {
if (value < 60) {
return { value, unit: 'min' as const, amount: value }
} else if (value < 1440) {
return { value, unit: 'hour' as const, amount: value / 60 }
} else {
return { value, unit: 'day' as const, amount: value / 1440 }
}
})}
>
{({ unit, amount, value }) => {
const label = `${amount} ${locale === 'ja' ? unitInJapanese[unit] : unit}`
Expand Down
14 changes: 11 additions & 3 deletions apps/web/app/routes/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { type ActionFunctionArgs, type LoaderFunctionArgs, json } from '@remix-run/node'
import { useFetcher, useLoaderData } from '@remix-run/react'
import { ReminderSetting } from '@synk-cal/core'
import { ReminderSetting, config } from '@synk-cal/core'
import { ReminderSettings } from '~/components/Settings'
import { getAuthRepository } from '~/services/getAuthRepository'
import { getReminderSettingsRepository } from '~/services/getReminderSettingsRepository'

const NOTIFY_BEFORE_OPTIONS = config.REMINDER_MINUTES_BEFORE_OPTIONS

export const loader = async ({ request }: LoaderFunctionArgs) => {
const user = await getAuthRepository()?.getUserFromHeader(request.headers)

Expand All @@ -19,6 +21,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
user,
isReminderSettingsEnabled: !!reminderSettingsRepo,
reminders,
notifyBeforeOptions: NOTIFY_BEFORE_OPTIONS,
})
}

Expand Down Expand Up @@ -52,7 +55,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
}

export default function SettingsRoute() {
const { user, reminders, isReminderSettingsEnabled } = useLoaderData<typeof loader>()
const { user, reminders, isReminderSettingsEnabled, notifyBeforeOptions } = useLoaderData<typeof loader>()
const fetcher = useFetcher()

const handleRemindersChange = (newReminders: ReminderSetting[]) => {
Expand All @@ -72,7 +75,12 @@ export default function SettingsRoute() {
) : !isReminderSettingsEnabled ? (
<div>Reminder settings are not enabled.</div>
) : (
<ReminderSettings user={user} reminders={currentReminders} onChange={handleRemindersChange} />
<ReminderSettings
user={user}
reminders={currentReminders}
notifyBeforeOptions={notifyBeforeOptions}
onChange={handleRemindersChange}
/>
)}
</div>
)
Expand Down
7 changes: 6 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"bin": {
"synk-cal": "./bin/server.js"
},
"files": ["bin", "public", "build"],
"files": [
"bin",
"public",
"build"
],
"scripts": {
"build": "remix vite:build",
"dev": "remix vite:dev",
Expand All @@ -26,6 +30,7 @@
"@fullcalendar/daygrid": "^6.1.15",
"@fullcalendar/react": "^6.1.15",
"@fullcalendar/timegrid": "^6.1.15",
"@google-cloud/firestore": "^7.1.0",
"@nextui-org/react": "^2.4.8",
"@remix-run/express": "^2.15.3",
"@remix-run/node": "^2.15.3",
Expand Down
5 changes: 5 additions & 0 deletions apps/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ declare module '@remix-run/node' {
}

export default defineConfig({
build: {
rollupOptions: {
external: ['@google-cloud/firestore'],
},
},
plugins: [
remix({
future: {
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.