From c16d0ab2db147fa481c0378a670c0285d64d9168 Mon Sep 17 00:00:00 2001 From: spencerwooo Date: Fri, 4 Feb 2022 17:22:40 +0800 Subject: [PATCH] new breadcrumb that scrolls to the end automatically --- components/Breadcrumb.tsx | 60 +++++++++++++++++++++++++------------- components/FileListing.tsx | 56 +++++++++++++++++------------------ pages/[...path].tsx | 10 ++++--- pages/_app.tsx | 4 +++ pages/index.tsx | 10 ++++--- 5 files changed, 84 insertions(+), 56 deletions(-) diff --git a/components/Breadcrumb.tsx b/components/Breadcrumb.tsx index b939401..4009265 100644 --- a/components/Breadcrumb.tsx +++ b/components/Breadcrumb.tsx @@ -1,41 +1,61 @@ -import Link from 'next/link' +import type { ParsedUrlQuery } from 'querystring' -import { ParsedUrlQuery } from 'querystring' +import Link from 'next/link' +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' + +const HomeCrumb = () => { + return ( + + + + Home + + + ) +} const Breadcrumb: React.FC<{ query?: ParsedUrlQuery }> = ({ query }) => { if (query) { const { path } = query if (Array.isArray(path)) { + // We are rendering the path in reverse, so that the browser automatically scrolls to the end of the breadcrumb + // https://stackoverflow.com/questions/18614301/keep-overflow-div-scrolled-to-bottom-unless-user-scrolls-up/18614561 return ( -
-
- 🚩 Home -
- {path.map((q: string, i: number) => ( -
-
/
-
+
    + {path + .slice(0) + .reverse() + .map((p: string, i: number) => ( +
  1. + encodeURIComponent(p)) .join('/')}`} + passHref > - {q} + + {p} + -
-
- ))} -
+ + ))} +
  • + +
  • + ) } } return ( -
    -
    - 🚩 Home -
    +
    +
    ) } diff --git a/components/FileListing.tsx b/components/FileListing.tsx index 9ffff95..4b9d582 100644 --- a/components/FileListing.tsx +++ b/components/FileListing.tsx @@ -66,10 +66,10 @@ const FileListItem: FC<{ fileContent: OdFolderObject['value'][number] }> = ({ fi const renderEmoji = emojiIcon && !emojiIcon.index return ( -
    -
    +
    +
    {/*
    {c.file ? c.file.mimeType : 'folder'}
    */} -
    +
    {renderEmoji ? ( {emojiIcon ? emojiIcon[0] : '📁'} ) : ( @@ -80,10 +80,10 @@ const FileListItem: FC<{ fileContent: OdFolderObject['value'][number] }> = ({ fi {renderEmoji ? c.name.replace(emojiIcon ? emojiIcon[0] : '', '').trim() : c.name}
    -
    +
    {formatModifiedDateTime(c.lastModifiedDateTime)}
    -
    +
    {humanFileSize(c.size)}
    @@ -120,7 +120,7 @@ const Checkbox: FC<{ return ( = ({ title }) => { return ( - + ) @@ -337,22 +337,22 @@ const FileListing: FC<{ query?: ParsedUrlQuery }> = ({ query }) => { return ( <> -
    -
    -
    +
    +
    +
    Name
    -
    +
    Last Modified
    -
    +
    Size
    -
    +
    Actions
    -
    -
    +
    +
    = ({ query }) => { ) : (