ContentLinkButtons.tsx 2.0 KB

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