PageSourceSearch

https://tbuddy.app/assets/app.products.new-B3oflYFK.js

js tbuddy.app collected 2026-10-02 01:17:07 UTC 11,682 bytes, 1 lines download raw bytes

1import{u as te,e as re,r as a,s as A,j as e,bD as se,aj as ae,ah as ie,n as le,h as o,L as ne,g as oe,P as O,ai as B}from"./index-BOoZFuWa.js";import{a as ce}from"./app-shell-BjcDR96W.js";import{c as de}from"./quota-CgfU75xi.js";import{L as ue}from"./limit-reached-sheet-DH0vbGI2.js";import{resolveTier as me}from"./tier-badge-BS_ot_P_.js";import{I as pe}from"./image-CmcXo6BU.js";import{I as xe}from"./image-plus-CtKZbUCl.js";import"./bell-heW9z5p5.js";import"./arrow-right-BB--XxhS.js";import"./at-sign-O0OVfKsi.js";import"./feedback.functions-52mFnH9m.js";import"./star-7QRc-wM9.js";import"./gift-B_HBNbrl.js";import"./users-CZw1mlml.js";import"./user-plus-B99o8SMc.js";import"./trophy-1OJ8FeBL.js";import"./crown-Daal2D_2.js";import"./shield-check-D7xSLGV9.js";import"./info-Cf7MgNsT.js";import"./search-DLg3s1M3.js";import"./house-C5aSFVfe.js";import"./list-checks-Cv4-dcGV.js";import"./shopping-bag-CcD19NSf.js";import"./megaphone-UorZ1h2H.js";import"./chevron-down-DNuUnLmP.js";function Ae(){const{user:l}=te(),g=re(),[y,F]=a.useState(""),[C,G]=a.useState(""),[j,H]=a.useState(0),[x,W]=a.useState("one_time"),[h,S]=a.useState(1),[L,K]=a.useState(""),[n,d]=a.useState([]),[R,_]=a.useState(!1),[P,I]=a.useState(1),[N,Q]=a.use
1State("free"),[T,J]=a.useState(!0),[v,V]=a.useState(""),[U,X]=a.useState(""),[b,M]=a.useState(null),z=a.useRef(null),k=a.useRef(null),q=a.useRef(null),E=a.useRef(new WeakMap);a.useEffect(()=>{l&&A.from("profiles").select("plan_tier,plan_until,premium_until").eq("id",l.id).maybeSingle().then(({data:t})=>{const r=me(t);Q(r),I(r==="ultra"?3:r==="premium"?2:1)})},[l]);async function Y(t){if(t.preventDefault(),!l)return o.error("Sign in first");if(!y.trim()||j<=0)return o.error("Add a title and price");if(!v)return o.error("Pick a category");if(x==="limited"&&(!h||h<1))return o.error("Set a stock quantity");const r=await de(l.id,"product");if(!r.ok){M({used:r.count,limit:r.limit,tier:r.tier});return}_(!0);try{let s=null,i=[],u=null,m=[];if(n.length>0){const f=await O("post-media",l.id,n[0],{kind:"product"});s=f.publicUrl,u=f.blurhash,f.publicUrl&&(i.push(f.publicUrl),m.push(f.blurhash));for(const ee of n.slice(1,3))try{const p=await O("post-media",l.id,ee,{kind:"product"});p.publicUrl&&(i.push(p.publicUrl),m.push(p.blurhash))}catch(p){p instanceof B||console.warn("extra upload failed",p)}}const{data:Z,error:D}=await A.from("products").insert({owner_id:l.id,title:y.trim(),description:C.trim()||null,price_cents:Math.round(j*100),image_url:s,image_urls:i,blurhash:u,blurhashes:m.length?m:null,kind:x,stock_qty:x==="limited"?h:null,city:L.trim()||null,chat_enabled:T,category:v,contact_phone:U.trim()||null,expires_at:new Date(Date.now()+P*30*24*3600*1e3).toISOString()}).select("id").single();if(D)throw D;o.success("Product listed!"),g({to:"/app/products/$id",params:{id:Z.id}})}catch(s){s instanceof B?o.info(s.message):o.error(s.message||"Failed to list")}finally{_(!1)}}function w(t){return t.type.startsWith("image/")?t.size>8*1024*1024?(o.error("Image too large"),!1):!0:(o.error("Only images allowed"),!1)}const $=t=>{let r=E.current.get(t);return r||(r=URL.createObjectURL(t),E.current.set(t,r)),r};return e.jsxs("div",{className:"mx-auto max-w-md",children:[e.jsx(ue,{open:!!b,onClose:()=>M(null),kind:"product",used:b?.used??0,limit:b?.limit??1,tier:b?.tier??"free"}),e.jsx(ce,{back:!0,title:"Sell a product",subtitle:"One-time, limited stock, or recurring"}),e.jsxs("form",{onSubmit:Y,className:"px-5 pb-8 space-y-3 animate-in fade-in slide-in-from-bottom-2 duration-300",children:[e.jsxs("div",{className:"block",children:[e.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:"Photos"}),e.jsx("button",{type:"button",onClick:()=>z.current?.click(),className:"mt-1 w-full aspect-video rounded-2xl border-2 border-dashed border-primary/40 bg-primary-soft/30 flex flex-col items-center justify-center text-muted-foreground text-sm overflow-hidden cursor-pointer",children:n[0]?e.jsx("img",{src:$(n[0]),className:"size-full object-cover",alt:"Cover"}):e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"size-6 mb-1 text-primary"}),e.jsx("span",{className:"text-primary font-medium",children:"Tap to add cover photo"})]})}),e.jsx("input",{ref:z,type:"file",accept:"image/jpeg,image/png",className:"hidden",onChange:t=>{const r=t.target.files?.[0];r&&w(r)&&(d(s=>(s.length===0?[r]:[r,...s.slice(1)]).slice(0,3)),t.currentTarget.value="")}}),e.jsx("input",{ref:q,type:"file",accept:"image/jpeg,image/png",className:"hidden",onChange:t=>{const r=t.target.files?.[0],s=k.current;t.currentTarget.value="",k.current=null,!(!r||s==null)&&w(r)&&d(i=>i.map((u,m)=>m===s?r:u))}}),n.length>0&&e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("p",{className:"text-[11px] font-semibold text-muted-foreground",children:["Photos (",n.length,"/3) · first is cover"]}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Use ← → to reorder"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[n.map((t,r)=>e.jsxs("div",{className:"relative aspect-square w-full rounded-xl overflow-hidden border border-border group",children:[e.jsx("img",{src:$(t),alt:"",className:"size-full object-cover"}),e.jsx("span",{className:"absolute top-1 left-1 rounded-full bg-black/70 text-white text-[11px] px-2 py-0.5 font-semibold leading-tight",children:r+1}),e.jsx("button",{type:"button",onClick:()=>d(s=>s.filter((i,u)=>u!==r)),className:"absolute top-1 right-1 size-7 rounded-full bg-black/80 text-white text-sm flex items-center justify-center shadow-md","aria-label":"Remove photo",children:"×"}),e.jsxs("div",{className:"absolute bottom-0 inset-x-0 flex items-stretch justify-between bg-black/60 text-white text-base",children:[e.jsx("button",{type:"button",disabled:r===0,onClick:()=>d(s=>{const i=s.slice();return[i[r-1],i[r]]=[i[r],i[r-1]],i}),className:"flex-1 px-2 py-2 disabled:opacity-30 active:bg-black/40","aria-label":"Move left",children:"←"}),e.jsx("button",{type:"button",onClick:()=>{k.current=r,q.current?.click()},className:"flex-1 px-2 py-2 active:bg-black/40","aria-label":"Replace photo",children:"⟳"}),e.jsx("button",{type:"button",disabled:r===n.length-1,onClick:()=>d(s=>{const i=s.slice();return[i[r+1],i[r]]=[i[r],i[r+1]],i}),className:"flex-1 px-2 py-2 disabled:opacity-30 active:bg-black/40","aria-label":"Move right",children:"→"})]})]},r)),n.length<3&&e.jsxs("label",{className:"aspect-square w-full rounded-xl border-2 border-dashed border-primary/40 bg-primary-soft/30 flex items-center justify-center text-primary curs
1or-pointer",children:[e.jsx(xe,{className:"size-8"}),e.jsx("input",{type:"file",accept:"image/jpeg,image/png",className:"hidden",onChange:t=>{const r=t.target.files?.[0];if(r){if(!w(r)){t.currentTarget.value="";return}d(s=>[...s,r].slice(0,3)),t.currentTarget.value=""}}})]})]})]})]}),e.jsx(c,{label:"Title",children:e.jsx("input",{value:y,onChange:t=>F(t.target.value),maxLength:120,required:!0,placeholder:"e.g. iPhone 13 Pro Max 256GB",className:"ds-input"})}),e.jsx(c,{label:"Category",children:e.jsx("div",{className:"grid grid-cols-4 gap-2",children:se.map(t=>e.jsxs("button",{type:"button",onClick:()=>V(t.key),className:`flex flex-col items-center justify-center gap-1 px-1 py-2.5 rounded-xl border text-[11px] font-medium transition ${v===t.key?"bg-foreground text-background border-foreground":"bg-card border-border text-muted-foreground"}`,children:[e.jsx("span",{className:"text-xl leading-none",children:t.emoji}),e.jsx("span",{className:"truncate max-w-full",children:t.label})]},t.key))})}),e.jsx(c,{label:"Description",children:e.jsx("textarea",{value:C,onChange:t=>G(t.target.value),maxLength:1e3,rows:3,placeholder:"e.g. Like new, used 6 months, includes original box and charger",className:"ds-input resize-none"})}),e.jsx(c,{label:`Price (${ae().symbol.trim()})`,children:e.jsx("input",{type:"number",min:1,value:j||"",onChange:t=>H(Number(t.target.value)),required:!0,placeholder:"e.g. 2500",className:"ds-input",inputMode:"numeric"})}),e.jsx(c,{label:"Type",children:e.jsx("div",{className:"flex gap-2",children:["one_time","limited","recurring"].map(t=>e.jsx("button",{type:"button",onClick:()=>W(t),className:`flex-1 rounded-xl border px-3 py-2 text-xs font-semibold ${x===t?"bg-foreground text-background border-foreground":"bg-card border-border"}`,children:t==="one_time"?"One-time":t==="limited"?"Limited":"Recurring"},t))})}),x==="limited"&&e.jsx(c,{label:"Stock quantity",children:e.jsx("input",{type:"number",min:1,inputMode:"numeric",value:h||"",onChange:t=>{const r=t.target.value.replace(/^0+(?=\d)/,"");if(r===""){S(0);return}const s=parseInt(r,10);S(Number.isFinite(s)?Math.max(0,s):0)},placeholder:"1",className:"ds-input"})}),e.jsx(c,{label:"Location",children:e.jsx("div",{className:"ds-input flex items-center gap-2",children:e.jsx(ie,{value:L,onChange:K,maxLength:120,placeholder:"Area, street or landmark"})})}),e.jsxs("label",{className:"flex items-start gap-3 bg-card border border-border rounded-2xl px-4 py-3",children:[e.jsx("input",{type:"checkbox",checked:T,onChange:t=>J(t.target.checked),className:"mt-0.5 size-4 accent-primary"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-semibold",children:"Let buyers chat with me directly"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:'Anyone who taps Chat will also show up in your "Buyers interested" list.'})]})]}),e.jsxs(c,{label:"Contact phone (optional)",children:[e.jsx("input",{type:"tel",inputMode:"tel",value:U,onChange:t=>X(t.target.value),placeholder:"+91 98765 43210",maxLength:32,className:"ds-input"}),e.jsx("p",{className:"mt-1 text-[10px] text-muted-foreground",children:"Buyers can tap to call you directly. Leave blank to hide."})]}),e.jsxs(c,{label:"Listing expires after",children:[e.jsx("div",{className:"flex gap-2",children:[1,2,3].map(t=>{const r=t===1?"free":t===2?"premium":"ultra",s=t===1||t===2&&N!=="free"||t===3&&N==="ultra";return e.jsxs("button",{type:"button",onClick:()=>{if(!s){o.info(`${r[0].toUpperCase()+r.slice(1)} plan unlocks ${t} months`);return}I(t)},className:`flex-1 rounded-xl border px-3 py-2 text-xs font-semibold inline-flex items-center justify-center gap-1 ${P===t?"bg-foreground text-background border-foreground":"bg-card border-border"} ${s?"":"opacity-60"}`,title:s?void 0:`Requires ${r}`,children:[!s&&e.jsx(le,{className:"size-3"}),t," ",t===1?"month":"months"]},t)})}),e.jsx("p",{className:"mt-1 text-[10px] text-muted-foreground",children:"Automatically removed after this period."}),N!=="ultra"&&e.jsx(ne,{to:"/app/premium",className:"mt-2 inline-block text-[11px] text-primary font-semibold underline",children:"Unlock longer listings · Upgrade plan"})]}),e.jsxs("button",{disabled:R,className:"mt-3 w-full rounded-2xl bg-gradient-warm text-primary-foreground font-semibold py-3.5 shadow-card disabled:opacity-60 inline-flex items-center justify-center gap-2",children:[R&&e.jsx(oe,{className:"size-4 animate-spin"})," List product"]})]}),e.jsx("style",{children:".ds-input{display:block;width:100%;border-radius:0.9rem;background:var(--card);color:var(--foreground);border:1px solid var(--border);padding:0.75rem 1rem;font-size:0.875rem;outline:none;transition:border-color .15s, box-shadow .15s} .ds-input:focus{border-color:var(--primary); box-shadow:0 0 0 3px color-mix(in oklch, var(--primary) 18%, transparent)}"})]})}function c({label:l,children:g}){return e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:l}),e.jsx("div",{className:"mt-1",children:g})]})}
1export{Ae 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.