mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-02 22:26:57 +01:00
Add r, f, shift+b, d
This commit is contained in:
parent
301b2576c0
commit
c82edd2778
2 changed files with 89 additions and 3 deletions
|
@ -129,6 +129,26 @@ export default function KeyboardShortcutsHelp() {
|
||||||
action: 'Search',
|
action: 'Search',
|
||||||
keys: <kbd>/</kbd>,
|
keys: <kbd>/</kbd>,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
action: 'Reply',
|
||||||
|
keys: <kbd>r</kbd>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: 'Favourite',
|
||||||
|
keys: <kbd>f</kbd>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: 'Boost',
|
||||||
|
keys: (
|
||||||
|
<>
|
||||||
|
<kbd>Shift</kbd> + <kbd>b</kbd>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: 'Bookmark',
|
||||||
|
keys: <kbd>d</kbd>,
|
||||||
|
},
|
||||||
].map(({ action, keys }) => (
|
].map(({ action, keys }) => (
|
||||||
<tr key={action}>
|
<tr key={action}>
|
||||||
<th>{action}</th>
|
<th>{action}</th>
|
||||||
|
|
|
@ -19,6 +19,7 @@ import {
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from 'preact/hooks';
|
} from 'preact/hooks';
|
||||||
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
import { InView } from 'react-intersection-observer';
|
import { InView } from 'react-intersection-observer';
|
||||||
import { useLongPress } from 'use-long-press';
|
import { useLongPress } from 'use-long-press';
|
||||||
import useResizeObserver from 'use-resize-observer';
|
import useResizeObserver from 'use-resize-observer';
|
||||||
|
@ -621,8 +622,9 @@ function Status({
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
try {
|
try {
|
||||||
favouriteStatus();
|
favouriteStatus();
|
||||||
if (!isSizeLarge)
|
if (!isSizeLarge) {
|
||||||
showToast(favourited ? 'Unfavourited' : 'Favourited');
|
showToast(favourited ? 'Unfavourited' : 'Favourited');
|
||||||
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -644,8 +646,9 @@ function Status({
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
try {
|
try {
|
||||||
bookmarkStatus();
|
bookmarkStatus();
|
||||||
if (!isSizeLarge)
|
if (!isSizeLarge) {
|
||||||
showToast(bookmarked ? 'Unbookmarked' : 'Bookmarked');
|
showToast(bookmarked ? 'Unbookmarked' : 'Bookmarked');
|
||||||
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -832,9 +835,72 @@ function Status({
|
||||||
|
|
||||||
const showContextMenu = size !== 'l' && !previewMode && !_deleted && !quoted;
|
const showContextMenu = size !== 'l' && !previewMode && !_deleted && !quoted;
|
||||||
|
|
||||||
|
const hotkeysEnabled = !readOnly && !previewMode;
|
||||||
|
const rRef = useHotkeys('r', replyStatus, {
|
||||||
|
enabled: hotkeysEnabled,
|
||||||
|
});
|
||||||
|
const fRef = useHotkeys(
|
||||||
|
'f',
|
||||||
|
() => {
|
||||||
|
try {
|
||||||
|
favouriteStatus();
|
||||||
|
if (!isSizeLarge) {
|
||||||
|
showToast(favourited ? 'Unfavourited' : 'Favourited');
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
enabled: hotkeysEnabled,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const dRef = useHotkeys(
|
||||||
|
'd',
|
||||||
|
() => {
|
||||||
|
try {
|
||||||
|
bookmarkStatus();
|
||||||
|
if (!isSizeLarge) {
|
||||||
|
showToast(bookmarked ? 'Unbookmarked' : 'Bookmarked');
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
enabled: hotkeysEnabled,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const bRef = useHotkeys(
|
||||||
|
'shift+b',
|
||||||
|
() => {
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const done = await confirmBoostStatus();
|
||||||
|
if (!isSizeLarge && done) {
|
||||||
|
showToast(reblogged ? 'Unboosted' : 'Boosted');
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
})();
|
||||||
|
},
|
||||||
|
{
|
||||||
|
enabled: hotkeysEnabled && canBoost,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<article
|
<article
|
||||||
ref={statusRef}
|
ref={(node) => {
|
||||||
|
statusRef.current = node;
|
||||||
|
// Use parent node if it's in focus
|
||||||
|
// Use case: <a><status /></a>
|
||||||
|
// When navigating (j/k), the <a> is focused instead of <status />
|
||||||
|
// Hotkey binding doesn't bubble up thus this hack
|
||||||
|
const nodeRef =
|
||||||
|
node?.closest?.(
|
||||||
|
'.timeline-item, .timeline-item-alt, .status-link, .status-focus',
|
||||||
|
) || node;
|
||||||
|
rRef.current = nodeRef;
|
||||||
|
fRef.current = nodeRef;
|
||||||
|
dRef.current = nodeRef;
|
||||||
|
bRef.current = nodeRef;
|
||||||
|
}}
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
class={`status ${
|
class={`status ${
|
||||||
!withinContext && inReplyToId && inReplyToAccount
|
!withinContext && inReplyToId && inReplyToAccount
|
||||||
|
|
Loading…
Reference in a new issue