PageSourceSearch

https://stasht.app/assets/EditProfile-Dxmc5TU0.js

js stasht.app collected 2026-10-01 14:23:08 UTC 12,803 bytes, 2 lines download raw bytes

1import{u as ne,j as e}from"./query-Cg3kfXWF.js";import{r}from"./router-2d4Df_P9.js";import{t as _}from"./ui-components-CZv-mgrC.js";import{S as le}from"./StackHeader-DqetOarS.js";import{C as ie,cG as G,cH as ce,cI as de,N as ue,E as me,p as D,b0 as fe,bP as pe,cz as xe,B as ge,aL as he}from"./index-4qCi1SPN.js";import{a as be}from"./timezone-CarhJoZ9.js";import{m as F,c as J,C as ye,ag as je,M as ve}from"./icons-and-animation-DhDkwEqv.js";import"./react-vendor-Dyffda3n.js";import"./radix-ui-iYcaMoVP.js";import"./utilities-BCN5r5Be.js";(function(){try{var i=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};i.SENTRY_RELEASE={id:"75f2fd9f1a8569f4053a67ef07438687a5966aa6"}}catch{}})();try{(function(){var i=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},s=new i.Error().stack;s&&(i._sentryDebugIds=i._sentryDebugIds||{},i._sentryDebugIds[s]="bea466ab-aeba-4b5d-aeaa-264056dae4f3",i._sentryDebugIdIdentifier="sentry-dbid-bea466ab-aeba-4b5d-aeaa-264056dae4f3")})()}catch{}class we{async pickImage(s="prompt"){return ie.isNativePlatform()?this.pickImageNative(s):this.pickImageWeb()}async pickImageNative(s){try{const o=s==="camera"?G.Camera:s==="library"?G.Photos:G.Prompt,m=await ce.getPhoto({quality:80,allowEditing:!0,resultType:de.Base64,source:o,width:400,height:400});return m.base64String?`data:image/jpeg;base64,${m.base64String}`:null}catch{return null}}pickImageWeb(){return new Promise(s=>{const o=document.createElement("input");o.type="file",o.accept="image/jpeg,image/png,image/webp,image/gif",o.onchange=async m=>{const f=m.target.files?.[0];if(!f){s(null);return}
1if(f.size>5*1024*1024){s(null);return}const c=new FileReader;c.onload=()=>s(c.result),c.onerror=()=>s(null),c.readAsDataURL(f)},o.oncancel=()=>s(null),o.click()})}async getUploadUrl(s="image/jpeg"){return ue.post(me.PROFILE.AVATAR_UPLOAD,{content_type:s})}async uploadToS3(s,o,m="image/jpeg"){const f=o.split(",")[1],c=atob(f),N=new Uint8Array(c.length);for(let b=0;b<c.length;b++)N[b]=c.charCodeAt(b);const P=new Blob([N],{type:m}),S=await fetch(s,{method:"PUT",body:P,headers:{"Content-Type":m}});if(!S.ok)throw new Error(`Failed to upload to S3: ${S.status}`)}getContentTypeFromDataUrl(s){const o=s.match(/^data:([^;]+);/);return o?o[1]:"image/jpeg"}}const R=new we,Te=()=>{const i=ne(),[s,o]=r.useState(null),[m,f]=r.useState(!0),[c,N]=r.useState(!1),[P,S]=r.useState(""),[b,Z]=r.useState(""),[y,q]=r.useState(""),[C,ee]=r.useState(""),[j,p]=r.useState("idle"),$=r.useRef(null),[z,M]=r.useState(""),[V,E]=r.useState(null),[I,O]=r.useState(!1),[v,U]=r.useState(""),[L,T]=r.useState(null),[B,w]=r.useState([]),[A,H]=r.useState(!1),[Q,W]=r.useState(!1),[K,x]=r.useState(null),g=r.useRef(null),k=fe.MAPBOX_ACCESS_TOKEN;r.useEffect(()=>{(async()=>{try{f(!0);const a=await D.getProfile();o(a),S(a.name||""),Z(a.email||""),q(a.stasht_username||""),ee(a.stasht_username||""),M(a.description||""),E(a.avatar_url||null),U(a.home_location||""),T(a.home_coordinates||null),g.current=a.home_location||null}catch{}finally{f(!1)}})()},[]);const te=r.useCallback(async t=>{if(t===C){p("idle");return}if(t.length<3){p("invalid");return}p("checking");try{const a=await D.checkUsernameAvailability(t);p(a.available?"available":"taken")}catch{p("idle")}},[C]);r.useEffect(()=>{const t=v?.trim()||"";if(!k||t.length<2){w([]),H(!1);return}if(t===g.current){w([]);return}const a=new AbortController,u=setTimeout(async()=>{H(!0);try{const l=await fetch(`https://api.mapbox.com/geocoding/v5/mapbox.places/${encodeURIComponent(t)}.json?access_token=${k}&types=place,locality,neighborhood&autocomplete=true&limit=5`,{signal:a.signal});if(!l.ok)throw new Error("Failed to fetch locations");const n=((await l.json()).features||[]).map(d=>({id:d.id,label:d.text||d.place_name,description:d.place_name||d.text,coordinates:d.geometry?.coordinates||[0,0]}));w(n)}catch(l){if(l.name==="AbortError")return;w([])}finally{H(!1)}},250);return()=>{clearTimeout(u),a.abort()}},[v,k]);const ae=async()=>{if(!k){x("Location service not available");return}W(!0),x(null);try{const t=await new Promise((d,oe)=>{navigator.geolocation.getCurrentPosition(d,oe,{enableHighAccuracy:!0,timeout:1e4,maximumAge:0})}),{latitude:a,longitude:u}=t.coords,l=await fetch(`https://api.mapbox.com/geocoding/v5/mapbox.places/${u},${a}.json?access_token=${k}&types=place,locality&limit=1`);if(!l.ok)throw new Error("Failed to get location name");const n=(await l.json()).features?.[0];if(n){const d=n.place_name||n.text;g.current=d,U(d),T({lat:a,lng:u}),w([])}else x("Couldn't determine location name")}catch(t){t.code===1?x("Location access denied"):t.code===2?x("Location unavailable"):t.code===3?x("Location request timed out"):x("Failed to get location")}finally{W(!1)}},se=t=>{g.current=t.description,U(t.description),T({lng:t.coordinates[0],lat:t.coordinates[1]}),w([])},X=async(t="prompt")=>{try{O(!0);const a=await R.pickImage(t);if(!a){O(!1);return}E(a);const u=R.getContentTypeFromDataUrl(a);let l,h;try{const n=await R.getUploadUrl(u);l=n.upload_url,h=n.avatar_url}catch(n){throw n}try{await R.uploadToS3(l,a,u)}catch(n){throw n}try{await D.updateProfile({avatar_url:h})}catch(n){throw n}E(h),_.success("Profile photo updated!")}catch{_.error("Failed to update profile photo"),E(s?.avatar_url||null)}finally{O(!1)}},Y=()=>{he()?X("prompt"):X("library")},re=async()=>{if(y!==C&&j!=="available"){_.error("Please fix your username before saving");return}try{N(!0);const t={name:P,stasht_username:y,description:z};if(v&&L){const u=Number(L.lat),l=Number(L.lng);t.home_location=v,t.home_coordinates={lat:u,lng:l};const{timezone_id:h,utc_offset_minutes:n}=be(u,l);t.timezone_id=h,t.utc_offset_minutes=n}const a=await D.updateProfile(t);o(a),i.setQueryData(["profile"],a),g.current=a.home_location||null,_.success("Profile updated successfully")}catch{_.error("Failed to update profile")}finally{N(!1)}};return m?e.jsx(pe,{path:xe()}):e.jsxs("div",{className:"min-h-screen pb-24 bg-background",style:{paddingTop:"var(--sat)"},"data-page":"edit-profile",children:[e.jsx(le,{title:"Edit Profile"}),e.jsx("div",{className:"px-4 sm:px-6 lg:px-8 pt-6 pb-8 mx-auto max-w-7xl",children:e.jsxs("div",{className:"flex flex-col gap-6 lg:grid lg:grid-cols-2 lg:gap-8 lg:items-start",children:[e.jsx("div",{className:"lg:sticky lg:top-28 flex justify-center",children:e.jsxs(F.div,{initial:{y:20,opacity:0}
1,animate:{y:0,opacity:1},transition:{delay:.1},className:"flex flex-col items-center",children:[e.jsxs("div",{className:"relative mb-3",children:[e.jsx("div",{className:"w-24 h-24 sm:w-28 sm:h-28 rounded-full bg-brand-gradient-radial p-1",children:e.jsxs("div",{className:"w-full h-full rounded-full bg-card flex items-center justify-center overflow-hidden relative",children:[V?e.jsx("img",{src:V,alt:"Profile",className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full bg-gradient-to-br from-orange-100 to-yellow-100 dark:from-orange-900/40 dark:to-yellow-900/40 flex items-center justify-center",children:e.jsx("span",{className:"text-4xl sm:text-5xl",children:"👤"})}),I&&e.jsx("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center rounded-full",children:e.jsx(J,{className:"w-8 h-8 text-white animate-spin"})})]})}),e.jsx(F.button,{whileTap:{scale:.9},onClick:Y,disabled:I,className:"absolute bottom-0 right-0 w-9 h-9 sm:w-10 sm:h-10 rounded-full bg-brand-gradient border-3 border-background flex items-center justify-center disabled:opacity-50",children:e.jsx(ye,{className:"w-4 h-4 sm:w-5 sm:h-5 text-white"})})]}),e.jsx("button",{onClick:Y,disabled:I,className:"text-sm font-normal text-brand disabled:opacity-50",children:I?"Uploading...":"Change Photo"})]})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs(F.div,{initial:{y:20,opacity:0},animate:{y:0,opacity:1},transition:{delay:.2},className:" bg-card/80 border border-border rounded-3xl mb-6",children:[e.jsx("div",{className:"p-4 border-b border-border",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("label",{className:"text-base text-foreground font-normal",children:"Name"}),e.jsx("input",{type:"text",value:P,onChange:t=>S(t.target.value),className:"flex-1 text-right bg-transparent border-none outline-none text-base text-foreground placeholder:text-muted-foreground",placeholder:"Demo User"})]})}),e.jsxs("div",{className:"p-4 border-b border-border",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("label",{className:"text-base text-foreground font-normal",children:"Username"}),e.jsx("input",{type:"text",value:y,onChange:t=>{const a=t.target.value.toLowerCase();if(q(a),$.current&&window.clearTimeout($.current),a===C){p("idle");return}if(a.length>0&&!/^[a-z0-9_]+$/.test(a)){p("invalid");return}if(a.length<3){p("invalid");return}$.current=window.setTimeout(()=>{te(a)},300)},className:"flex-1 text-right bg-transparent border-none outline-none text-base text-foreground placeholder:text-muted-foreground",placeholder:"username"})]}),j==="available"&&e.jsxs("p",{className:"text-xs text-green-600 mt-1 flex items-center gap-1 justify-end",children:[e.jsx(je,{className:"h-3 w-3"})," Available"]}),j==="taken"&&e.jsx("p",{className:"text-xs text-red-500 mt-1 text-right",children:"Username is already taken"}),j==="checking"&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1 text-right",children:"Checking availability..."}),j==="invalid"&&y.length>0&&e.jsx("p",{className:"text-xs text-red-500 mt-1 text-right",children:/^[a-z0-9_]+$/.test(y)?"Username must be at least 3 characters":"Only lowercase letters, numbers, and underscores are allowed"})]}),e.jsx("div",{className:"p-4 border-b border-border",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("label",{className:"text-base text-foreground font-normal",children:"Email"}),e.jsx("input",{type:"email",value:b,readOnly:!0,className:"flex-1 text-right bg-transparent border-none outline-none text-base text-muted-foreground placeholder:text-muted-foreground",placeholder:"[email protected]"})]})}),e.jsx("div",{className:"p-4 border-b border-border",children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("label",{className:"text-base text-foreground font-normal",children:"Bio"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[z.length,"/50"]})]}),e.jsx("input",{type:"text",value:z,onChange:t=>M(t.target.value),maxLength:50,className:"flex-1 text-right bg-transparent border-none outline-none text-base text-foreground placeholder:text-muted-foreground",placeholder:"Tell us about yourself"})]})}),e.jsxs("div",{className:"p-4 relative",children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ve,{className:"w-4 h-4 text-brand-500"}),e.jsx("label",{className:"text-base text-foreground font-normal",children:"Home Base"})]}),e.jsx("button",{type:"button",onClick:ae,disabled:Q,className:"text-sm text-brand-500 disabled:opacity-50",children:Q?"Getting...":"Use my location"})]}
1),e.jsx("input",{type:"text",value:v,onChange:t=>{const a=t.target.value;U(a),a!==g.current&&(T(null),g.current=null)},className:"w-full bg-transparent border border-border rounded-xl px-3 py-2 text-base text-foreground placeholder:text-muted-foreground",placeholder:"Search for a city or location..."}),K&&e.jsx("p",{className:"text-xs text-red-500",children:K}),v&&!L&&!A&&B.length===0&&e.jsx("p",{className:"text-xs text-amber-500",children:"Select a location from the suggestions to save coordinates"})]}),(A||B.length>0)&&e.jsxs("div",{className:"absolute left-4 right-4 top-full mt-1 z-10 rounded-xl border border-border bg-card overflow-hidden",children:[A&&e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 text-sm text-muted-foreground",children:[e.jsx(J,{className:"h-4 w-4 animate-spin"}),"Searching locations..."]}),!A&&B.map(t=>e.jsxs("button",{type:"button",onClick:()=>se(t),className:"w-full text-left px-4 py-3 border-b border-border last:border-b-0",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:t.label}),e.jsx("div",{className:"text-xs text-muted-foreground",children:t.description})]},t.id))]})]})]}),e.jsx(F.div,{initial:{y:20,opacity:0},animate:{y:0,opacity:1},transition:{delay:.3},children:e.jsx(ge,{variant:"gradient",size:"modal",onClick:re,disabled:c||y!==C&&j!=="available",className:"rounded-2xl p-4",children:c?"Saving...":"Save Changes"})})]})]})})]})};export{Te as default};
2//# sourceMappingURL=EditProfile-Dxmc5TU0.js.map

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.