Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move dashboard screen business logic to custom hooks #540

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 2 additions & 29 deletions client/components/dashboard/QuickActionSection.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,11 @@
import { RStack } from '@packrat/ui';
import QuickActionButton from './QuickActionButton';
import useTheme from '../../hooks/useTheme';
import { useRouter } from 'expo-router';
import useCustomStyles from '~/hooks/useCustomStyles';
import { useQuickActions } from '~/hooks/dashboard';

const QuickActionsSection = () => {
const router = useRouter();
const styles = useCustomStyles(loadStyles);

const quickActionData = [
{
action: 'createPack',
iconName: 'backpack',
text: 'Create a Pack',
},
{
action: 'createTrip',
iconName: 'navigation',
text: 'Create a Trip',
},
];

/**
* Handles the selection of an action.
*
* @param {string} action - The selected action.
*/
const handleActionSelect = (action) => {
if (action === 'createPack') {
router.push('/pack/create');
} else if (action === 'createTrip') {
router.push('/trip/create');
}
};
const { handleActionSelect, quickActionData } = useQuickActions();

return (
<RStack style={{ flexDirection: 'row', ...styles.section }}>
Expand Down
1 change: 1 addition & 0 deletions client/hooks/dashboard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useQuickActions } from './useQuickActions'
33 changes: 33 additions & 0 deletions client/hooks/dashboard/useQuickActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useRouter } from "expo-router";

const quickActionData = [
{
action: 'createPack',
iconName: 'backpack',
text: 'Create a Pack',
},
{
action: 'createTrip',
iconName: 'navigation',
text: 'Create a Trip',
},
];

export const useQuickActions = () => {
const router = useRouter();

/**
* Handles the selection of an action.
*
* @param {string} action - The selected action.
*/
const handleActionSelect = (action) => {
if (action === 'createPack') {
router.push('/pack/create');
} else if (action === 'createTrip') {
router.push('/trip/create');
}
};

return { quickActionData, handleActionSelect }
}
Loading