Persist expand diffs state

This commit is contained in:
Ondřej 2023-08-21 13:43:42 +02:00
parent 64e2f4d622
commit edec2f4120
2 changed files with 3 additions and 1 deletions

View file

@ -0,0 +1 @@
(()=>{function d(t){let e=()=>{let n,l=localStorage;return t.interceptor((r,i,s,a,m)=>{let o=n||`_x_${a}`,u=f(o,l)?g(o,l):r;return s(u),t.effect(()=>{let c=i();p(o,c,l),s(c)}),u},r=>{r.as=i=>(n=i,r),r.using=i=>(l=i,r)})};Object.defineProperty(t,"$persist",{get:()=>e()}),t.magic("persist",e),t.persist=(n,{get:l,set:r},i=localStorage)=>{let s=f(n,i)?g(n,i):l();r(s),t.effect(()=>{let a=l();p(n,a,i),r(a)})}}function f(t,e){return e.getItem(t)!==null}function g(t,e){return JSON.parse(e.getItem(t,e))}function p(t,e,n){n.setItem(t,JSON.stringify(e))}document.addEventListener("alpine:init",()=>{window.Alpine.plugin(d)});})();

View file

@ -18,10 +18,11 @@
src="https://plausible.nolog.cz/js/plausible.js"
></script>
<script src="{{ url_for('static', filename='htmx@1.9.4.min.js') }}"></script>
<script defer src="{{ url_for('static', filename='alpinejs-persist@3.12.3.min.js') }}"></script>
<script defer src="{{ url_for('static', filename='alpinejs@3.12.3.min.js') }}"></script>
{% block head %}{% endblock %}
</head>
<body hx-boost="true" x-data="{ expandDiffs: false }">
<body hx-boost="true" x-data="{ expandDiffs: $persist(false) }">
<header class="py-4 bg-white {% block header_class %}border-b{% endblock %}">
<div class="container flex flex-wrap items-center gap-x-8 gap-y-2">
<a href="/" class="text-inherit">