-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pompurin404
committed
Aug 1, 2024
1 parent
5e99800
commit b43f078
Showing
6 changed files
with
152 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import useSWR from 'swr' | ||
import { | ||
getProfileConfig, | ||
addProfileItem as add, | ||
removeProfileItem as remove | ||
} from '@renderer/utils/ipc' | ||
import { useEffect } from 'react' | ||
|
||
interface RetuenType { | ||
profileConfig: IProfileConfig | undefined | ||
mutateProfileConfig: () => void | ||
addProfileItem: (item: Partial<IProfileItem>) => Promise<void> | ||
removeProfileItem: (id: string) => void | ||
} | ||
|
||
export const useProfileConfig = (): RetuenType => { | ||
const { data: profileConfig, mutate: mutateProfileConfig } = useSWR('getProfileConfig', () => | ||
getProfileConfig() | ||
) | ||
|
||
const addProfileItem = async (item: Partial<IProfileItem>): Promise<void> => { | ||
await add(item) | ||
mutateProfileConfig() | ||
window.electron.ipcRenderer.send('profileConfigUpdated') | ||
} | ||
|
||
const removeProfileItem = async (id: string): Promise<void> => { | ||
await remove(id) | ||
mutateProfileConfig() | ||
window.electron.ipcRenderer.send('profileConfigUpdated') | ||
} | ||
|
||
useEffect(() => { | ||
window.electron.ipcRenderer.on('profileConfigUpdated', () => { | ||
mutateProfileConfig() | ||
}) | ||
return (): void => { | ||
window.electron.ipcRenderer.removeAllListeners('profileConfigUpdated') | ||
} | ||
}, []) | ||
|
||
return { | ||
profileConfig, | ||
mutateProfileConfig, | ||
addProfileItem, | ||
removeProfileItem | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters