databag/app/mobile/src/session/useSession.hook.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-09-16 20:06:52 +00:00
import { useState, useEffect, useContext } from 'react';
import { useWindowDimensions } from 'react-native';
import { useNavigate } from 'react-router-dom';
2022-09-17 07:22:12 +00:00
import config from 'constants/Config';
2022-09-16 20:06:52 +00:00
export function useSession() {
const [state, setState] = useState({
2022-09-17 07:22:12 +00:00
tabbled: null,
subWidth: '33%',
baseWidth: '33%',
2022-09-19 05:42:27 +00:00
cardId: null,
converstaionId: null,
2022-09-16 20:06:52 +00:00
});
2022-09-17 07:22:12 +00:00
const dimensions = useWindowDimensions();
2022-09-16 20:06:52 +00:00
const navigate = useNavigate();
const updateState = (value) => {
setState((s) => ({ ...s, ...value }));
}
2022-09-17 07:22:12 +00:00
useEffect(() => {
2022-09-19 00:04:17 +00:00
if (dimensions.width > config.tabbedWidth) {
const width = Math.floor((dimensions.width * 33) / 100);
if (width > 500) {
updateStatus({ tabbed: false, baseWidth: 550, subWidth: 500 });
2022-09-19 00:04:17 +00:00
}
else {
updateState({ tabbed: false, baseWidth: width + 50, subWidth: width });
2022-09-19 00:04:17 +00:00
}
}
else {
updateState({ tabbed: true });
}
2022-09-17 07:22:12 +00:00
}, [dimensions]);
2022-09-16 20:06:52 +00:00
const actions = {
setCardId: (cardId) => {
updateState({ cardId });
}
2022-09-16 20:06:52 +00:00
};
return { state, actions };
}