ContentLinkButtons.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React, { useCallback, useMemo } from 'react';
  2. import { smoothScrollIntoView } from '~/client/util/smooth-scroll';
  3. import { RecentlyCreatedIcon } from '~/components/Icons/RecentlyCreatedIcon';
  4. import { usePageUser } from '~/stores/context';
  5. const WIKI_HEADER_LINK = 120;
  6. const ContentLinkButtons = (): JSX.Element => {
  7. const { data: pageUser } = usePageUser();
  8. // get element for smoothScroll
  9. const getBookMarkListHeaderDom = useMemo(() => { return document.getElementById('bookmarks-list') }, []);
  10. const getRecentlyCreatedListHeaderDom = useMemo(() => { return document.getElementById('recently-created-list') }, []);
  11. const BookMarkLinkButton = useCallback((): JSX.Element => {
  12. if (getBookMarkListHeaderDom == null) {
  13. return <></>;
  14. }
  15. return (
  16. <button
  17. type="button"
  18. className="btn btn-outline-secondary btn-sm px-2"
  19. onClick={() => smoothScrollIntoView(getBookMarkListHeaderDom, WIKI_HEADER_LINK)}
  20. >
  21. <i className="fa fa-fw fa-bookmark-o"></i>
  22. <span>Bookmarks</span>
  23. </button>
  24. );
  25. }, [getBookMarkListHeaderDom]);
  26. const RecentlyCreatedLinkButton = useCallback(() => {
  27. if (getRecentlyCreatedListHeaderDom == null) {
  28. return <></>;
  29. }
  30. return (
  31. <button
  32. type="button"
  33. className="btn btn-outline-secondary btn-sm px-3"
  34. onClick={() => smoothScrollIntoView(getRecentlyCreatedListHeaderDom, WIKI_HEADER_LINK)}
  35. >
  36. <i className="grw-icon-container-recently-created mr-2"><RecentlyCreatedIcon /></i>
  37. <span>Recently Created</span>
  38. </button>
  39. );
  40. }, [getRecentlyCreatedListHeaderDom]);
  41. if (pageUser == null) {
  42. return <></>;
  43. }
  44. return (
  45. <div className="mt-3 d-flex justify-content-between">
  46. <BookMarkLinkButton />
  47. <RecentlyCreatedLinkButton />
  48. </div>
  49. );
  50. };
  51. export default ContentLinkButtons;