-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Stimulus Components #85
Comments
While stimulus components would work, I think Twig Components would be even better (which would wrap the stimulus calls in twig). |
It's easier (for me at least) to work with the new bundle structure when adding stimulus/twig components. I see you've added #80 to milestone 1.1, would you like me to take a crack at refactoring the bundle config to use AbstractBundle? |
I made some progress on this, by creating a pwa-extra-bundle. I use Bootstrap rather than Tailwind, so I created twig components (which wrap stimulus controllers) where the content is configurable . composer require survos/pwa-extra-bundle Then cut, paste and customize <twig:PwaInstall>
<twig:block name="install">
<button type="button" class="btn btn-primary">
<span class="bi bi-download"></span>
Install as PWA
</button>
</twig:block>
<twig:block name="launch">
<button type="button" class="btn btn-success">
<span class="bi bi-download"></span>
It's installed! Launch it!
</button>
</twig:block>
</twig:PwaInstall>
<twig:ConnectionDetector>
<twig:block name="online">
<button class="btn btn-warning">Online</button>
</twig:block>
<twig:block name="offline">
<button class="btn btn-danger">offline</button>
</twig:block>
</twig:ConnectionDetector>
Launch still does not work, as I'm not sure what it's supposed to be. See it in action: https://noise.survos.com/, functional but unattractive, as I'm in the middle of switch to bootstrap. |
Hi, I started working on stimulus component. The refactoring of the bundle configuration is done in 1.1.x and I would like to release it by the end of the month. |
Two stimulus components are available:
|
background sync sounds very exciting, but I'm not sure how to use it. Here's the form rendering to add a task in phpwa-demo. Should the stimulus controller go on the form itself, or can it go on a div that wraps the form? And if the user is offline, what happens? I've been reading https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Guides/Offline_and_background_operation, and an example would be very helpful. {{ form_start(form, {attr: {class: ' class="max-w-sm mx-auto"'}}) }}
<div class="mb-5">
<label for="name" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
{{ form_label(form.name) }}
</label>
{{ form_widget(form.name, {attr: {class: 'block w-full p-4 text-gray-900 border border-gray-300 rounded-lg bg-gray-50 text-base focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500'}}) }}
</div>
<button type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Add</button>
{{ form_end(form) }}
|
To work with BackgroundSync, you first need to declare what routes/methods you want to capture. And you are done! ... almost done. The purpose of this stimulus component is to help redirecting correctly. It is used by the other forms on the page where we expect a redirection to
|
So the idea is that it would return to a page that said "Thanks for submitting! You're offline now, but your request is queued for delivery when you reconnect." That's pretty cool! |
That's the idea. What I am trying to do now is to notify the frontend that the queue is not empty. "onSync": async ({queue}) => {
await queue.replayRequests();
remainingRequests = await queue.getAll();
const bc = new BroadcastChannel('background-sync');
bc.postMessage({name: '{$sync->queueName}', remaining: remainingRequests.length});
bc.close();
} The final goal is to ease features like this one: GoogleChrome/workbox#2044 (comment) |
This is great. Question: is it possible to bypass the form submit and go directly to the queue? In particular, I'm thinking about when you want to take photos quickly and don't want to wait for the upload. |
It should be possible to bypass it using JS. |
Description
The demo contains helpful Stimulus Components and additional JS scripts that could be added here to ease the integration.
Example
The text was updated successfully, but these errors were encountered: