Files
wanderer/assets/js/hooks/Mapper/components/mapRootContent/hooks/useCharacterActivityHandlers.ts
2025-11-25 01:52:06 +00:00

66 lines
1.7 KiB
TypeScript

import { useCallback } from 'react';
import { useMapRootState } from '@/hooks/Mapper/mapRootProvider';
import { OutCommand } from '@/hooks/Mapper/types/mapHandlers';
import { ActivitySummary } from '@/hooks/Mapper/types';
/**
* Hook for character activity related handlers
*/
export const useCharacterActivityHandlers = () => {
const { outCommand, update } = useMapRootState();
/**
* Handle hiding the character activity dialog
*/
const handleHideCharacterActivity = useCallback(() => {
// Update local state to hide the dialog
update(state => ({
...state,
showCharacterActivity: false,
}));
}, [update]);
/**
* Handle showing the character activity dialog
*/
const handleShowActivity = useCallback((days?: number | null) => {
// Update local state to show the dialog
update(state => ({
...state,
showCharacterActivity: true,
}));
// Send the command to the server with optional days parameter
outCommand({
type: OutCommand.showActivity,
data: days !== undefined ? { days } : {},
});
}, [outCommand, update]);
/**
* Handle updating character activity data
*/
const handleUpdateActivity = useCallback(
(activityData: { activity: ActivitySummary[] }) => {
if (!activityData || !activityData.activity) {
console.error('Invalid activity data received:', activityData);
return;
}
// Update local state with the activity data
update(state => ({
...state,
characterActivityData: activityData,
showCharacterActivity: true,
}));
},
[update],
);
return {
handleHideCharacterActivity,
handleShowActivity,
handleUpdateActivity,
};
};