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

49 lines
1.2 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';
import { AppContext } from 'context/AppContext';
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,
2022-09-19 00:04:17 +00:00
profileWidth: '33%',
cardWidth: '33%',
2022-09-19 05:42:27 +00:00
cardId: null,
converstaionId: null,
contactDrawer: 'profile',
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 app = useContext(AppContext);
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, cardWidth: 550, profileWidth: 500 });
}
else {
updateState({ tabbed: false, cardWidth: width + 50, profileWidth: width });
}
}
else {
updateState({ tabbed: true });
}
2022-09-17 07:22:12 +00:00
}, [dimensions]);
2022-09-16 20:06:52 +00:00
const actions = {
2022-09-19 06:50:57 +00:00
setContactDrawer: (contactDrawer) => {
updateState({ contactDrawer });
},
2022-09-16 20:06:52 +00:00
};
return { state, actions };
}