From a253845eca7cea5218933e4ec6353c3feff4a85e Mon Sep 17 00:00:00 2001 From: Clement Desmidt Date: Wed, 9 Mar 2022 11:14:14 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20Affiche=20les=20pages=20dans=20l?= =?UTF-8?q?'ordre=20avec=20les=20dates=20format=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/PageController.php | 9 ++++++--- resources/js/components/pages/Form.tsx | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index bc737c7..afd8201 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -28,18 +28,21 @@ class PageController extends Controller } //https://itnext.io/laravel-the-mysterious-ordered-uuid-29e7500b4f8 - $pages = array_map(static function ($page_path) use ($request) { + $pages = array_reverse(array_map(static function ($page_path) use ($request) { try { return [ 'id' => explode('.', basename($page_path))[0], - 'date' => DateTime::createFromFormat('U', substr(hexdec(implode(array_slice(explode('-', basename($page_path)), 0, 2))), 0, 10))->format('Y-m-d H:i:s'), + 'date' => DateTime::createFromFormat( + 'U', + substr(hexdec(implode(array_slice(explode('-', basename($page_path)), 0, 2))), 0, 10) + )->format('d/m/Y H:i:s'), ]; } catch (\Exception $e) { $request->session()->flash('status', 'Date ?'); return null; } - }, Storage::disk('pages')->files(Auth::user()->getAuthIdentifier())); + }, Storage::disk('pages')->files(Auth::user()->getAuthIdentifier()))); $user = Auth::user(); diff --git a/resources/js/components/pages/Form.tsx b/resources/js/components/pages/Form.tsx index dd02aac..71a35c4 100644 --- a/resources/js/components/pages/Form.tsx +++ b/resources/js/components/pages/Form.tsx @@ -41,10 +41,14 @@ export default function PageForm({setListPages, csrf, url, passphrase}) { if (json.success) { HTMLForm.reset(); + const savedDate = json.date; + const oSavedDate = new Date(); + oSavedDate.setFullYear(savedDate.substring(0, 4), savedDate.substring(4,6), savedDate.substring(6,8)); + oSavedDate.setHours(savedDate.substring(9,11), savedDate.substring(11,13), savedDate.substring(13,15)); setListPages(previousList => [ { id: uuid, - date: json.date, + date: oSavedDate.toLocaleString(), title: decryptedFormData.get("title"), content: decryptedFormData.get("text"), },