2 lines
9.0 KiB
Plaintext
2 lines
9.0 KiB
Plaintext
import{r as z,j as t,a as v}from"./index-D3mqsRyr.js";import{a as _}from"./index-BbG2BJY6.js";import{_ as g}from"./lodash-D1Hd1xdK.js";import{l as k}from"./commentHelpers-BV1Y8Iwv.js";const C=({config:n={},replyTo:i=null,commentId:o=null,comment_text:e="",saveCallback:m=null,cancelCallback:d=null,changeTotal:a=null})=>{const[r,l]=z.useState(e),s=c=>l(c.target.value),u=()=>{_.post("/central-comments/create",{parent_id:i,comment_text:r,comment_url:n.comment_url}).then(c=>{if(!c.data.success){console.error(c.data.error);return}m&&m(c.data.data),a&&a(1),l("")})},p=()=>{_.post("/central-comments/edit",{comment_id:o,comment_text:r,comment_url:n.comment_url}).then(c=>{if(!c.data.success){console.error(c.data.error);return}m&&m(c.data.data),l("")})},h=()=>{d&&d()},x=i?"Válasz írása":o?"Hozzászólás szerkesztése":"Új hozzászólás";return t.jsxs("form",{className:"mb-6 mt-3",children:[t.jsx("textarea",{className:"m-commentBlock__textarea mb-3",value:r,onChange:s,placeholder:x}),t.jsxs("div",{className:"d-flex align-items-center justify-content-between",children:[r&&r.trim().length?t.jsx("input",{type:"button",value:"Hozzászólás "+(o?"módosítása":"küldése"),onClick:o?p:u,className:"m-button -colorBgPrimary -colorInversePrimary -hoverPrimary -fontWeightSeeded d-inline-block text-center"}):t.jsx("input",{type:"button",value:"Hozzászólás "+(o?"módosítása":"küldése"),disabled:!0,className:"m-button -colorBgPrimary -disabled -fontWeightSeeded d-inline-block text-center"}),d?t.jsx("a",{onClick:h,className:"a-link -primaryHoverEffect -fontSize-14",children:"Mégsem"}):""]})]})},y=({config:n={},comment:i={},changeTotal:o=null})=>{const[e,m]=z.useState({repliesDisplayed:!1,repliedCurrently:!1,comment:i,addedComments:[]}),d=e.comment.user&&e.comment.user.name?e.comment.user.name:"Törölt felhasználó",a=new Date(e.comment.created_at).toLocaleString("HU-hu"),r=e.comment.user&&e.comment.user.sso_id&&e.comment.user.sso_id===n.user_sso_id,l=()=>{m({...e,repliesDisplayed:!e.repliesDisplayed,addedComments:[]})},s=()=>m({...e,repliedCurrently:!0}),u=()=>m({...e,repliedCurrently:!1}),p=()=>m({...e,editedCurrently:!0}),h=()=>m({...e,editedCurrently:!1}),x=async()=>{if(e.editedCurrently=!1,!window.confirm("Biztos törlöd a hozzászólásod?"))return;const f=await _.get("/central-comments/delete",{params:{comment_id:e.comment.id}});if(f.data.success){m({...e,comment:{...e.comment,deleted:!0}}),o&&o(-1);return}console.error(f.data.error)},c=f=>{f&&(e.comment.number_of_replies++,e.repliesDisplayed&&e.addedComments.push(f)),e.repliedCurrently=!1,m(e)},j=f=>{f&&f.comment&&(e.comment={...e.comment,comment:f.comment}),h()};return t.jsxs("div",{className:"m-comment",children:[t.jsxs("div",{className:"d-flex align-items-start",children:[t.jsx("div",{className:"pr-4 pr-md-5",children:t.jsx("div",{className:"m-comment__image d-flex justify-content-center align-items-center",children:t.jsx("i",{className:"a-icon -fontSize-18 -colorInversePrimary fas fa-user"})})}),t.jsxs("div",{className:"w-100",children:[t.jsxs("div",{className:"mb-3 d-flex align-items-center",children:[t.jsx("strong",{className:"a-text -fontFamilyPrimary -fontSize-14 -fontColorPrimary -fontWeightAccentuated mr-2",children:d}),t.jsx("span",{className:"a-text -fontFamilyPrimary -fontSize-14 -fontColorSenary",children:a})]}),e.comment.deleted||e.comment.moderation&&!r?t.jsx("p",{className:"m-comment__text -deleted my-6",children:e.comment.deleted?"Törölt hozzászólás":"Moderált hozzászólás"}):t.jsxs("p",{className:"m-comment__text my-6",children:[e.comment.comment,e.comment.moderation||e.comment.user&&e.comment.user.moderation?t.jsx("strong",{className:"m-comment__highlighted -moderated d-block mt-2",children:"Ez a hozzászólás moderálásra került!"}):""]}),(e.comment.number_of_replies||n.user_sso_id)&&t.jsxs("div",{className:"d-flex justify-content-between align-items-center mt-3",children:[e.comment.number_of_replies?t.jsxs("a",{onClick:l,className:"m-comment__more a-link -fontWeightAccentuated -fontColorQuaternary -fontSize-14 text-nowrap d-flex align-items-center",children:[t.jsx("svg",{className:`m-comment__svg ${e.repliesDisplayed?"-opened":""}`,width:"22",height:"17",viewBox:"0 0 22 17",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:t.jsx("path",{d:"M15.7667 16.8186C15.4042 16.6602 15.1667 16.2977 15.1667 15.9019V12.8644H3.83334C1.99459 12.8644 0.5 11.4061 0.5 9.53105V2.23519C0.5 1.49894 1.09625 0.901855 1.83334 0.901855C2.57042 0.901855 3.16667 1.49894 3.16667 2.23519V9.53105C3.16667 9.93521 3.46626 10.1977 3.83334 10.1977H15.1667V7.23521C15.1667 6.83937 15.4042 6.47687 15.7667 6.31854C16.1334 6.1602 16.5542 6.23104 16.8459 6.50187L21.5126 10.8352C21.9417 11.2311 21.9417 11.9061 21.5126 12.3019L16.8459 16.6352C16.5542 16.9061 16.1334 16.9769 15.7667 16.8186Z",fill:"#278090"})}),t.jsxs("span",{className:"d-block",children:[e.comment.number_of_replies," ","hozzászólás"]})]}):"",t.jsxs("div",{className:"w-100 align-items-center justify-content-end d-flex",children:[n.user_sso_id&&!e.comment.deleted&&t.jsxs("a",{onClick:s,className:"a-link -primaryHoverEffect -fontSize-14 d-flex ml-4 align-items-center",children:[t.jsx("i",{className:"a-icon fas fa-reply mr-2"}),t.jsx("span",{className:"d-none d-md-block",children:"Válasz"})]}),r&&!e.comment.deleted&&t.jsxs(t.Fragment,{children:[t.jsxs("a",{onClick:p,className:"a-link -primaryHoverEffect -fontSize-14 d-flex ml-4 align-items-center",children:[t.jsx("i",{className:"a-icon fas fa-edit mr-2"}),t.jsx("span",{className:"d-none d-md-block",children:"Szerkesztés"})]}),t.jsxs("a",{className:"a-link -primaryHoverEffect -fontSize-14 d-flex ml-4 align-items-center",onClick:x,children:[t.jsx("i",{className:"a-icon fas fa-trash mr-2"}),t.jsx("span",{className:"d-none d-md-block",children:"Törlés"})]})]})]})]}),(e.repliedCurrently||e.editedCurrently)&&t.jsxs("div",{className:e.repliesDisplayed?"mt-5":"",style:{transition:"margin-top 0.25s ease-in-out"},children:[e.repliedCurrently&&t.jsx(C,{config:n,replyTo:e.comment.id,saveCallback:c,cancelCallback:u,changeTotal:o}),e.editedCurrently&&t.jsx(C,{config:n,commentId:e.comment.id,comment_text:e.comment.comment,saveCallback:j,cancelCallback:h,changeTotal:o})]})]})]}),e.repliesDisplayed&&t.jsx(N,{className:"-sub",config:n,commentId:e.comment.id,load:!0,addedComments:e.addedComments,changeTotal:o})]})},N=({config:n={},load:i=!0,commentId:o=null,addedComments:e=[],changeTotal:m=null,className:d=""})=>{const[a,r]=z.useState({loaded:!1,comments:[],page:0,more:0});g.each(a.comments,s=>{e=g.without(e,s)});const l=()=>{a.page++,_.get("/central-comments/list",{params:{comment_url:n.comment_url,comment_id:o,page:a.page}}).then(s=>{const u=s.data;if(!u.success){console.error(u.message||"Something went wrong...");return}const p=u.data.data,h=u.data.meta;p.map(x=>{a.comments.push(x)}),a.more=Math.min(n.per_page,Math.max(0,h.total-a.comments.length)),r({...a})})};return i&&!a.loaded&&(a.loaded=!0,l()),t.jsxs("div",{className:`m-commentBlock__list ${d}`,children:[!o&&a.loaded&&!e.length&&!a.comments.length?t.jsx("p",{className:"m-commentBlock__empty p-5",children:"A témában még nem született hozzászólás."}):"",o?"":e.map(s=>t.jsx(y,{config:n,comment:s,changeTotal:m},s.id)),a.comments.map(s=>t.jsx(y,{config:n,comment:s,changeTotal:m},s.id)),o?e.map(s=>t.jsx(y,{config:n,comment:s,changeTotal:m},s.id)):"",a.more>0?t.jsxs("a",{onClick:l,className:"a-link -primaryHoverEffect -fontSize-14 mt-6 d-inline-block -fontWeightSeeded",children:["További ",a.more," ",o?"válasz":"hozzászólás"," ","mutatása"]}):""]})},w=({config:n={}})=>{const i=z.useRef(),[o,e]=z.useState({loaded:!1,total:0,addedComments:[]}),m=l=>{const s=l.getBoundingClientRect(),u=Math.floor(s.top),p=Math.floor(s.left),h=Math.floor(s.bottom),x=Math.floor(s.right),c=Math.floor(window.innerHeight||document.documentElement.clientHeight),j=Math.floor(window.innerWidth||document.documentElement.clientWidth);return u>=0&&p>=0&&h<=c&&x<=j},d=()=>{!o.loaded&&i.current&&m(i.current)&&k().then(l=>{e(s=>({...s,loaded:!0,total:l}))})};z.useEffect(()=>(window.addEventListener("load",d),window.addEventListener("scroll",d),()=>{window.removeEventListener("load",d),window.removeEventListener("scroll",d)}),[o.loaded]);const a=l=>{l&&e(s=>({...s,addedComments:[l,...s.addedComments]}))},r=l=>{e(s=>({...s,total:s.total+l}))};return t.jsxs("div",{className:"m-commentBlock d-print-none px-xl-0",ref:i,children:[t.jsxs("h3",{className:"a-title -fontFamilySecondary -fontSize-28 -fontWeightStandard -fontColorPrimary mb-6",children:["Hozzászólások (",o.total,")"]}),n.user_sso_id?t.jsx(C,{config:n,saveCallback:a,changeTotal:r}):t.jsxs("p",{className:"m-commentBlock__login",children:["A hozzászólás íráshoz ",t.jsx("a",{href:"/login",className:"a-link -primaryHoverEffect",children:"belépés"})," szükséges!"]}),t.jsx(N,{config:n,load:o.loaded,addedComments:o.addedComments,changeTotal:r})]})};(()=>{const n=document.getElementById("comment-react-root");if(n){const i={comment_url:n.dataset.commentUrl||window.location.href,user_sso_id:n.dataset.userSsoId||"",user_name:n.dataset.userName||"",per_page:n.dataset.perPage||15};v.render(t.jsx(w,{config:i}),n)}})();
|