Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stimulus-timeago instead of knplabs time bundle #7

Open
tacman opened this issue Mar 1, 2024 · 1 comment
Open

Use stimulus-timeago instead of knplabs time bundle #7

tacman opened this issue Mar 1, 2024 · 1 comment

Comments

@tacman
Copy link
Contributor

tacman commented Mar 1, 2024

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
Copy link
Member

Spomky commented Mar 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants