From d7abbd21fd624e5f200b5c63792e5dfe383f8f1a Mon Sep 17 00:00:00 2001 From: Ian Wijma Date: Tue, 28 Nov 2023 00:16:34 +1100 Subject: [PATCH] Remove Permissions and add Date formatting in File listing Removed 'Permissions' column from the file listing in index.html to declutter the view. Instead of showing permissions, we now format the 'Modified' field with a human-friendly date format, to improve readability. This involves changes in 'list.js', where the field 'Permissions' is now replaced with a formatted 'Modified' date. Additionally, a 'formatDate' function is added in 'files.js' to handle the new date formatting logic. --- src/index.html | 2 -- src/parts/files.js | 16 ++++++++++++++++ src/parts/files/list.js | 5 ++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/index.html b/src/index.html index aeeb4ac..db84665 100644 --- a/src/index.html +++ b/src/index.html @@ -59,7 +59,6 @@ Name Size - Permissions Modified @@ -71,7 +70,6 @@ - diff --git a/src/parts/files.js b/src/parts/files.js index 93054c7..bcf4412 100644 --- a/src/parts/files.js +++ b/src/parts/files.js @@ -90,4 +90,20 @@ export const formatDirectoryItemCount = (directoryItemCount) => { export const openFile = async (path) => { return await tauriInvoke('open_file', { path }); +} + +export const formatDate = (timestamp) => { + const now = (new Date).getTime(); + const date = new Date(parseInt(`${timestamp}000`)) + const then = (date).getTime(); + const diff = now - then; + const diffInDays = Math.floor(diff/(1000 * 60 * 60 * 24)); + + if (diffInDays <= 0) { + return `${date.getHours()}:${date.getMinutes()}`; + } else if (diffInDays <= 365) { + return `${date.toLocaleString('default', { month: 'short' })} ${date.getDate()}` + } + + return `${date.toLocaleString('default', { month: 'short' })} ${date.getDate()} ${date.getFullYear()}`; } \ No newline at end of file diff --git a/src/parts/files/list.js b/src/parts/files/list.js index 33190fe..9b99478 100644 --- a/src/parts/files/list.js +++ b/src/parts/files/list.js @@ -1,5 +1,5 @@ import {getTemplate} from "../../libs/template.js"; -import {formatBytes, formatDirectoryItemCount, getEntries, openFile} from "../files.js"; +import {formatBytes, formatDate, formatDirectoryItemCount, getEntries, openFile} from "../files.js"; import {getCurrentDir, navigate} from "../../libs/navigation.js"; import {getOneElementOrThrow} from "../../libs/element.js"; import {sep} from "../../libs/path.js"; @@ -42,8 +42,7 @@ export const renderListFiles = () => { if (entry.is_directory) prefix = sep; return `${prefix}${value}`; }); - applyValue(entry, itemTemplate, 'permission') - applyValue(entry, itemTemplate, 'modified') + applyValue(entry, itemTemplate, 'modified', (value) => formatDate(value)) applyValue( entry, itemTemplate,