Skip to content

Commit 5f3b7f5

Browse files
committed
feat(nav): add API Reference link to navigation menu
refactor(AuthGuard): remove redundant error handling refactor(ChatRoom): simplify message sending logic and update message list props refactor(PlanetCreator): streamline form submission and reset logic refactor(PlanetsList): update planet props typing for better clarity
1 parent 5ecfa8d commit 5f3b7f5

5 files changed

Lines changed: 14 additions & 63 deletions

File tree

apps/web/src/App.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ function App() {
1818
<div className="nav-menu">
1919
<a href="#planets">Planets</a>
2020
<a href="#chat">Chat</a>
21+
<a href={import.meta.env.VITE_API_URL} target="_blank" rel="noopener noreferrer">
22+
API Reference
23+
</a>
2124
</div>
2225

2326
<div className="nav-actions">

apps/web/src/components/AuthGuard.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ export function AuthGuard({ children }: AuthGuardProps) {
2323
})
2424
setUser(userData)
2525
}
26-
catch (err) {
27-
if (!controller.signal.aborted) {
28-
console.error('Auth check failed:', err)
29-
// Don't show error, just show login
30-
}
31-
}
3226
finally {
3327
if (!controller.signal.aborted) {
3428
setIsLoading(false)

apps/web/src/components/ChatRoom.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import { WarningMessage } from './ui/WarningMessage'
88

99
const DEFAULT_ROOM = 'default'
1010

11-
interface ChatMessage {
12-
message: string
13-
}
14-
1511
export function ChatRoom() {
1612
const [inputValue, setInputValue] = useState('')
1713

@@ -24,9 +20,6 @@ export function ChatRoom() {
2420

2521
const sendMessageMutation = useMutation(
2622
chatServiceOrpc.room.publish.mutationOptions({
27-
onSuccess: () => {
28-
setInputValue('')
29-
},
3023
onError(error) {
3124
console.error('Failed to send message:', error)
3225
// eslint-disable-next-line no-alert
@@ -41,10 +34,12 @@ export function ChatRoom() {
4134
if (!inputValue.trim())
4235
return
4336

44-
sendMessageMutation.mutate({
37+
await sendMessageMutation.mutateAsync({
4538
room: DEFAULT_ROOM,
4639
message: inputValue,
4740
})
41+
42+
setInputValue('')
4843
}
4944

5045
return (
@@ -89,11 +84,7 @@ export function ChatRoom() {
8984
)
9085
}
9186

92-
interface MessageListProps {
93-
messages: ChatMessage[]
94-
}
95-
96-
function MessageList({ messages }: MessageListProps) {
87+
function MessageList({ messages }: { messages: Array<{ message: string }> }) {
9788
return (
9889
<ul className="chat-messages">
9990
{messages.length === 0 && (

apps/web/src/components/PlanetCreator.tsx

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,17 @@
11
import { useMutation, useQueryClient } from '@tanstack/react-query'
2-
import { useState } from 'react'
32
import { planetServiceOrpc } from '../lib/service-planet'
43
import { Card } from './ui/Card'
54
import { InfoMessage } from './ui/InfoMessage'
65

7-
interface PlanetFormData {
8-
name: string
9-
description?: string
10-
image?: File
11-
}
12-
136
export function PlanetCreator() {
147
const queryClient = useQueryClient()
15-
const [formData, setFormData] = useState<PlanetFormData>({
16-
name: '',
17-
description: '',
18-
})
198

209
const createPlanetMutation = useMutation(
2110
planetServiceOrpc.planet.create.mutationOptions({
2211
onSuccess() {
23-
// Invalidate and refetch planets list
2412
queryClient.invalidateQueries({
2513
queryKey: planetServiceOrpc.planet.key(),
2614
})
27-
28-
// Reset form
29-
setFormData({ name: '', description: '' })
30-
31-
// Clear file input manually
32-
const fileInput = document.querySelector<HTMLInputElement>('input[type="file"]')
33-
if (fileInput) {
34-
fileInput.value = ''
35-
}
3615
},
3716
onError(error) {
3817
console.error('Failed to create planet:', error)
@@ -42,19 +21,21 @@ export function PlanetCreator() {
4221
}),
4322
)
4423

45-
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
24+
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
4625
e.preventDefault()
4726
const form = new FormData(e.currentTarget)
4827

4928
const name = form.get('name') as string
5029
const description = (form.get('description') as string | null) ?? undefined
5130
const image = form.get('image') as File
5231

53-
createPlanetMutation.mutate({
32+
await createPlanetMutation.mutateAsync({
5433
name,
5534
description,
5635
image: image.size > 0 ? image : undefined,
5736
})
37+
38+
e.currentTarget.reset()
5839
}
5940

6041
return (
@@ -71,8 +52,6 @@ export function PlanetCreator() {
7152
name="name"
7253
required
7354
placeholder="Enter planet name..."
74-
value={formData.name}
75-
onChange={e => setFormData({ ...formData, name: e.target.value })}
7655
/>
7756
</label>
7857

@@ -81,8 +60,6 @@ export function PlanetCreator() {
8160
<textarea
8261
name="description"
8362
placeholder="Describe this planet (optional)..."
84-
value={formData.description}
85-
onChange={e => setFormData({ ...formData, description: e.target.value })}
8663
/>
8764
</label>
8865

apps/web/src/components/PlanetsList.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1+
import type { PlanetServiceOutputs } from '../lib/service-planet'
12
import { useSuspenseInfiniteQuery } from '@tanstack/react-query'
23
import { planetServiceOrpc } from '../lib/service-planet'
34
import { ErrorMessage } from './ui/ErrorMessage'
45
import { InfoMessage } from './ui/InfoMessage'
56
import { InterfaceWindow } from './ui/InterfaceWindow'
67

7-
interface Planet {
8-
id: number
9-
name: string
10-
description?: string
11-
imageUrl?: string
12-
}
13-
148
export function PlanetsList() {
159
const {
1610
data,
@@ -66,11 +60,7 @@ export function PlanetsList() {
6660
)
6761
}
6862

69-
interface PlanetsTableProps {
70-
planets: Planet[]
71-
}
72-
73-
function PlanetsTable({ planets }: PlanetsTableProps) {
63+
function PlanetsTable({ planets }: { planets: PlanetServiceOutputs['planet']['list'] }) {
7464
return (
7565
<table>
7666
<thead>
@@ -90,11 +80,7 @@ function PlanetsTable({ planets }: PlanetsTableProps) {
9080
)
9181
}
9282

93-
interface PlanetRowProps {
94-
planet: Planet
95-
}
96-
97-
function PlanetRow({ planet }: PlanetRowProps) {
83+
function PlanetRow({ planet }: { planet: PlanetServiceOutputs['planet']['list'][0] }) {
9884
return (
9985
<tr>
10086
<td>

0 commit comments

Comments
 (0)