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

Update dependency react-router-dom to v7 #1830

Merged
merged 4 commits into from
Nov 23, 2024
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
74 changes: 42 additions & 32 deletions web/package-lock.json

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

2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"react": "18.3.1",
"react-dom": "18.3.1",
"react-error-boundary": "4.1.2",
"react-router-dom": "6.28.0",
"react-router": "7.0.1",
"tailwind-merge": "2.5.4",
"tailwindcss": "3.4.15",
"tailwindcss-animate": "1.0.7",
Expand Down
23 changes: 11 additions & 12 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {
RouterProvider,
createBrowserRouter,
defer,
redirect,
useRouteError
} from 'react-router-dom'
} from 'react-router'

import EmailList from 'pages/EmailList'
import EmailRawView from 'pages/EmailRawView'
Expand Down Expand Up @@ -40,11 +39,11 @@ const router = createBrowserRouter([
errorElement: <ErrorBoundary />,
loader: ({ params }) => {
if (!params.threadID) return redirect('/inbox')
return defer({
return {
type: 'thread',
threadID: params.threadID,
thread: getThread(params.threadID)
})
}
}
},
{
Expand All @@ -53,11 +52,11 @@ const router = createBrowserRouter([
errorElement: <ErrorBoundary />,
loader: ({ params }) => {
if (!params.messageID) return redirect('/inbox')
return defer({
return {
type: 'email',
messageID: params.messageID,
email: getEmail(params.messageID)
})
}
}
}
]
Expand All @@ -76,10 +75,10 @@ const router = createBrowserRouter([
element: <EmailView />,
loader: ({ params }) => {
if (!params.messageID) return null
return defer({
return {
messageID: params.messageID,
email: getEmail(params.messageID)
})
}
}
}
]
Expand All @@ -98,10 +97,10 @@ const router = createBrowserRouter([
element: <EmailView />,
loader: ({ params }) => {
if (!params.messageID) return redirect('/sent')
return defer({
return {
messageID: params.messageID,
email: getEmail(params.messageID)
})
}
}
}
]
Expand All @@ -114,10 +113,10 @@ const router = createBrowserRouter([
errorElement: <ErrorBoundary />,
loader: ({ params }) => {
if (!params.messageID) return redirect('/inbox')
return defer({
return {
messageID: params.messageID,
raw: getEmailRaw(params.messageID)
})
}
}
}
])
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PaperAirplaneIcon
} from '@heroicons/react/24/outline'
import { ReactElement, forwardRef, useEffect, useState } from 'react'
import { NavLink } from 'react-router-dom'
import { NavLink } from 'react-router'

import { getInfo } from 'services/info'

Expand Down
22 changes: 14 additions & 8 deletions web/src/components/emails/EmailTableRow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CheckIcon } from '@heroicons/react/20/solid'
import { useContext } from 'react'
import { useNavigate } from 'react-router-dom'
import { useNavigate } from 'react-router'

import EmailName from 'components/emails/EmailName'

Expand Down Expand Up @@ -33,20 +33,20 @@ export default function EmailTableRow(props: EmailTableRowProps) {
})
}

const openEmail = () => {
const openEmail = async () => {
if (email.type === 'draft') {
if (email.threadID) {
navigate(`/inbox/thread/${email.threadID}`)
await navigate(`/inbox/thread/${email.threadID}`)
return
}
void openDraftEmail(email.messageID)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
} else if (email.type === 'inbox' || email.type === 'sent') {
if (email.threadID) {
navigate(`/inbox/thread/${email.threadID}`)
await navigate(`/inbox/thread/${email.threadID}`)
return
}
navigate(`/inbox/${email.messageID}`)
await navigate(`/inbox/${email.messageID}`)
}
}

Expand Down Expand Up @@ -79,7 +79,9 @@ export default function EmailTableRow(props: EmailTableRowProps) {
backgroundClassName +
unreadClassName
}
onClick={openEmail}
onClick={() => {
void openEmail()
}}
>
<span title={email.from.length > 0 ? email.from[0] : ''}>
<EmailName emails={email.from} />
Expand All @@ -91,7 +93,9 @@ export default function EmailTableRow(props: EmailTableRowProps) {
backgroundClassName +
unreadClassName
}
onClick={openEmail}
onClick={() => {
void openEmail()
}}
>
{email.subject}
</div>
Expand All @@ -101,7 +105,9 @@ export default function EmailTableRow(props: EmailTableRowProps) {
backgroundClassName +
(email.unread ? ' md:font-bold' : ' md:dark:font-light')
}
onClick={openEmail}
onClick={() => {
void openEmail()
}}
>
{formatDate(
email.timeReceived ?? email.timeUpdated ?? email.timeSent ?? '',
Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/EmailRawView.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react'
import { Await, useLoaderData } from 'react-router-dom'
import { Await, useLoaderData } from 'react-router'

import { Toaster } from '@ui/toaster'
import { toast } from '@ui/use-toast'

import { reparseEmail } from 'services/emails'

export default function EmailRawView() {
const data = useLoaderData() as { messageID: string; raw: string }
const data: { messageID: string; raw: string } = useLoaderData()

const [isRequesting, setIsRequesting] = React.useState(false)

Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/EmailRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This is the root component for inbox, draft, and sent pages.
*/
import { useContext, useEffect, useState } from 'react'
import { Outlet, useOutletContext } from 'react-router-dom'
import { Outlet, useOutletContext } from 'react-router'

import DraftEmailsTabs from 'components/emails/DraftEmailsTabs'
import FullScreenContent from 'components/emails/FullScreenContent'
Expand Down
14 changes: 9 additions & 5 deletions web/src/pages/EmailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@heroicons/react/24/outline'
import React, { useContext, useEffect, useRef, useState } from 'react'
import { ErrorBoundary } from 'react-error-boundary'
import { Await, useLoaderData, useNavigate } from 'react-router-dom'
import { Await, useLoaderData, useNavigate } from 'react-router'

import { toast } from '@ui/use-toast'

Expand Down Expand Up @@ -37,9 +37,9 @@ import { parseEmailContent, parseEmailName } from 'utils/emails'
import { formatDate } from 'utils/time'

export default function EmailView() {
const data = useLoaderData() as
const data:
| { type: 'email'; messageID: string; email: Email }
| { type: 'thread'; threadID: string; thread: Thread }
| { type: 'thread'; threadID: string; thread: Thread } = useLoaderData()

const navigate = useNavigate()

Expand Down Expand Up @@ -154,7 +154,7 @@ export default function EmailView() {
} else {
await trashEmail(data.messageID)
}
navigate(-1)
await navigate(-1)
}

const handleRead = async () => {
Expand Down Expand Up @@ -189,13 +189,17 @@ export default function EmailView() {
}
}

const handleBack = async () => {
await navigate(-1)
}

return (
<>
<div className="px-2 md:px-0 mb-4 preflight">
<EmailMenuBar
emailIDs={'messageID' in data ? [data.messageID] : []}
handleBack={() => {
navigate(-1)
void handleBack()
}}
showOperations={true}
handleDelete={() => {
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Bars3Icon } from '@heroicons/react/24/outline'
import { useReducer, useRef, useState } from 'react'
import { Outlet } from 'react-router-dom'
import { Outlet } from 'react-router'

import { Toaster } from '@ui/toaster'

Expand Down
Loading