|
| 1 | +import * as React from 'react' |
| 2 | +import { FaTwitter } from '@react-icons/all-files/fa/FaTwitter' |
| 3 | +import { FaZhihu } from '@react-icons/all-files/fa/FaZhihu' |
| 4 | +import { FaGithub } from '@react-icons/all-files/fa/FaGithub' |
| 5 | +import { FaLinkedin } from '@react-icons/all-files/fa/FaLinkedin' |
| 6 | +import { IoSunnyOutline } from '@react-icons/all-files/io5/IoSunnyOutline' |
| 7 | +import { IoMoonSharp } from '@react-icons/all-files/io5/IoMoonSharp' |
| 8 | + |
| 9 | +import { useDarkMode } from 'lib/use-dark-mode' |
| 10 | +import * as config from 'lib/config' |
| 11 | + |
| 12 | +import styles from './styles.module.css' |
| 13 | + |
| 14 | +// TODO: merge the data and icons from PageSocial with the social links in Footer |
| 15 | + |
| 16 | +export const FooterImpl: React.FC = () => { |
| 17 | + const [hasMounted, setHasMounted] = React.useState(false) |
| 18 | + const { isDarkMode, toggleDarkMode } = useDarkMode() |
| 19 | + |
| 20 | + const onToggleDarkMode = React.useCallback( |
| 21 | + (e) => { |
| 22 | + e.preventDefault() |
| 23 | + toggleDarkMode() |
| 24 | + }, |
| 25 | + [toggleDarkMode] |
| 26 | + ) |
| 27 | + |
| 28 | + React.useEffect(() => { |
| 29 | + setHasMounted(true) |
| 30 | + }, []) |
| 31 | + |
| 32 | + return ( |
| 33 | + <footer className={styles.footer}> |
| 34 | + <div className={styles.copyright}>Copyright 2022 {config.author}</div> |
| 35 | + |
| 36 | + <div className={styles.settings}> |
| 37 | + {hasMounted && ( |
| 38 | + <a |
| 39 | + className={styles.toggleDarkMode} |
| 40 | + href='#' |
| 41 | + role='button' |
| 42 | + onClick={onToggleDarkMode} |
| 43 | + title='Toggle dark mode' |
| 44 | + > |
| 45 | + {isDarkMode ? <IoMoonSharp /> : <IoSunnyOutline />} |
| 46 | + </a> |
| 47 | + )} |
| 48 | + </div> |
| 49 | + |
| 50 | + <div className={styles.social}> |
| 51 | + {config.twitter && ( |
| 52 | + <a |
| 53 | + className={styles.twitter} |
| 54 | + href={`https://twitter.com/${config.twitter}`} |
| 55 | + title={`Twitter @${config.twitter}`} |
| 56 | + target='_blank' |
| 57 | + rel='noopener noreferrer' |
| 58 | + > |
| 59 | + <FaTwitter /> |
| 60 | + </a> |
| 61 | + )} |
| 62 | + |
| 63 | + {config.zhihu && ( |
| 64 | + <a |
| 65 | + className={styles.zhihu} |
| 66 | + href={`https://zhihu.com/people/${config.zhihu}`} |
| 67 | + title={`Zhihu @${config.zhihu}`} |
| 68 | + target='_blank' |
| 69 | + rel='noopener noreferrer' |
| 70 | + > |
| 71 | + <FaZhihu /> |
| 72 | + </a> |
| 73 | + )} |
| 74 | + |
| 75 | + {config.github && ( |
| 76 | + <a |
| 77 | + className={styles.github} |
| 78 | + href={`https://github.com/${config.github}`} |
| 79 | + title={`GitHub @${config.github}`} |
| 80 | + target='_blank' |
| 81 | + rel='noopener noreferrer' |
| 82 | + > |
| 83 | + <FaGithub /> |
| 84 | + </a> |
| 85 | + )} |
| 86 | + |
| 87 | + {config.linkedin && ( |
| 88 | + <a |
| 89 | + className={styles.linkedin} |
| 90 | + href={`https://www.linkedin.com/in/${config.linkedin}`} |
| 91 | + title={`LinkedIn ${config.author}`} |
| 92 | + target='_blank' |
| 93 | + rel='noopener noreferrer' |
| 94 | + > |
| 95 | + <FaLinkedin /> |
| 96 | + </a> |
| 97 | + )} |
| 98 | + </div> |
| 99 | + </footer> |
| 100 | + ) |
| 101 | +} |
| 102 | + |
| 103 | +export const Footer = React.memo(FooterImpl) |
0 commit comments