| | @@ -0,0 +1,39 @@ |
| 1 | +{% comment %}
|
| 2 | +HTMX-based live reload detection for Fossil repository changes.
|
| 3 | +Include on pages that should auto-detect when the .fossil file changes.
|
| 4 | +Polls every 30 seconds and shows a banner if the repo has been updated.
|
| 5 | +{% endcomment %}
|
| 6 | +{% if fossil_repo %}
|
| 7 | +<div id="live-reload-banner" class="hidden fixed top-16 left-0 right-0 z-40 bg-brand/90 text-white text-sm text-center py-2 px-4"
|
| 8 | + x-data="{ show: false }"
|
| 9 | + x-show="show"
|
| 10 | + x-transition>
|
| 11 | + <div class="flex items-center justify-center gap-3">
|
| 12 | + <svg class="h-4 w-4 animate-pulse" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
|
| 13 | + <path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0l3.181 3.183a8.25 8.25 0 0013.803-3.7M4.031 9.865a8.25 8.25 0 0113.803-3.7l3.181 3.182" />
|
| 14 | + </svg>
|
| 15 | + <span>Repository updated</span>
|
| 16 | + <button onclick="location.reload()" class="underline font-semibold">Refresh</button>
|
| 17 | + <button @click="show = false" class="ml-2 opacity-70 hover:opacity-100">×</button>
|
| 18 | + </div>
|
| 19 | +</div>
|
| 20 | +<script>
|
| 21 | + (function() {
|
| 22 | + let lastCount = {{ fossil_repo.checkin_count }};
|
| 23 | + setInterval(function() {
|
| 24 | + fetch('{% url "fossil:timeline" slug=project.slug %}?page=1&type=ci', { headers: { 'HX-Request': 'true' } })
|
| 25 | + .then(r => r.text())
|
| 26 | + .then(html => {
|
| 27 | + // Count entries in the response as a quick proxy for "has changed"
|
| 28 | + const matches = html.match(/tl-row/g);
|
| 29 | + const count = matches ? matches.length : 0;
|
| 30 | + if (count > 0 && count !== lastCount) {
|
| 31 | + document.querySelector('#live-reload-banner')?.__x?.$data && (document.querySelector('#live-reload-banner').__x.$data.show = true);
|
| 32 | + lastCount = count;
|
| 33 | + }
|
| 34 | + })
|
| 35 | + .catch(() => {});
|
| 36 | + }, 30000);
|
| 37 | + })();
|
| 38 | +</script>
|
| 39 | +{% endif %}
|