File size: 3,828 Bytes
07bbbbf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
/**
* Library API Module
*
* Handles all library and group management operations.
* Extracted from AppContext for better modularity.
*
* Following best practices:
* - Single responsibility (library operations only)
* - Clean API boundary
* - Reusable across components
*/
import { invoke } from '@tauri-apps/api/core';
import { MdxProfile } from '../types';
/**
* Create a new dictionary group
*/
export const createDictGroup = async (groupName: string): Promise<number> => {
return await invoke('library_create_dict_group', { groupName });
};
/**
* Delete a dictionary group
*/
export const deleteDictGroup = async (groupId: number): Promise<void> => {
await invoke('library_delete_dict_group', { groupId });
};
/**
* Rename a dictionary group
*/
export const renameDictGroup = async (groupId: number, newName: string): Promise<void> => {
await invoke('library_rename_dict_group', { groupId, newName });
};
/**
* Refresh library from disk
*/
export const refreshLibrary = async (): Promise<void> => {
await invoke('library_refresh_library');
};
/**
* Get group for a given group_id
*/
export const getGroup = async (groupId: number): Promise<MdxProfile> => {
return await invoke('library_get_group', { groupId });
};
/**
* Get profile for a given group_id and profile_id
*/
export const getProfile = async (groupId: number, profileId: number): Promise<MdxProfile> => {
return await invoke('library_get_profile', { groupId, profileId });
};
/**
* List all groups
*/
export const listGroups = async (): Promise<MdxProfile[]> => {
return await invoke('library_list_groups');
};
/**
* Update profile disabled status in a group
*/
export const updateProfileDisabledStatus = async (
parentGroupId: number,
profileId: number,
disabled: boolean
): Promise<void> => {
await invoke('library_update_profile_disabled_status', {
parentGroupId,
profileId,
disabled,
});
};
/**
* Adjust profile order within a group
*/
export const adjustProfileOrder = async (
parentGroupId: number,
profileId: number,
newIndex: number
): Promise<void> => {
await invoke('library_adjust_profile_order', {
parentGroupId,
profileId,
newIndex,
});
};
/**
* Adjust group order
*/
export const adjustGroupOrder = async (groupId: number, newIndex: number): Promise<void> => {
await invoke('library_adjust_group_order', { groupId, newIndex });
};
/**
* Open main database with the given profile
*/
export const openMainDatabase = async (profileId: number): Promise<void> => {
await invoke('library_open_main_database', { profileId });
};
/**
* Get current main profile ID
*/
export const getCurrentMainProfileId = async (): Promise<number> => {
return await invoke('library_get_current_main_profile_id');
};
/**
* Get main database profile
*/
export const getMainDbProfile = async (): Promise<MdxProfile | null> => {
return await invoke('library_get_main_db_profile');
};
// Export types from ConvertDBDialog
export type { CollationOptions, ConvertOptions } from '../components/ConvertDBDialog';
/**
* Result of database conversion
*/
export interface ConversionResult {
newMdxPath: string;
newMddPath?: string;
}
/**
* Convert MDX/MDD files to new format
*/
export const convertFile = async (
profileId: number,
collationLocale: string,
removeOldFiles: boolean = true
): Promise<ConversionResult> => {
return await invoke('library_convert_db', { profileId, collationLocale, removeOldFiles });
};
/**
* Create fulltext search index
*/
export const createFtsIndex = async (mdxFilePath: string): Promise<void> => {
await invoke('library_create_fts_index', { mdxFilePath });
};
/**
* Cancel ongoing conversion
*/
export const cancelConversion = async (): Promise<void> => {
await invoke('library_cancel_conversion');
};
|