From c66c61bfeec4404f1792a9d11bc4b862b2f7b512 Mon Sep 17 00:00:00 2001 From: spencerwooo Date: Fri, 4 Feb 2022 22:20:53 +0800 Subject: [PATCH] switch layout dropdown and layout store --- components/SwitchLayout.tsx | 56 +++++++++++++++++++++++++++++++++++++ pages/[...path].tsx | 4 ++- pages/_app.tsx | 6 ++++ pages/index.tsx | 4 ++- 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 components/SwitchLayout.tsx diff --git a/components/SwitchLayout.tsx b/components/SwitchLayout.tsx new file mode 100644 index 0000000..6533c16 --- /dev/null +++ b/components/SwitchLayout.tsx @@ -0,0 +1,56 @@ +import { Fragment } from 'react' +import { IconProp } from '@fortawesome/fontawesome-svg-core' +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { Listbox, Transition } from '@headlessui/react' + +import useLocalStorage from '../utils/useLocalStorage' + +const layouts: Array<{ id: number; name: 'Grid' | 'List'; icon: IconProp }> = [ + { id: 1, name: 'Grid', icon: 'th' }, + { id: 2, name: 'List', icon: 'th-list' }, +] + +export const SwitchLayout = () => { + const [preferredLayout, setPreferredLayout] = useLocalStorage('preferredLayout', layouts[0]) + + return ( +
+ + + + + {preferredLayout.name} + + + + + + + + + {layouts.map(layout => ( + + {layout.name === preferredLayout.name && ( + + + + )} + + + {layout.name} + + + ))} + + + +
+ ) +} diff --git a/pages/[...path].tsx b/pages/[...path].tsx index 82536ef..13fb508 100644 --- a/pages/[...path].tsx +++ b/pages/[...path].tsx @@ -6,6 +6,7 @@ import Navbar from '../components/Navbar' import FileListing from '../components/FileListing' import Footer from '../components/Footer' import Breadcrumb from '../components/Breadcrumb' +import { SwitchLayout } from '../components/SwitchLayout' export default function Folders() { const { query } = useRouter() @@ -19,8 +20,9 @@ export default function Folders() {
-
diff --git a/pages/_app.tsx b/pages/_app.tsx index ddff109..c5ef125 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -41,10 +41,13 @@ import { faSignOutAlt, faCloud, faChevronCircleDown, + faChevronDown, faLink, faExternalLinkAlt, faExclamationCircle, faExclamationTriangle, + faTh, + faThList, faHome, } from '@fortawesome/free-solid-svg-icons' import * as Icons from '@fortawesome/free-brands-svg-icons' @@ -98,6 +101,9 @@ library.add( faCheck, faCheckCircle, faSearch, + faChevronDown, + faTh, + faThList, ...iconList ) diff --git a/pages/index.tsx b/pages/index.tsx index f36ab4b..23789d8 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -5,6 +5,7 @@ import Navbar from '../components/Navbar' import FileListing from '../components/FileListing' import Footer from '../components/Footer' import Breadcrumb from '../components/Breadcrumb' +import { SwitchLayout } from '../components/SwitchLayout' export default function Home() { return ( @@ -16,8 +17,9 @@ export default function Home() {
-