2023-02-18 16:14:24 +03:00
|
|
|
import { useHotkeys } from 'react-hotkeys-hook';
|
|
|
|
import { useSnapshot } from 'valtio';
|
|
|
|
|
|
|
|
import Bookmarks from '../pages/bookmarks';
|
|
|
|
import Favourites from '../pages/favourites';
|
|
|
|
import Following from '../pages/following';
|
|
|
|
import Hashtag from '../pages/hashtag';
|
|
|
|
import List from '../pages/list';
|
2023-04-09 04:36:55 +03:00
|
|
|
import Mentions from '../pages/mentions';
|
2023-02-18 16:14:24 +03:00
|
|
|
import Notifications from '../pages/notifications';
|
|
|
|
import Public from '../pages/public';
|
2023-04-14 05:54:22 +03:00
|
|
|
import Trending from '../pages/trending';
|
2023-02-18 16:14:24 +03:00
|
|
|
import states from '../utils/states';
|
2023-02-18 17:13:32 +03:00
|
|
|
import useTitle from '../utils/useTitle';
|
2023-02-18 16:14:24 +03:00
|
|
|
|
|
|
|
function Columns() {
|
2023-02-18 17:13:32 +03:00
|
|
|
useTitle('Home', '/');
|
2023-02-18 16:14:24 +03:00
|
|
|
const snapStates = useSnapshot(states);
|
|
|
|
const { shortcuts } = snapStates;
|
|
|
|
|
2023-07-05 11:59:28 +03:00
|
|
|
console.debug('RENDER Columns', shortcuts);
|
|
|
|
|
2023-02-18 16:14:24 +03:00
|
|
|
const components = shortcuts.map((shortcut) => {
|
2023-04-08 17:16:13 +03:00
|
|
|
if (!shortcut) return null;
|
2023-02-18 16:14:24 +03:00
|
|
|
const { type, ...params } = shortcut;
|
|
|
|
const Component = {
|
|
|
|
following: Following,
|
|
|
|
notifications: Notifications,
|
|
|
|
list: List,
|
|
|
|
public: Public,
|
|
|
|
bookmarks: Bookmarks,
|
|
|
|
favourites: Favourites,
|
|
|
|
hashtag: Hashtag,
|
2023-04-09 04:36:55 +03:00
|
|
|
mentions: Mentions,
|
2023-04-14 05:54:22 +03:00
|
|
|
trending: Trending,
|
2023-02-18 16:14:24 +03:00
|
|
|
}[type];
|
2023-02-19 05:27:37 +03:00
|
|
|
if (!Component) return null;
|
2023-07-05 11:59:28 +03:00
|
|
|
return (
|
|
|
|
<Component key={type + JSON.stringify(params)} {...params} columnMode />
|
|
|
|
);
|
2023-02-18 16:14:24 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
useHotkeys(['1', '2', '3', '4', '5', '6', '7', '8', '9'], (e, handler) => {
|
|
|
|
try {
|
|
|
|
const index = parseInt(handler.keys[0], 10) - 1;
|
|
|
|
document.querySelectorAll('#columns > *')[index].focus();
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-11-03 17:08:44 +03:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
id="columns"
|
|
|
|
onContextMenu={(e) => {
|
|
|
|
// If right-click on header, but not links or buttons
|
|
|
|
if (
|
|
|
|
e.target.closest('.deck > header') &&
|
|
|
|
!e.target.closest('a') &&
|
|
|
|
!e.target.closest('button')
|
|
|
|
) {
|
|
|
|
e.preventDefault();
|
|
|
|
states.showShortcutsSettings = true;
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{components}
|
|
|
|
</div>
|
|
|
|
);
|
2023-02-18 16:14:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Columns;
|