refactor: clean up code structure and improve error handling in media controllers

This commit is contained in:
MythEclipse
2026-05-16 23:11:46 +07:00
parent 9b211f05cf
commit 7dedac2094
6 changed files with 44 additions and 23 deletions
+5 -1
View File
@@ -18,11 +18,15 @@ export function useMessages() {
const [error, setError] = useState<string | null>(null);
const fetchMessages = useCallback(async (channelId?: string) => {
if (!channelId) {
setMessages([]);
return [];
}
setLoading(true);
setError(null);
try {
const params = new URLSearchParams({ limit: "80" });
if (channelId) params.set("channel", channelId);
params.set("channel", channelId);
const result = await listMessages(params);
setMessages(result.data);
return result.data;