PageSourceSearch

https://stromsundsgratistidning.se/assets/foreningsnytt.redigera-CGWSfDmR.js

js stromsundsgratistidning.se collected 2026-10-04 07:15:24 UTC 5,651 bytes, 1 lines download raw bytes

1import{r as n,j as e,B as u,f as U,L as o,I as g,T as E,X as P,s as m,t as i}from"./index-EhlWxbWg.js";import{P as R}from"./PageShell-DH7nPkNN.js";import{A as B,a as V,b as X,c as $,d as q,e as H,f as G,g as J,h as M}from"./alert-dialog-CqlQPp94.js";import{a as O}from"./image-compress-BCpMMBkY.js";import{A as Q}from"./arrow-left-BGb0suHi.js";import{K as W}from"./key-round-CVNrT6b5.js";import{L as j,C as S}from"./loader-circle-C7FhLghT.js";import{T}from"./trash-2-CjWtyaik.js";import"./BreakingBanner-BO31IdU1.js";function oe(){const[p,b]=n.useState(""),[v,y]=n.useState(!1),[l,_]=n.useState(null),[t,c]=n.useState({association_name:"",headline:"",content:"",contact_email:""}),[x,f]=n.useState(null),[N,h]=n.useState(null),[w,k]=n.useState(!1),[C,A]=n.useState(!1);function I(a){c({association_name:a.association_name,headline:a.headline,content:a.content,contact_email:a.contact_email??""}),f(a.image_url),h(null)}async function F(a){if(a.preventDefault(),!!p.trim()){y(!0);try{const{data:s,error:r}=await m.rpc("get_foreningsnytt_by_code",{p_edit_code:p.trim().toUpperCase()});if(r)throw r;const d=Array.isArray(s)?s[0]:s;if(!d){i.error("Felaktig redigeringskod.");return}_(d),I(d)}catch(s){const r=s instanceof Error?s.message:"Kunde inte verifiera koden.";i.error(r)}finally{y(!1)}}}async function L(){if(l){k(!0);try{let a=x;if(N){const r=await O(N),d=r.name.split(".").pop()?.toLowerCase().replace(/[^a-z0-9]/g,"")||"jpg",D=`${crypto.randomUUID()}.${d}`,z=await m.storage.from("foreningsnytt").upload(D,r,{cacheControl:"3600",upsert:!1,contentType:r.type});if(z.error)throw z.error;a=m.storage.from("foreningsnytt").getPublicUrl(D).data.publicUrl}const{error:s}=await m.rpc("update_foreningsnytt_by_code",{p_edit_code:l.edit_code,p_association_name:t.association_name,p_headline:t.headline,p_content:t.content,p_contact_email:t.contact_email||null,p_image_url:a});if(s)throw s;i.success("Ändringarna är sparade. Inlägget granskas igen."),f(a),h(null)}catch(a){const s=a instanceof Error?a.message:"Kunde inte spara.";i.error(s)}finally{k(!1)}}}async function K(){if(l){A(!0);try{const{data:a,error:s}=await m.rpc("delete_foreningsnytt_by_code",{p_edit_code:l.edit_code});if(s)throw s;if(!a){i.error("Kunde inte ta bort inlägget.");return}i.success("Inlägget är borttaget."),_(null),b("")}catch(a){const s=a instanceof Error?a.message:"Kunde inte ta bort.";i.error(s)}finally{A(!1)}}}return e.jsxs(R,{title:"Redigera inlägg",eyebrow:"Föreningsnytt",children:[e.jsx("div",{className:"mb-6",children:e.jsx(u,{asChild:!0,variant:"ghost",size:"sm",children:e.jsxs(U,{to:"/foreningsnytt",children:[e.jsx(Q,{className:"size-4"})," Tillbaka"]})})}),l?e.jsxs("div",{className:"max-w-2xl mx-auto space-y-4",children:[e.jsx("div",{className:"rounded-md bg-muted border p-3 text-sm text-muted-foreground",children:"Ändringar skickas tillbaka för granskning innan de syns publikt."}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(o,{children:"Föreningens namn *"}),e.jsx(g,{value:t.association_name,onChange:a=>c({...t,association_name:a.target.value})})]}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(o,{children:"Rubrik *"}),e.jsx(g,{value:t.headline,onChange:a=>c({...t,headline:a.target.value})})]}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(o,{children:"Innehåll *"}),e.jsx(E,{rows:6,value:t.content,onChange:a=>c({...t,content:a.target.value})})]}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(o,{children:"Kontakt-e-post"}),e.jsx(g,{type:"email",value:t.contact_email,onChange:a=>c({...t,contact_email:a.target.value})})]}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(o,{children:"Bild"}),x&&e.jsxs("div",{className:"relative w-40 h-40 border bg-muted overflow-hidden",children:[e.jsx("img",{src:x,alt:"",className:"w-full h-full object-cover"}),e.jsx("button",{type:"button",onClick:()=>f(null),className:"absolute top-1 right-1 bg-foreground text-background rounded-full p-1",children:e.jsx(P,{className:"size-3"})})]}),e.jsx(g,{type:"file",accept:"image/*",onChange:a=>h(a.target.files?.[0]??null)})]}),e.jsxs("div",{className:"flex justify-between pt-4 rule-top",children:[e.jsxs(B,{children:[e.jsx(V,{asChild:!0,children:e.jsxs(u,{variant:"outline",className:"text-destructive border-destructive/40 hover:bg-destructive/10",children:[e.jsx(T,{className:"size-4"})," Ta bort inlägg"]})}),e.jsxs(X,{children:[e.jsxs($,{children:[e.jsx(q,{children:"Ta bort inlägget?"}),e.jsx(H,{children:"Detta går inte att ångra."})]}),e.jsxs(G,{children:[e.jsx(J,{children:"Avbryt"}),e.jsxs(M,{onClick:K,disabled:C,className:"bg-destructive text-destructive-foreground",children:[C?e.jsx(j,{className:"size-4 animate-spin"}):e.jsx(T,{className:"size-4"}),"Ta bort"]})]})]})]}),e.jsxs(u,{onClick:L,disabled:w,className:"bg-primary text-primary-foreground",children:[w?e.jsx(j,{className:"size-4 animate-spin"}):e.jsx(S,{className:"size-4"}),"Spara ändringar"]})]})]}
1):e.jsxs("form",{onSubmit:F,className:"max-w-md mx-auto space-y-4 bg-card border p-6",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(W,{className:"size-4"})," Ange din redigeringskod"]}),e.jsxs("div",{className:"grid gap-1.5",children:[e.jsx(o,{children:"Redigeringskod"}),e.jsx(g,{value:p,onChange:a=>b(a.target.value.toUpperCase()),placeholder:"XF39A2",maxLength:6,className:"font-mono tracking-[0.3em] uppercase",required:!0})]}),e.jsxs(u,{type:"submit",disabled:v,className:"w-full bg-primary text-primary-foreground",children:[v?e.jsx(j,{className:"size-4 animate-spin"}):e.jsx(S,{className:"size-4"}),"Verifiera och öppna"]})]})]})}export{oe as component};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.