ContentLinkButtons.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import React, { useCallback } from 'react';
  2. import type { IUserHasId } from '@growi/core';
  3. import { smoothScrollIntoView } from '~/client/util/smooth-scroll';
  4. import { RecentlyCreatedIcon } from '~/components/Icons/RecentlyCreatedIcon';
  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 type ContentLinkButtonsProps = {
  44. author?: IUserHasId,
  45. }
  46. export const ContentLinkButtons = (props: ContentLinkButtonsProps): JSX.Element => {
  47. const { author } = props;
  48. if (author == null || author.status === 4) {
  49. return <></>;
  50. }
  51. return (
  52. <div className="mt-3 d-flex justify-content-between">
  53. <BookMarkLinkButton />
  54. <RecentlyCreatedLinkButton />
  55. </div>
  56. );
  57. };