Files
new-phone-who-dis/phone/src/os/notifications/hooks/useQuickAccess.tsx
T
J Francisco Rader 4acb214ec9 Task/improve hardcoded styles and types (#107)
* Add working notifications with only twitter for now

* feat(notification-bar): I didnt copy from NP

* feat(notifications): Collapse when no more notifications after closing one

* Improve overall messages styling code

* Improve Routing performance

* improve use keyboard hook

* Remove unused returns

* Button hover color :)

* Button hover color :) x2

* Added hover style to containedPrimary msg btn

* Replace custom components for custom theme providers for Messages and Contacts apps

* Improve createAppThemeProvider

* Improve createAppThemeProvider

* Final housekeeping for messages styles

* Change placeholder to label in Contacts app text fields

* Fix alerts style with navigation and fix calc copy alerrt

* Split Phone code for snackbar

* Add more options and style Context Menu

* Enable Sellout theme provider and make it work with light themes
2021-02-21 12:41:25 -05:00

53 lines
1.3 KiB
TypeScript

import { useCallback, useEffect } from 'react';
import { matchPath, useHistory } from 'react-router-dom';
import { atom, useRecoilState } from 'recoil';
import { IAppConfig } from '../../apps/config/apps';
import { useApps } from '../../apps/hooks/useApps';
const state = {
recentlyUsed: atom({
key: 'recentlyUsed',
default: [],
}),
};
const MAX_QUICK_ACCESS_ITEMS = 5;
const unshiftApp = (arr: IAppConfig[], app) => {
const idx = arr.findIndex((a) => a.id === app.id);
if (idx !== -1) {
arr.splice(idx, 1);
}
arr.unshift(app);
return arr;
};
export const useQuickAccess = () => {
const history = useHistory();
const { apps, getApp } = useApps();
const [recentlyUsed, setRecentlyUsed] = useRecoilState<IAppConfig[]>(
state.recentlyUsed
);
useEffect(() => {
setRecentlyUsed([getApp('SETTINGS')]);
}, [getApp, setRecentlyUsed]);
const listener = useCallback(
(location) => {
const newState = [...recentlyUsed];
apps.forEach((app) => {
if (matchPath(location.pathname, { path: app.path, exact: true })) {
unshiftApp(newState, app);
}
});
setRecentlyUsed(newState.slice(0, MAX_QUICK_ACCESS_ITEMS));
},
[apps, recentlyUsed, setRecentlyUsed]
);
history.listen(listener);
return recentlyUsed;
};