mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 07:55:52 +01:00
♻️ Refactor icon picker (#724)
This commit is contained in:
14
src/hooks/icons/useGetDashboardIcons.tsx
Normal file
14
src/hooks/icons/useGetDashboardIcons.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { NormalizedIconRepositoryResult } from '../../tools/server/images/abstract-icons-repository';
|
||||
|
||||
export const useGetDashboardIcons = () =>
|
||||
useQuery({
|
||||
queryKey: ['repository-icons'],
|
||||
queryFn: async () => {
|
||||
const response = await fetch('/api/icons/');
|
||||
const data = await response.json();
|
||||
return data as NormalizedIconRepositoryResult[];
|
||||
},
|
||||
refetchOnMount: false,
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
@@ -1,27 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { IconSelectorItem } from '../types/iconSelector/iconSelectorItem';
|
||||
|
||||
export const useRepositoryIconsQuery = <TRepositoryIcon extends object>({
|
||||
url,
|
||||
converter,
|
||||
}: {
|
||||
url: string;
|
||||
converter: (value: TRepositoryIcon) => IconSelectorItem;
|
||||
}) =>
|
||||
useQuery({
|
||||
queryKey: ['repository-icons', { url }],
|
||||
queryFn: async () => fetchRepositoryIcons<TRepositoryIcon>(url),
|
||||
select(data) {
|
||||
return data.map((x) => converter(x));
|
||||
},
|
||||
refetchOnWindowFocus: false,
|
||||
});
|
||||
|
||||
const fetchRepositoryIcons = async <TRepositoryIcon extends object>(
|
||||
url: string
|
||||
): Promise<TRepositoryIcon[]> => {
|
||||
const response = await fetch(
|
||||
'https://api.github.com/repos/walkxcode/Dashboard-Icons/contents/png'
|
||||
);
|
||||
return response.json();
|
||||
};
|
||||
Reference in New Issue
Block a user