feat: support elementary keyboard shortcuts

This commit is contained in:
Shusui MOYATANI
2023-03-08 01:55:30 +09:00
parent 410b18d3a2
commit e581d3fc74
9 changed files with 218 additions and 103 deletions

View File

@@ -1,15 +1,44 @@
import { createSignal, Show } from 'solid-js';
import type { Component } from 'solid-js';
import { createSignal, Show, type JSX, Component } from 'solid-js';
import MagnifyingGlass from 'heroicons/24/solid/magnifying-glass.svg';
import PencilSquare from 'heroicons/24/solid/pencil-square.svg';
type SideBarProps = {
postForm: () => JSX.Element;
};
import NotePostForm from '@/components/NotePostForm';
import useConfig from '@/clients/useConfig';
import useCommands from '@/clients/useCommands';
import usePubkey from '@/clients/usePubkey';
import { useHandleCommand } from '@/hooks/useCommandBus';
const SideBar: Component = (props) => {
const [config] = useConfig();
const pubkey = usePubkey();
const commands = useCommands();
const SideBar: Component<SideBarProps> = (props) => {
const [formOpened, setFormOpened] = createSignal(false);
const handlePost = ({ content }: { content: string }) => {
commands
.publishTextNote({
relayUrls: config().relayUrls,
pubkey: pubkey(),
content,
})
.then(() => {
console.log('ok');
})
.catch((err) => {
console.error('error', err);
});
};
useHandleCommand(() => ({
commandType: 'openPostForm',
handler: (cmd) => {
setFormOpened(true);
},
}));
return (
<div class="flex shrink-0 flex-row border-r bg-sidebar-bg">
<div class="flex w-14 flex-auto flex-col items-center gap-3 border-r border-rose-200 py-5">
@@ -25,7 +54,9 @@ const SideBar: Component<SideBarProps> = (props) => {
{/* <div>column 1</div> */}
{/* <div>column 2</div> */}
</div>
<Show when={formOpened()}>{() => props.postForm()}</Show>
<Show when={formOpened()}>
<NotePostForm onPost={handlePost} onClose={() => setFormOpened(false)} />
</Show>
</div>
);
};