-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor room title display and update tests
- Loading branch information
1 parent
acde1e3
commit e789c07
Showing
2 changed files
with
21 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,45 @@ | ||
import { FC } from "hono/dist/types/jsx"; | ||
import {Rooms} from "../schema"; | ||
import { Rooms } from "../schema"; | ||
|
||
type Props = { | ||
rooms: (typeof Rooms.$inferSelect)[]; | ||
}; | ||
|
||
const TITLE_LENGTH = 20; | ||
const formatTitle = (room: typeof Rooms.$inferSelect) => { | ||
if (!room.roomTitle) { | ||
return room.roomId; | ||
} | ||
return room.roomTitle.length > TITLE_LENGTH | ||
? `${room.roomTitle.slice(0, TITLE_LENGTH)}...` | ||
: room.roomTitle; | ||
}; | ||
|
||
export const RoomList: FC<{ props: Props }> = ({ props }) => ( | ||
<> | ||
<h1>Chat Rooms.</h1> | ||
<a href={"/chats/new"}>New</a> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>ID</th> | ||
<th>Title</th> | ||
<th>Created</th> | ||
<th>Updated</th> | ||
<th>Link</th> | ||
</tr> | ||
</thead> | ||
{props.rooms.map((room) => ( | ||
<tbody> | ||
<tbody> | ||
{props.rooms.map((room) => ( | ||
<tr> | ||
<td>{room.roomTitle}</td> | ||
<td>{formatTitle(room)}</td> | ||
<td>{room.roomCreated}</td> | ||
<td>{room.roomUpdated}</td> | ||
<td> | ||
<a href={`/chats/${room.roomId}`}>Detail</a> | ||
</td> | ||
</tr> | ||
</tbody> | ||
))} | ||
))} | ||
</tbody> | ||
</table> | ||
</> | ||
); |