From 81d0cad71c2b35887e4a1fe6f8586df020867754 Mon Sep 17 00:00:00 2001 From: myl7 Date: Tue, 15 Feb 2022 19:27:47 +0800 Subject: [PATCH] Preserve original ext and skip folders when extracting extensions (#448) --- components/FileListing.tsx | 8 ++++---- components/FolderGridLayout.tsx | 2 +- components/FolderListLayout.tsx | 2 +- utils/getFileIcon.ts | 5 ++++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/components/FileListing.tsx b/components/FileListing.tsx index 2f6deb4..f63145f 100644 --- a/components/FileListing.tsx +++ b/components/FileListing.tsx @@ -12,7 +12,7 @@ import { useTranslation } from 'next-i18next' import useLocalStorage from '../utils/useLocalStorage' import { getPreviewType, preview } from '../utils/getPreviewType' import { useProtectedSWRInfinite } from '../utils/fetchWithSWR' -import { getExtension, getFileIcon } from '../utils/getFileIcon' +import { getExtension, getRawExtension, getFileIcon } from '../utils/getFileIcon' import { getStoredToken } from '../utils/protectedRouteHandler' import { DownloadingToast, @@ -70,10 +70,10 @@ const formatChildName = (name: string) => { const { render, emoji } = renderEmoji(name) return render ? name.replace(emoji ? emoji[0] : '', '').trim() : name } -export const ChildName: FC<{ name: string }> = ({ name }) => { +export const ChildName: FC<{ name: string; folder?: boolean }> = ({ name, folder }) => { const original = formatChildName(name) - const extension = getExtension(original) - const prename = original.substring(0, original.length - extension.length) + const extension = folder ? '' : getRawExtension(original) + const prename = folder ? original : original.substring(0, original.length - extension.length) return ( {prename} diff --git a/components/FolderGridLayout.tsx b/components/FolderGridLayout.tsx index 7915a15..d8bc309 100644 --- a/components/FolderGridLayout.tsx +++ b/components/FolderGridLayout.tsx @@ -46,7 +46,7 @@ const GridItem = ({ c, path }: { c: OdFolderChildren; path: string }) => { - +
{formatModifiedDateTime(c.lastModifiedDateTime)} diff --git a/components/FolderListLayout.tsx b/components/FolderListLayout.tsx index 184cf7d..6abaf9c 100644 --- a/components/FolderListLayout.tsx +++ b/components/FolderListLayout.tsx @@ -20,7 +20,7 @@ const FileListItem: FC<{ fileContent: OdFolderChildren }> = ({ fileContent: c })
- +
{formatModifiedDateTime(c.lastModifiedDateTime)} diff --git a/utils/getFileIcon.ts b/utils/getFileIcon.ts index 35f8015..8b4318f 100644 --- a/utils/getFileIcon.ts +++ b/utils/getFileIcon.ts @@ -105,8 +105,11 @@ export function hasKey(obj: O, key: PropertyKey): key is keyof O { return key in obj } +export function getRawExtension(fileName: string): string { + return fileName.slice(((fileName.lastIndexOf('.') - 1) >>> 0) + 2) +} export function getExtension(fileName: string): string { - return fileName.slice(((fileName.lastIndexOf('.') - 1) >>> 0) + 2).toLowerCase() + return getRawExtension(fileName).toLowerCase() } export function getFileIcon(fileName: string, flags?: { video?: boolean }): [IconPrefix, IconName] {