DEV Community

Discussion on: Forem: Keyboard shortcuts

Collapse
reobin profile image
Robin Gagnon

Once there is the navigation for the article feed, the bookmark shortcut is a must.

Throwing ideas below:

  • Write a new post (n?)
  • Go to profile (p?)
  • Go to listings (l?)
  • Go back to the feed (f?)
  • Maybe shortcuts to switch between the different feeds (week, month, etc.)
Collapse
link2twenty profile image
Andrew Bone Author • Edited on

I like those maybe add message (M) too?

Twitter use chaining for certain actions like going to a certain page is g then another letter which is something we can theoretically do with the hook.

Collapse
reobin profile image
Robin Gagnon

Chaining sound super nice! vim-like 🌞

Thread Thread
link2twenty profile image
Andrew Bone Author

If that's a road we wanna go down it might be worth including chaining in the hook currently the only way to do it would be something like.

const [chaining, setChaining] = useState([]);
const [chainingQueue, setChainingQueue] = useState([]);

const pushChaining = useCallback((item)=>{
  setChaining([...chaining, item]);
},[chaining])

useEffect(()=>{ 
  let timeout;

  timeout = window.setTimeout(()=>{
    setChaining([]);
  }, 1500);

  if(!chainingQueue) return;
  pushChaining(chainingQueue);
  setChainingQueue(null)

  return ()=>clearTimeout(timeout);
},[chainingQueue, pushChaining]);

useKeyboardShortcut({
  KeyG: setChainingQueue('KeyG'),
  KeyH: (chaining === ['KeyG'] && function)
})
Enter fullscreen mode Exit fullscreen mode

Which is a bit convoluted to do over and over again.