Spomky-Labs / phpwa-demo

Demonstration for the PHPWA Bundle
0 stars 1 forks source link

Use stimulus-timeago instead of knplabs time bundle #7

Open tacman opened 4 months ago

tacman commented 4 months ago

The problem with

{{ item.createdAt|time_diff }}

is that it renders HTML with the age of the item at the time of rendering.

What we want is the age of the item. This can be done by installing stimulus-timeago, and instead using

<time data-controller="timeago"
      data-timeago-add-suffix-value="true"
      data-timeago-include-seconds-value="true"
      data-timeago-refresh-interval-value="1000"
      data-timeago-datetime-value="{{ item.createdAt|date('c') }}"></time>.

That way, when it runs offline the time ago is correct. And even updated dynamically!

Add an item at

https://phpwa-demo.survos.com/

Go offline and refresh, the item age is accurate.

Spomky commented 4 months ago

Indeed. It looks better and will perfectly fit in case data are loaded async