Skip to content

Commit 969b8bd

Browse files
RRRyomanakaterm
andauthored
Message UI (#589)
# PRの概要 チャット画面の軽微な修正 ## 具体的な変更内容 各メッセージの3点バーをメッセージの横に配置 メッセージ幅を画面の70%以内に制限 アルファベットのみの文でも文字が画面オーバーしないようにword-breakをbreak-allに変更 ## 影響範囲 RoomWindowを使う範囲 ## 動作要件 ## 補足 ## レビューリクエストを出す前にチェック! - [☑️ ] 改めてセルフレビューしたか - [☑️ ] 手動での動作検証を行ったか - [☑️ ] server の機能追加ならば、テストを書いたか - 理由: 書いた | server の機能追加ではない - [ ☑️] 間違った使い方が存在するならば、それのドキュメントをコメントで書いたか - 理由: 書いた | 間違った使い方は存在しない - [ ☑️] わかりやすいPRになっているか <!-- レビューリクエスト後は、Slackでもメンションしてお願いすることを推奨します。 --> --------- Co-authored-by: naka-12 <[email protected]>
1 parent 8ac6171 commit 969b8bd

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

web/api/user.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ export function useAll(): Hook<UserWithCoursesAndSubjects[]> {
2424
}
2525
export function useRecommended(): UseHook<UserWithCoursesAndSubjects[]> {
2626
const url = endpoints.recommendedUsers;
27-
return useAuthorizedData<UserWithCoursesAndSubjects[]>(url);
27+
return useAuthorizedData<UserWithCoursesAndSubjects[]>(
28+
url,
29+
z.array(UserWithCoursesAndSubjectsSchema),
30+
);
2831
}
2932
export function useMatched(): Hook<UserWithCoursesAndSubjects[]> {
3033
return useCustomizedSWR("users::matched", matched, UserListSchema);

web/components/chat/RoomWindow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,11 @@ export function RoomWindow(props: Props) {
215215
</div>
216216
) : (
217217
<div
218-
className={`rounded-xl p-2 shadow ${
218+
className={`rounded-xl p-2 flex max-w-[70vw] shadow ${
219219
m.creator === myId ? "bg-secondary" : "bg-white"
220220
}`}
221221
>
222-
<p className="whitespace-pre-wrap break-words">
222+
<p className="whitespace-pre-wrap break-all">
223223
{m.content}
224224
</p>
225225
{m.creator === myId && (

web/hooks/useData.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,24 @@ export default function useData<T>(url: string) {
3434
return { data, isLoading, error, reload };
3535
}
3636

37-
async function safeReadData<T>(url: string): Promise<Result<T>> {
37+
async function safeReadData<T>(
38+
url: string,
39+
schema: Zod.Schema<T>,
40+
): Promise<Result<T>> {
3841
try {
3942
const res = await credFetch("GET", url);
40-
const result = await res.json();
41-
// TODO: zod
43+
const data = await res.json();
44+
const result = schema.parse(data);
4245
return Ok(result);
4346
} catch (e) {
47+
console.error(`
48+
safeReadData: Schema Parse Error | in incoming data | Error: ${e}`);
4449
return Err(e);
4550
}
4651
}
4752

4853
// TODO: refactor this to look better.
49-
export function useAuthorizedData<T>(url: string) {
54+
export function useAuthorizedData<T>(url: string, schema: Zod.Schema<T>) {
5055
const [data, setData] = useState<T | null>(null);
5156
const [loading, setLoading] = useState<boolean>(false);
5257
const [error, setError] = useState<Error | null>(null);
@@ -55,7 +60,7 @@ export function useAuthorizedData<T>(url: string) {
5560
setLoading(true);
5661
setError(null);
5762

58-
const result = await safeReadData<T>(url);
63+
const result = await safeReadData<T>(url, schema);
5964
if (result.ok) {
6065
setData(result.value);
6166
setLoading(false);
@@ -64,7 +69,7 @@ export function useAuthorizedData<T>(url: string) {
6469
setError(result.error as Error);
6570
setData(null);
6671
setLoading(false);
67-
}, [url]);
72+
}, [url, schema]);
6873

6974
useEffect(() => {
7075
reload();

0 commit comments

Comments
 (0)