phanpy/src/pages/home.jsx

77 lines
2 KiB
React
Raw Normal View History

import { useEffect } from 'preact/hooks';
import { useSnapshot } from 'valtio';
2022-12-10 12:14:48 +03:00
import Columns from '../components/columns';
2022-12-10 12:14:48 +03:00
import Icon from '../components/icon';
import Link from '../components/link';
import db from '../utils/db';
2023-02-09 17:27:49 +03:00
import openCompose from '../utils/open-compose';
import states from '../utils/states';
import { getCurrentAccountNS } from '../utils/store-utils';
2022-12-10 12:14:48 +03:00
2023-02-09 17:27:49 +03:00
import Following from './following';
2023-02-09 17:27:49 +03:00
function Home() {
const snapStates = useSnapshot(states);
useEffect(() => {
(async () => {
const keys = await db.drafts.keys();
if (keys.length) {
const ns = getCurrentAccountNS();
const ownKeys = keys.filter((key) => key.startsWith(ns));
if (ownKeys.length) {
states.showDrafts = true;
}
}
})();
}, []);
2022-12-10 12:14:48 +03:00
return (
<>
{snapStates.settings.shortcutsColumnsMode ? (
<Columns />
2023-02-18 15:48:24 +03:00
) : (
<Following
title="Home"
path="/"
id="home"
headerStart={false}
headerEnd={
<Link
to="/notifications"
class={`button plain ${
snapStates.notificationsShowNew ? 'has-badge' : ''
}`}
onClick={(e) => {
e.stopPropagation();
}}
>
<Icon icon="notification" size="l" alt="Notifications" />
</Link>
}
/>
)}
<button
2023-02-09 17:27:49 +03:00
// hidden={scrollDirection === 'end' && !nearReachStart}
type="button"
id="compose-button"
onClick={(e) => {
if (e.shiftKey) {
const newWin = openCompose();
if (!newWin) {
alert('Looks like your browser is blocking popups.');
states.showCompose = true;
}
} else {
states.showCompose = true;
}
}}
>
2023-02-16 12:51:54 +03:00
<Icon icon="quill" size="xl" alt="Compose" />
</button>
</>
2022-12-10 12:14:48 +03:00
);
2022-12-16 08:27:04 +03:00
}
2023-02-09 17:27:49 +03:00
export default Home;