Use stimulus for global reloading

This commit is contained in:
Jan Böhmer 2022-07-24 14:41:28 +02:00
parent 390deca544
commit ea6357c259
4 changed files with 22 additions and 14 deletions

View file

@ -0,0 +1,8 @@
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
connect() {
//If we encounter an element with global reload controller, then reload the whole page
window.location.href = window.location.href;
}
}

View file

@ -354,7 +354,7 @@ class UserSettingsController extends AbstractController
'user' => $user, 'user' => $user,
'settings_form' => $form, 'settings_form' => $form,
'pw_form' => $pw_form, 'pw_form' => $pw_form,
'page_need_reload' => $page_need_reload, 'global_reload_needed' => $page_need_reload,
'google_form' => $google_form, 'google_form' => $google_form,
'backup_form' => $backup_form, 'backup_form' => $backup_form,

View file

@ -6,10 +6,6 @@
{% trans %}user.settings.label{% endtrans %}{% endblock %} {% trans %}user.settings.label{% endtrans %}{% endblock %}
{% block card_content %} {% block card_content %}
{% if page_need_reload %}
<script>window.location.href = window.location.href;</script>
{% endif %}
{{ form_start(settings_form) }} {{ form_start(settings_form) }}
<ul class="nav nav-tabs" id="myTab" role="tablist"> <ul class="nav nav-tabs" id="myTab" role="tablist">

View file

@ -24,7 +24,6 @@
<link rel="icon" type="image/png" href="{{ asset('icon/favicon-16x16.png') }}" sizes="16x16"> <link rel="icon" type="image/png" href="{{ asset('icon/favicon-16x16.png') }}" sizes="16x16">
<link rel="mask-icon" href="{{ asset('icon/safari-pinned-tab.svg') }}" color="#5bbad5"> <link rel="mask-icon" href="{{ asset('icon/safari-pinned-tab.svg') }}" color="#5bbad5">
<title>{% apply trim %}{% block title %}{{ partdb_title}}{% endblock %}{% endapply %}</title> <title>{% apply trim %}{% block title %}{{ partdb_title}}{% endblock %}{% endapply %}</title>
{% block stylesheets %} {% block stylesheets %}
{# Include the main bootstrap theme based on user/global setting #} {# Include the main bootstrap theme based on user/global setting #}
@ -89,17 +88,22 @@
{% endblock %} {% endblock %}
<div class="toasts-global d-none"> <div class="toasts-global d-none">
{% for label, messages in app.flashes() %} {% for label, messages in app.flashes() %}
{% for message in messages %} {% for message in messages %}
{{ include('_toast.html.twig', { {{ include('_toast.html.twig', {
'label': label, 'label': label,
'message': message 'message': message
}) }} }) }}
{% endfor %}
{% endfor %} {% endfor %}
{% endfor %}
</div> </div>
</turbo-frame>
{# Allow pages to request a fully reload of everything #}
{% if global_reload_needed is defined and global_reload_needed %}
<div {{ stimulus_controller('turbo/global_reload') }}></div>
{% endif %}
</turbo-frame>
{% block scripts %} {% block scripts %}
{% endblock %} {% endblock %}