Archived
- add uv configuration for the backend - update frontend to make auth work - add new auth endpoints - add bookmars feat - add reader feat
2 lines
5.4 KiB
JavaScript
2 lines
5.4 KiB
JavaScript
import{X as k,i as j,h as v,r,j as e}from"./index-BQiEVoRj.js";import{b as S}from"./books-BG7wMiRx.js";import{u as w,B}from"./useMediaQuery-DwhAHSnz.js";function _(){const{t:o}=k(),{id:a}=j(),s=v(),[i,p]=r.useState(null),[u,g]=r.useState(!0),[b,d]=r.useState(null),t=w(B.md),l=r.useCallback(async()=>{if(a){g(!0),d(null);try{const n=Number(a);if(Number.isNaN(n)){d(o("bookDetail.invalidId"));return}const y=await S.getBook(n);p(y)}catch(n){d(n instanceof Error?n.message:o("bookDetail.loadFailed"))}finally{g(!1)}}},[a,o]);r.useEffect(()=>{l()},[l]);const m={want_to_read:{bg:"#dbeafe",text:"#1d4ed8"},reading:{bg:"#dcfce7",text:"#16a34a"},finished:{bg:"#f3e8ff",text:"#9333ea"},dnf:{bg:"#fef3c7",text:"#b45309"}},c={maxWidth:720,margin:"0 auto",padding:t?16:24,minHeight:"100vh",background:"#f8f9fa"},h={display:"inline-flex",alignItems:"center",gap:4,padding:t?"10px 16px":"8px 16px",borderRadius:8,border:"1px solid #e5e7eb",background:"#fff",color:"#374151",fontSize:t?15:14,cursor:"pointer",marginBottom:t?16:24,minHeight:44};if(u)return e.jsxs("div",{style:c,children:[e.jsx("div",{style:{height:32,width:80,background:"#e5e7eb",borderRadius:6,marginBottom:24}}),e.jsxs("div",{style:{display:"flex",gap:t?16:24,flexDirection:t?"column":"row"},children:[e.jsx("div",{style:{width:t?140:240,height:t?210:360,background:"#e5e7eb",borderRadius:12,flexShrink:0,alignSelf:t?"center":"flex-start"}}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{height:28,background:"#e5e7eb",borderRadius:6,marginBottom:12,width:"60%"}}),e.jsx("div",{style:{height:18,background:"#e5e7eb",borderRadius:4,marginBottom:8,width:"40%"}}),e.jsx("div",{style:{height:18,background:"#e5e7eb",borderRadius:4,marginBottom:8,width:"30%"}}),e.jsx("div",{style:{height:14,background:"#e5e7eb",borderRadius:4,marginBottom:4,width:"90%"}}),e.jsx("div",{style:{height:14,background:"#e5e7eb",borderRadius:4,marginBottom:4,width:"80%"}}),e.jsx("div",{style:{height:14,background:"#e5e7eb",borderRadius:4,width:"70%"}})]})]})]});if(b||!i)return e.jsxs("div",{style:c,children:[e.jsxs("button",{onClick:()=>s("/"),style:h,children:["← ",o("bookDetail.backToLibrary")]}),e.jsxs("div",{style:{textAlign:"center",padding:t?"60px 16px":"80px 20px"},children:[e.jsx("div",{style:{fontSize:t?48:64,marginBottom:16},children:"😕"}),e.jsx("h2",{style:{fontSize:t?18:20,color:"#1f2937",marginBottom:8},children:o("bookDetail.notFound")}),e.jsx("p",{style:{color:"#6b7280",marginBottom:20},children:b||o("bookDetail.notFoundDescription")}),e.jsx("button",{onClick:()=>void l(),className:"btn",style:{padding:"12px 24px",fontSize:15,minHeight:44},children:o("common.retry")})]})]});const x=m[i.reading_status]??{bg:"#f3f4f6",text:"#6b7280"},f={year:"numeric",month:"long",day:"numeric"};return e.jsxs("div",{style:c,children:[e.jsxs("button",{onClick:()=>s("/"),style:h,children:["← ",o(t?"bookDetail.back":"bookDetail.backToLibrary")]}),e.jsxs("div",{style:{display:"flex",gap:t?20:32,flexDirection:t?"column":"row"},children:[e.jsx("div",{style:{flexShrink:0,alignSelf:t?"center":"flex-start"},children:e.jsx("div",{style:{width:t?160:240,height:t?240:360,borderRadius:12,overflow:"hidden",background:"#f0f0f0",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 20px rgba(0,0,0,0.1)"},children:i.cover_image?e.jsx("img",{src:i.cover_image,alt:i.title,style:{width:"100%",height:"100%",objectFit:"cover"}}):e.jsx("span",{style:{fontSize:t?48:80},children:"📖"})})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("h1",{style:{fontSize:t?22:28,fontWeight:700,color:"#1f2937",marginBottom:8,lineHeight:1.2},children:i.title}),i.author&&e.jsx("p",{style:{fontSize:t?16:18,color:"#4b5563",marginBottom:6},children:o("bookDetail.byAuthor",{author:i.author})}),e.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",marginBottom:16,marginTop:12},children:[e.jsx("span",{style:{background:x.bg,color:x.text,fontSize:13,fontWeight:600,padding:"4px 12px",borderRadius:999,minHeight:28,display:"inline-flex",alignItems:"center"},children:i.reading_status_display}),i.genre&&e.jsx("span",{style:{background:"#eef2ff",color:"#4f46e5",fontSize:13,padding:"4px 12px",borderRadius:999,minHeight:28,display:"inline-flex",alignItems:"center"},children:i.genre}),i.total_pages>0&&e.jsx("span",{style:{background:"#f3f4f6",color:"#6b7280",fontSize:13,padding:"4px 12px",borderRadius:999,minHeight:28,display:"inline-flex",alignItems:"center"},children:o("bookDetail.pages",{count:String(i.total_pages)})})]}),i.description&&e.jsxs("div",{style:{marginTop:20},children:[e.jsx("h3",{style:{fontSize:16,fontWeight:600,color:"#1f2937",marginBottom:8},children:o("bookDetail.description")}),e.jsx("p",{style:{fontSize:15,color:"#4b5563",lineHeight:1.7,whiteSpace:"pre-wrap"},children:i.description})]}),e.jsx("div",{style:{marginTop:24,paddingTop:16,borderTop:"1px solid #e5e7eb"},children:e.jsxs("p",{style:{fontSize:13,color:"#9ca3af"},children:[o("bookDetail.added",{date:new Date(i.created_at).toLocaleDateString(void 0,f)}),i.created_at!==i.updated_at&&` · ${o("bookDetail.updated",{date:new Date(i.updated_at).toLocaleDateString(void 0,f)})}`]})}),t&&e.jsx("div",{style:{marginTop:24},children:e.jsxs("button",{onClick:()=>s("/"),style:{width:"100%",padding:"14px 24px",borderRadius:10,border:"none",background:"#4f46e5",color:"#fff",fontSize:15,fontWeight:600,cursor:"pointer",minHeight:44},children:["← ",o("bookDetail.backToLibrary")]})})]})]})]})}export{_ as BookDetailPage};
|