generated from Labyricorn/labyricorn-project-template
CI / frontend-quality (push) Canceled after 0s
- All 'voicebox'/'Voicebox'/'VOICEBOX' strings replaced with 'talkbox'/'TalkBox'/'TALKBOX' - Port changed from 17493 to 17494 (avoids conflict with upstream VoiceBox) - MCP tool namespace: voicebox.* -> talkbox.* - App bundle ID: sh.voicebox.app -> com.talkbox.app - Binary names: voicebox-server -> talkbox-server, voicebox-mcp -> talkbox-mcp - Docker user/group: voicebox -> talkbox - Database: voicebox.db -> talkbox.db - Env vars: VOICEBOX_* -> TALKBOX_* - Asset files renamed: voicebox-logo.* -> talkbox-logo.*, etc. - External binaries in tauri.conf.json updated to talkbox-server/talkbox-mcp
182 lines
4.8 KiB
TypeScript
182 lines
4.8 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
import { apiClient } from '@/lib/api/client';
|
|
import type { VoiceProfileCreate } from '@/lib/api/types';
|
|
import { usePlatform } from '@/platform/PlatformContext';
|
|
|
|
export function useProfiles() {
|
|
return useQuery({
|
|
queryKey: ['profiles'],
|
|
queryFn: () => apiClient.listProfiles(),
|
|
});
|
|
}
|
|
|
|
export function useProfile(profileId: string) {
|
|
return useQuery({
|
|
queryKey: ['profiles', profileId],
|
|
queryFn: () => apiClient.getProfile(profileId),
|
|
enabled: !!profileId,
|
|
});
|
|
}
|
|
|
|
export function useCreateProfile() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (data: VoiceProfileCreate) => apiClient.createProfile(data),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['profiles'] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useUpdateProfile() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({ profileId, data }: { profileId: string; data: VoiceProfileCreate }) =>
|
|
apiClient.updateProfile(profileId, data),
|
|
onSuccess: (_, variables) => {
|
|
queryClient.invalidateQueries({ queryKey: ['profiles'] });
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['profiles', variables.profileId],
|
|
});
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteProfile() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (profileId: string) => apiClient.deleteProfile(profileId),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['profiles'] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useProfileSamples(profileId: string) {
|
|
return useQuery({
|
|
queryKey: ['profiles', profileId, 'samples'],
|
|
queryFn: () => apiClient.listProfileSamples(profileId),
|
|
enabled: !!profileId,
|
|
});
|
|
}
|
|
|
|
export function useAddSample() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({
|
|
profileId,
|
|
file,
|
|
referenceText,
|
|
}: {
|
|
profileId: string;
|
|
file: File;
|
|
referenceText: string;
|
|
}) => apiClient.addProfileSample(profileId, file, referenceText),
|
|
onSuccess: (_, variables) => {
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['profiles', variables.profileId, 'samples'],
|
|
});
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['profiles', variables.profileId],
|
|
});
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteSample() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (sampleId: string) => apiClient.deleteProfileSample(sampleId),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['profiles'] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useUpdateSample() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({ sampleId, referenceText }: { sampleId: string; referenceText: string }) =>
|
|
apiClient.updateProfileSample(sampleId, referenceText),
|
|
onSuccess: (data) => {
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['profiles', data.profile_id, 'samples'],
|
|
});
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['profiles', data.profile_id],
|
|
});
|
|
queryClient.invalidateQueries({ queryKey: ['profiles'] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useExportProfile() {
|
|
const platform = usePlatform();
|
|
|
|
return useMutation({
|
|
mutationFn: async (profileId: string) => {
|
|
const blob = await apiClient.exportProfile(profileId);
|
|
|
|
// Get profile name for filename
|
|
const profile = await apiClient.getProfile(profileId);
|
|
const safeName = profile.name.replace(/[^a-z0-9]/gi, '-').toLowerCase();
|
|
const filename = `profile-${safeName}.talkbox.zip`;
|
|
|
|
await platform.filesystem.saveFile(filename, blob, [
|
|
{
|
|
name: 'TalkBox Profile',
|
|
extensions: ['zip'],
|
|
},
|
|
]);
|
|
|
|
return blob;
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useImportProfile() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (file: File) => apiClient.importProfile(file),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['profiles'] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useUploadAvatar() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({ profileId, file }: { profileId: string; file: File }) =>
|
|
apiClient.uploadAvatar(profileId, file),
|
|
onSuccess: (_, variables) => {
|
|
queryClient.invalidateQueries({ queryKey: ['profiles'] });
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['profiles', variables.profileId],
|
|
});
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteAvatar() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (profileId: string) => apiClient.deleteAvatar(profileId),
|
|
onSuccess: (_, profileId) => {
|
|
queryClient.invalidateQueries({ queryKey: ['profiles'] });
|
|
queryClient.invalidateQueries({
|
|
queryKey: ['profiles', profileId],
|
|
});
|
|
},
|
|
});
|
|
}
|