Skip to content

Commit 8b61161

Browse files
committed
HOOKS: notification and searchable hooks all done.
1 parent 315c343 commit 8b61161

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useSettingsStore } from '@/app/store/useSettingsStore';
2+
import { audioService } from '@/shared/lib/audio-service';
3+
import { useCallback } from 'react';
4+
5+
export const useNotificationSound = () => {
6+
const { soundEnabled } = useSettingsStore();
7+
8+
const playNotificationSound = useCallback(() => {
9+
if (soundEnabled) {
10+
audioService.play();
11+
}
12+
}, [soundEnabled]);
13+
14+
return { playNotificationSound };
15+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { api } from '@/shared/api/api';
2+
import type { components } from '@/shared/types/api-types';
3+
import { useQuery } from '@tanstack/react-query';
4+
5+
type UserListItem = components['schemas']['SanitizedUserDto'];
6+
type TeamListItem = components['schemas']['TeamDto'];
7+
type ListData = (UserListItem | TeamListItem)[];
8+
9+
export const useSearchableList = (type: 'user' | 'team', searchTerm: string) => {
10+
const queryKey = [`search-${type}s`, searchTerm];
11+
const endpoint = type === 'user' ? '/users' : '/teams';
12+
const isSearchEnabled = searchTerm.length === 0 || searchTerm.length >= 2;
13+
14+
return useQuery({
15+
queryKey,
16+
queryFn: async () => {
17+
const queryParams: Record<string, any> = { page: 1, limit: 100 };
18+
if (searchTerm) {
19+
queryParams.search = searchTerm;
20+
}
21+
const response = await api.get<ListData>(endpoint, {
22+
params: queryParams,
23+
});
24+
return response.data;
25+
},
26+
enabled: isSearchEnabled,
27+
});
28+
};

0 commit comments

Comments
 (0)