mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
Add quick access and improve Apps config
This commit is contained in:
1 parent
6ae60b377c
commit
c149a1f49e
5 files changed
+115
-26
No files matched your search
@@ -1,5 +1,15 @@
|
||||
import React from 'react';
|
||||
import { IconButton } from '@material-ui/core';
|
||||
|
||||
export const NotificationIcon = ({ Icon }) => {
|
||||
return <Icon fontSize='small' />;
|
||||
interface INotificationIcon {
|
||||
icon: JSX.Element;
|
||||
onClick(e: any): void;
|
||||
}
|
||||
|
||||
export const NotificationIcon = ({ icon, onClick }: INotificationIcon) => {
|
||||
return (
|
||||
<IconButton size="small" onClick={onClick}>
|
||||
{icon}
|
||||
</IconButton>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { matchPath, useHistory } from 'react-router-dom';
|
||||
import { atom, useRecoilState } from 'recoil';
|
||||
import { IAppConfig, 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 { allApps, getApp } = useApps();
|
||||
const [recentlyUsed, setRecentlyUsed] = useRecoilState<IAppConfig[]>(
|
||||
state.recentlyUsed
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setRecentlyUsed([getApp("SETTINGS")])
|
||||
}, [getApp, setRecentlyUsed])
|
||||
|
||||
const listener = useCallback((location) => {
|
||||
const newState = [...recentlyUsed];
|
||||
allApps.forEach((app) => {
|
||||
if (matchPath(location.pathname, { path: app.path, exact: false })) {
|
||||
unshiftApp(newState, app);
|
||||
}
|
||||
});
|
||||
setRecentlyUsed(newState.slice(0, MAX_QUICK_ACCESS_ITEMS));
|
||||
}, [allApps, recentlyUsed, setRecentlyUsed]);
|
||||
|
||||
history.listen(listener);
|
||||
|
||||
return recentlyUsed;
|
||||
};
|
||||
Reference in new issue
Block a user