💄 Affiche les pages dans l'ordre avec les dates formatées

This commit is contained in:
Clement Desmidt 2022-03-09 11:14:14 +01:00
parent 44e9b5d694
commit a253845eca
2 changed files with 11 additions and 4 deletions

View File

@ -28,18 +28,21 @@ class PageController extends Controller
} }
//https://itnext.io/laravel-the-mysterious-ordered-uuid-29e7500b4f8 //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 { try {
return [ return [
'id' => explode('.', basename($page_path))[0], '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) { } catch (\Exception $e) {
$request->session()->flash('status', 'Date ?'); $request->session()->flash('status', 'Date ?');
return null; return null;
} }
}, Storage::disk('pages')->files(Auth::user()->getAuthIdentifier())); }, Storage::disk('pages')->files(Auth::user()->getAuthIdentifier())));
$user = Auth::user(); $user = Auth::user();

View File

@ -41,10 +41,14 @@ export default function PageForm({setListPages, csrf, url, passphrase}) {
if (json.success) { if (json.success) {
HTMLForm.reset(); 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 => [ setListPages(previousList => [
{ {
id: uuid, id: uuid,
date: json.date, date: oSavedDate.toLocaleString(),
title: decryptedFormData.get("title"), title: decryptedFormData.get("title"),
content: decryptedFormData.get("text"), content: decryptedFormData.get("text"),
}, },