PageSourceSearch

https://classmate-vuive.com/assets/LanglabDictationManagement-20c02786.js

js classmate-vuive.com collected 2026-10-08 16:08:15 UTC 15,335 bytes, 1 lines download raw bytes

1import{b as Ie,a as o,j as t,F as $e}from"./index-7a84a097.js";import{l as je,r as l}from"./vendor-56877fa0.js";import{u as Fe,a as Pe}from"./useDictationBookmark-17c00d83.js";import{u as Oe}from"./CheckPermissions-afd20e60.js";import{F as He}from"./data-f4081293.js";import{H as _e}from"./Header-77bf3a82.js";import{D as Ke,g as Ge}from"./fixedData-084c7640.js";import{T as le}from"./trash-2-c05bd201.js";import{A as Ve}from"./arrow-left-3cbec197.js";import{B as We}from"./bookmark-862a6966.js";import{X as Ze}from"./x-f4d47a47.js";import{B as Xe}from"./bookmark-minus-879dc6eb.js";import"./chart-libs-b4df5823.js";import"./menu-7e7bb316.js";import"./user-00eae526.js";const ut=()=>{const ie=je(),h=Ie(e=>e.user.user),O=Oe(h,He.EDIT_VOCAB_BANK),[c,ce]=l.useState(O?"dictation-bank":"your-input"),{useDictationsByUser:H,deleteDictationMutation:de,deleteDictationsMutation:ue,updateDictationMutation:_}=Fe({user:h}),{useBookmark:me,useBookmarkedDictations:he,removeBookmarkMutation:K}=Pe({user:h}),k=me(),G=k.data,{data:f,isLoading:V,refetch:C}=H("admin"),{data:g,isLoading:W,refetch:D}=H(h==null?void 0:h.email),{data:A,isLoading:M,refetch:pe}=he();l.useEffect(()=>{console.log("=== BOOKMARKED DICTATIONS DEBUG ==="),console.log("User:",h==null?void 0:h.email),console.log("isLoadingBookmarks:",M),console.log("bookmarkedDictations:",A),console.log("bookmarkData:",G),console.log("===================================")},[A,M,h,G]);const fe=c==="dictation-bank"?V:c==="bookmarks"&&(M||k.isLoading||V)||W,[i,b]=l.useState(new Set),[ge,R]=l.useState(!1),[Z,X]=l.useState(null),[v,Y]=l.useState("Select topic"),[w,q]=l.useState("Select Difficulty"),[T,J]=l.useState("a-z"),[Q,be]=l.useState(Math.random()),[x,z]=l.useState(""),[xe,ye]=l.useState("all"),[y,ee]=l.useState("all"),[U,te]=l.useState(null),[ae,se]=l.useState(!1),[ke,re]=l.useState(!1),[L,I]=l.useState(20),ve=20,E=l.useRef(null),$=e=>e.trim().replace(/[-_]/g," ").split(/\s+/).filter(Boolean).map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" "),we=Ke.map(e=>({value:e.name,label:e.name})),Ne=e=>{let r=[...e];if(x&&x.trim()!==""){const a=x.toLowerCase().trim();r=r.filter(s=>{var n,u,m,N,S,ne,oe;return!!((n=s.originalSentence)!=null&&n.toLowerCase().includes(a)||(u=s.title)!=null&&u.toLowerCase().includes(a)||(N=(m=s.sentenceMetadata)==null?void 0:m.topic)!=null&&N.toLowerCase().includes(a)||(ne=(S=s.sentenceMetadata)==null?void 0:S.cefrLevel)!=null&&ne.toLowerCase().includes(a)||(oe=s.subCategories)!=null&&oe.some(Ue=>Ue.toLowerCase().includes(a)))})}return v&&v!=="Select topic"&&(r=r.filter(a=>{var s,n;return((n=(s=a.sentenceMetadata)==null?void 0:s.topic)==null?void 0:n.toLowerCase())===v.toLowerCase()})),w&&w!=="Select Difficulty"&&(r=r.filter(a=>{var n;const s=Ge(w);return((n=a.sentenceMetadata)==null?void 0:n.cefrLevel)&&s.includes(a.sentenceMetadata.cefrLevel)})),y&&y!=="all"&&(r=r.filter(a=>{const s=a.isRepeated===!0;return y==="true"?s:y==="false"?!s:!0})),Se(r,T)},Se=(e,r)=>{const a=[...e];switch(r){case"a-z":return a.sort((s,n)=>(s.title||"").localeCompare(n.title||""));case"z-a":return a.sort((s,n)=>(n.title||"").localeCompare(s.title||""));case"shortest":return a.sort((s,n)=>{var u,m;return(((u=s.originalSentence)==null?void 0:u.length)||0)-(((m=n.originalSentence)==null?void 0:m.length)||0)});case"longest":return a.sort((s,n)=>{var u,m;return(((u=n.originalSentence)==null?void 0:u.length)||0)-(((m=s.originalSentence)==null?void 0:m.length)||0)});case"newest":return a.sort((s,n)=>new Date(n.createdAt||0).getTime()-new Date(s.createdAt||0).getTime());case"oldest":return a.sort((s,n)=>new Date(s.createdAt||0).getTime()-new Date(n.createdAt||0).getTime());case"random":return a.sort((s,n)=>{var N,S;const u=((((N=s.id)==null?void 0:N.charCodeAt(0))||0)+Q)%1,m=((((S=n.id)==null?void 0:S.charCodeAt(0))||0)+Q)%1;return u-m});default:return a}},Ce=e=>{e==="random"&&be(Math.random()),J(e)},p=l.useMemo(()=>c==="dictation-bank"?(f==null?void 0:f.data)||[]:c==="bookmarks"?A||[]:(g==null?void 0:g.data)||[],[c,f==null?void 0:f.data,g==null?void 0:g.data,A]),j=l.useMemo(()=>{if(!(p!=null&&p.length))return[];const e=new Set;return p.forEach(r=>{var a,s;(s=(a=r.sentenceMetadata)==null?void 0:a.topic)!=null&&s.trim()&&e.add(r.sentenceMetadata.topic.trim())}),Array.from(e).filter(r=>r.length>0).sort((r,a)=>$(r).localeCompare($(a))).map(r=>({value:r,label:$(r)}))}
1,[p]),d=Ne(p),De=l.useMemo(()=>d.slice(0,L),[d,L]),B=L<d.length,F=l.useCallback(()=>{if(!E.current||!B)return;const{scrollTop:e,scrollHeight:r,clientHeight:a}=E.current;r-e-a<100&&I(s=>Math.min(s+ve,d.length))},[B,d.length]);l.useEffect(()=>{const e=E.current;if(e)return e.addEventListener("scroll",F),()=>e.removeEventListener("scroll",F)},[F]),l.useEffect(()=>{b(new Set),Y("Select topic"),q("Select Difficulty"),J("a-z"),z(""),ye("all"),ee("all"),I(20)},[c]),l.useEffect(()=>{I(20)},[v,w,T,x,xe,y]);const P=e=>{ce(e)},Ae=e=>{b(r=>{const a=new Set(r);return a.has(e)?a.delete(e):a.add(e),a})},Le=()=>{b(i.size===d.length?new Set:new Set(d.map(e=>e.id)))},Ee=e=>{X(e),R(!0)},Be=async()=>{if(i.size===0){alert("Please select dictations to delete");return}if(window.confirm(`Delete ${i.size} dictations?`))try{(await ue.mutateAsync(Array.from(i))).status===200&&(alert(`Deleted ${i.size} dictations`),b(new Set),c==="dictation-bank"?await C():await D())}catch(e){alert(`Error: ${e instanceof Error?e.message:"Unknown"}`)}},Me=async()=>{if(Z)try{(await de.mutateAsync(Z)).status===200&&(R(!1),X(null),c==="dictation-bank"?await C():await D())}catch(e){alert(`Error: ${e instanceof Error?e.message:"Unknown"}`)}},Re=async(e,r)=>{te(e);try{(await _.mutateAsync({input:{id:e,isRepeated:!r}})).status===200&&(c==="dictation-bank"?await C():await D())}catch(a){alert(`Error updating dictation: ${a instanceof Error?a.message:"Unknown"}`)}finally{te(null)}},Te=async()=>{if(i.size===0){alert("Please select dictations to update");return}se(!0);try{const e=Array.from(i).map(s=>{const n=d.find(m=>m.id===s),u=!(n!=null&&n.isRepeated);return _.mutateAsync({input:{id:s,isRepeated:u}})});(await Promise.all(e)).filter(s=>s.status===200).length>0&&(b(new Set),c==="dictation-bank"?await C():await D())}catch(e){alert(`Error updating dictations: ${e instanceof Error?e.message:"Unknown"}`)}finally{se(!1)}},ze=async()=>{var r;if(i.size===0){alert("Please select dictations to unbookmark");return}if(window.confirm(`Remove bookmark for ${i.size} selected dictations?`)){re(!0);try{const a=Array.from(i);for(const s of a)try{const n=await K.mutateAsync(s);if(n.status!==200)throw new Error(n.message||"Failed to remove bookmark")}catch(n){console.error(`Error removing bookmark for ${s}:`,n)}b(new Set),await Promise.allSettled([pe(),(r=k.refetch)==null?void 0:r.call(k)]),alert(`Successfully updated bookmarks for ${a.length} dictations`)}catch(a){console.error("Error removing bookmarks:",a),alert(`Failed to remove bookmarks: ${a instanceof Error?a.message:"Unknown error"}`)}finally{re(!1)}}};return o("div",{className:"min-h-screen bg-gray-100",children:[t(_e,{}),o("div",{className:"p-2 pt-24 text-[13px] max-w-[1100px] mx-auto",children:[o("div",{className:"mb-6",children:[o("div",{className:"flex items-center gap-4 mb-6 border-b border-gray-200",children:[t("button",{onClick:()=>ie("/langlabDictation"),className:"flex items-center gap-2 px-3 py-2 text-gray-700 hover:text-gray-900 hover:bg-gray-100 rounded-lg transition-colors mb-[-1px]",children:t(Ve,{className:"w-5 h-5"})}),o("div",{className:"flex gap-4",children:[O&&t("button",{onClick:()=>P("dictation-bank"),className:`px-4 py-2 font-medium ${c==="dictation-bank"?"text-blue-600 border-b-2 border-blue-600":"text-gray-600"}`,children:"Dictation Bank"}),t("button",{onClick:()=>P("your-input"),className:`px-4 py-2 font-medium ${c==="your-input"?"text-blue-600 border-b-2 border-blue-600":"text-gray-600"}`,children:"Your Input"}),o("button",{onClick:()=>P("bookmarks"),className:`px-4 py-2 font-medium flex items-center gap-2 ${c==="bookmarks"?"text-blue-600 border-b-2 border-blue-600":"text-gray-600"}`,children:[t(We,{className:"w-4 h-4"}),"Bookmarks"]})]})]}),p.length>0&&o("div",{className:"bg-white p-4 rounded-lg shadow-sm mb-4",children:[t("div",{className:"mb-4",children:o("div",{className:"relative",children:[t("input",{type:"text",value:x,onChange:e=>z(e.target.value),placeholder:"Search by sentence, title, topic, or difficulty...",className:"w-full p-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),x&&t("button",{onClick:()=>z(""),className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600",children:t(Ze,{className:"w-5 h-5"})})]})}),o("div",{className:"grid grid-cols-2 gap-3 mb-3",children:[t("div",{children:o("select",{value:v,onCh
1ange:e=>Y(e.target.value),className:"w-full p-3 border border-gray-300 rounded-lg bg-white text-sm",disabled:!j.length,children:[t("option",{value:"Select topic",children:j.length?"Select topic":"No topics"}),j.map(e=>t("option",{value:e.value,children:e.label},e.value))]})}),t("div",{children:o("select",{value:w,onChange:e=>q(e.target.value),className:"w-full p-3 border border-gray-300 rounded-lg bg-white text-sm",children:[t("option",{value:"Select Difficulty",children:"Select Difficulty"}),we.map(e=>t("option",{value:e.value,children:e.label},e.value))]})})]}),o("div",{className:"grid grid-cols-3 gap-3 mb-3",children:[t("div",{children:o("select",{value:T,onChange:e=>Ce(e.target.value),className:"w-full p-3 border border-gray-300 rounded-lg bg-white text-sm",children:[t("option",{value:"a-z",children:"A - Z"}),t("option",{value:"z-a",children:"Z - A"}),t("option",{value:"shortest",children:"Shortest"}),t("option",{value:"longest",children:"Longest"}),t("option",{value:"newest",children:"Newest"}),t("option",{value:"oldest",children:"Oldest"}),t("option",{value:"random",children:"Random"})]})}),t("div",{children:o("select",{value:y,onChange:e=>ee(e.target.value),className:"w-full p-3 border border-gray-300 rounded-lg bg-white text-sm",children:[t("option",{value:"all",children:"All Repeated Status"}),t("option",{value:"true",children:"🔁 Is Repeated"}),t("option",{value:"false",children:"➡️ Not Repeated"})]})})]})]}),d.length>0&&o("div",{className:"flex items-center justify-between bg-white p-4 rounded-lg shadow-sm",children:[o("div",{className:"flex items-center gap-4",children:[t("button",{onClick:Le,className:"px-4 py-2 bg-gray-100 text-gray-700 rounded hover:bg-gray-200",children:i.size===d.length?"Deselect All":"Select All"}),o("span",{className:"text-sm text-gray-600",children:[i.size," of ",d.length]})]}),o("div",{className:"flex gap-2 items-center",children:[c==="bookmarks"&&i.size>0&&o("button",{onClick:ze,disabled:i.size===0||ke||K.isPending,className:"px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 disabled:opacity-50 flex items-center gap-2 text-sm",children:[t(Xe,{className:"w-4 h-4"}),"(",i.size,")"]}),c!=="bookmarks"&&i.size>0&&o("button",{onClick:()=>Te(),disabled:ae,className:"px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 disabled:opacity-50 flex items-center gap-2 text-sm",title:"Toggle repeated status for selected dictations",children:[ae?t("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white"}):"🔄","Toggle Repeated"]}),c!=="bookmarks"&&o("button",{onClick:Be,disabled:!i.size,className:"px-4 py-2 bg-red-500 text-white rounded hover:bg-red-600 disabled:opacity-50 flex items-center gap-2",children:[t(le,{className:"w-4 h-4"}),"(",i.size,")"]})]})]})]}),t("div",{className:"bg-white rounded-lg shadow-sm flex flex-col",style:{height:"calc(100vh - 400px)",minHeight:"500px"},children:fe?o("div",{className:"flex items-center justify-center py-12 flex-1",children:[t("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"}),t("span",{className:"ml-3",children:"Loading..."})]}):d.length===0?t("div",{className:"text-center py-12 text-gray-600 flex-1 flex items-center justify-center",children:c==="dictation-bank"?"No dictations in bank":c==="bookmarks"?"No bookmarked dictations yet":"No dictations in input"}):t($e,{children:o("div",{ref:E,className:"divide-y overflow-y-auto flex-1",children:[De.map(e=>{var r,a,s,n;return t("div",{className:"p-4 hover:bg-gray-50",children:o("div",{className:"flex items-start gap-4",children:[t("input",{type:"checkbox",checked:i.has(e.id),onChange:()=>Ae(e.id),className:"mt-1 w-4 h-4 text-blue-600 rounded"}),t("div",{className:"flex-1",children:o("div",{className:"flex justify-between items-start gap-4",children:[o("div",{className:"flex-1",children:[t("h3",{className:"text-lg font-semibold",children:e.title}),t("p",{className:"text-sm text-gray-600 mt-2",children:e.originalSentence}),o("div",{className:"flex flex-wrap gap-2 mt-2",children:[t("span",{className:"px-2 py-1 bg-blue-100 text-blue-800 text-xs rounded",children:e.difficulty}),((r=e.sentenceMetadata)==null?void 0:r.cefrLevel)&&t("span",{className:"px-2 py-1 bg-green-100 text-green-800 text-xs rounded",children:e.sentenceMetadata.cefrLevel}),((a=e.sentenceMetadata)==null?void 0:a.topic)&&t("span",{className:"px-2 py-1 bg-purple-100 text-purple-800 text-xs rounded",children:e.sentenceMetadata.topic}),((s=e.sentenceMetadata)==null?void 0:s.numberOfWords)&&o("span",{className:"px-2 py-1 bg-gray-100 text-xs rounded",children:[e.sentenceMetadata.numberOfWords," words"]})]}),((n=e.sentenceMetadata)==null?void 0:n.vietnameseTranslation)&&t("p",{className:"text-xs text-gray-500 mt-2 italic",children:e.sentenceMetadata.vietnameseTranslation})]}),o("div",{className:"flex gap-2 flex-shrink-0",children:[o("div",{className:"flex flex-col items-center gap-1",title:e.isRepeated?"Click to mark as not repeated":"Click to mark as repeated",children:[t("label",{className:"text-xs font-medium text-gray-700 whitespace-nowrap",children:"Repeated"}),t("input",{type:"checkbox",checked:e.isRepeated||!1,onChange:()=>Re(e.id,e.isRepeated||!1),disabled:U===e.id,className:`w-5 h-5 rounded cursor-pointer ${U===e.id?"opacity-50 cursor-not-allowed":e.isRepeated?"text-green-600 bg-green-50":"text-gray-400"}`}),U===e.id&&t("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-blue-600"})]}),t("button",{onClick:()=>Ee(e.id),className:"p-2 text-red-600 hover:bg-red-50 rounded",children:t(le,{className:"w-4 h-4"})})]})]})})]})},e.id)}),B&&t("div",{className:"flex justify-center items-center py-6",children:o("div",{className:"text-sm text-gray-500",children:["Scroll to load more... (",L," of ",d.length,")"]})}),!B&&d.length>0&&o("div",{className:"flex justify-center items-center py-6 text-sm text-gray-500",children:["End of list (",d.length," total)"]})]})})})]}),ge&&t("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:o("div",{className:"bg-white rounded-lg p-6 max-w-md w-full",children:[t("h3",{className:"text-lg font-semibold mb-4",children:"Confirm Delete"}),t("p",{className:"text-gray-600 mb-6",children:"Delete this dictation? This cannot be undone."}),o("div",{className:"flex gap-3 justify-end",children:[t("button",{onClick:()=>R(!1),className:"px-4 py-2 bg-gray-100 rounded",children:"Cancel"}),t("button",{onClick:Me,className:"px-4 py-2 bg-red-500 text-white rounded",children:"Delete"})]})]})})]})};export{ut as default};

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.