(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[405],{5557:function(e,t,a){(window.__NEXT_P=window.__NEXT_P||[]).push(["/",function(){return a(790)}])},790:function(e,t,a){"use strict";a.r(t),a.d(t,{default:function(){return y}});var o=a(5893),l=a(7294),n=a(2130);"undefined"!=typeof localStorage&&localStorage.getItem("token");let i=new n.g6("https://server.newboard.io/graphql",{headers:()=>({Authorization:"Bearer ".concat("undefined"!=typeof localStorage&&localStorage.getItem("token"))})}),s=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{let a=await i.request(e,t);return a}catch(e){throw console.error("GraphQL request error:",e),e}};var r=a(5675),d=a.n(r);function c(e){var t,a;let{navigateToPage:n}=e,[i,r]=(0,l.useState)({}),[c,p]=(0,l.useState)(!1),[u,g]=(0,l.useState)(!1),[x,h]=(0,l.useState)(""),[f,m]=(0,l.useState)(""),[b,y]=(0,l.useState)([]),[k,v]=(0,l.useState)([]),[w,I]=(0,l.useState)([]),[j,S]=(0,l.useState)(""),[W,B]=(0,l.useState)([]),[E,C]=(0,l.useState)(""),[_,F]=(0,l.useState)(""),[T,M]=(0,l.useState)(!1),[R,L]=(0,l.useState)({defaultBoardId:"",defaultListId:""}),[N,A]=(0,l.useState)(!1),[z,D]=(0,l.useState)(),q=e=>{if(U(e))try{let t=new URL(e).origin,a=encodeURIComponent(t),o="https://www.google.com/s2/favicons?sz=64&domain=".concat(a);if(!o)throw Error("Failed to fetch favicon");F(o)}catch(e){}};(0,l.useEffect)(()=>{let e=localStorage.getItem("default-Lists");if(e){let t=JSON.parse(e);D(t)}},[]);let P=()=>{let e=localStorage.getItem("default-boardId"),t=localStorage.getItem("default-listId"),a=localStorage.getItem("default-workspaceId");e===f&&t===x&&a===j?(localStorage.removeItem("default-boardId"),localStorage.removeItem("default-listId"),localStorage.removeItem("default-workspaceId"),L({...R,defaultWorkspaceId:"",defaultBoardId:"",defaultListId:""})):(localStorage.setItem("default-boardId",f),localStorage.setItem("default-listId",x),localStorage.setItem("default-workspaceId",j),chrome.storage.local.set({defaultBoardId:f,defaultListId:x,defaultWorkspaceId:j},function(){console.log("Default IDs have been set")}),L({...R,defaultWorkspaceId:j,defaultBoardId:f,defaultListId:x})),M(!T)};(0,l.useEffect)(()=>{let e=async()=>{let e=localStorage.getItem("default-workspaceId"),t=await s("\n  query GetMyWSs {\n    getMyWSs {\n      workspace {\n        workspaceId\n        name\n      }\n      JWTWithUserRole\n      role\n      activeBoardId\n    }\n  }\n");if((null==t?void 0:t.getMyWSs)&&!e){I(t.getMyWSs);let e=t.getMyWSs[0].workspace.workspaceId;S(e),$(e)}else I(t.getMyWSs),S(e),$(e)};e()},[]),(0,l.useEffect)(()=>{j&&$(j)},[j]);let $=async e=>{let t=await s("\n  query getWsBoardsWithoutFolders($workspaceId: String!) {\n    getWsBoardsWithoutFolders(workspaceId: $workspaceId) {\n      name\n      boardId\n      globalOrder\n      lists { \n        listId\n        name\n        bookmarks {\n          link\n        }\n      }\n    }\n  }\n",{workspaceId:e}),a=[];if(null==t?void 0:t.getWsBoardsWithoutFolders){y(a=t.getWsBoardsWithoutFolders);let e=localStorage.getItem("default-boardId"),n=localStorage.getItem("default-listId"),i=a.find(t=>t.boardId===e);if(i){m(e),v(i.lists);let t=i.lists.some(e=>e.listId===n);n&&t?h(n):i.lists.length>0?h(i.lists[0].listId):h(""),L({defaultBoardId:e,defaultListId:n})}else{var o,l;a.length>0&&(null===(o=a[0])||void 0===o?void 0:null===(l=o.lists)||void 0===l?void 0:l.length)>0?(m(a[0].boardId),v(a[0].lists),h(a[0].lists[0].listId)):(v([]),h(""))}}},O=async e=>{try{let t=await s("\n  query GetMetadata($url: String!) {\n    getMetadata(url: $url) {\n      title\n      description\n      featuredImage\n      favicon\n    }\n  }\n",{url:e});return t.getMetadata}catch(e){}};(0,l.useEffect)(()=>{j&&$(j)},[j]),(0,l.useEffect)(()=>{var e;let t=b.find(e=>e.boardId===f);localStorage.getItem("default-boardId");let a=localStorage.getItem("default-listId"),o=null==t?void 0:null===(e=t.lists)||void 0===e?void 0:e.some(e=>e.listId===a);(null==t?void 0:t.lists)&&(v(t.lists),t.lists[0]&&!o?h(t.lists[0].listId):h(a))},[f,b]);let U=e=>/^(https?:\/\/)?(www\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(\/[^\s]*)?$/i.test(e);(0,l.useEffect)(()=>{q(i.url)},[i.url]),"https://www.google.com/s2/favicons?sz=64&domain=https%3A%2F%2Fah.d.pr"==_&&F("/favicon.png");let G=async e=>{e.preventDefault();let t=e.target,a=t.title.value,o=t.url.value;if(U(o)){p(!0);let e=await O(o),t={title:a||i.title,link:o||i.link,favicon:_||" ",featuredImage:(null==e?void 0:e.featuredImage)||"",listId:x,workspaceId:j,desc:(null==e?void 0:e.description)||""};if(!t.title||!t.link||!t.listId||!t.workspaceId){C("Invalid Input"),p(!1);return}try{let e=await s("\n  mutation CreateBookmark($payload: CreateBookmarkData!) {\n    createBookmark(payload: $payload) {\n      title\n      favicon\n    }\n  }\n",{payload:t});if(e&&(C("Bookmark added successfully"),chrome.runtime.sendMessage({action:"bookmarkAdded"},e=>{chrome.runtime.lastError?console.error(chrome.runtime.lastError.message):console.log("Message received:",e)})),null==e?void 0:e.createBookmark){let a={...t,...e.createBookmark};B([...W,a]),g(!0),C("Bookmark added successfully"),chrome.runtime.sendMessage({action:"bookmarkAdded"},e=>{console.log("Bookmark added and icon updated")})}}catch(e){C("Error adding bookmark. Please try again.")}finally{p(!1)}}else{C("Invalid Link");return}},V=e=>{m(e.target.value)},X=e=>{h(e.target.value)},J=e=>{S(e.target.value)};(0,l.useEffect)(()=>{chrome.tabs&&chrome.tabs.query({active:!0,currentWindow:!0},e=>{let{url:t,title:a,favIconUrl:o}=e[0];r({url:t,title:a,favicon:o})})},[]);let Z=()=>{window.open("https://staging.newboard.app/","_blank")};return(0,o.jsxs)("div",{style:{padding:"20px",fontFamily:"Arial, sans-serif",width:"350px",maxWidth:"600px",margin:"0 auto"},children:[(0,o.jsxs)("div",{style:{fontWeight:"bold",display:"flex",gap:"5px"},children:[(0,o.jsx)("div",{onClick:Z,children:(0,o.jsx)(d(),{style:{boxShadow:N?"0px 4px 8px gray":"none",transition:"box-shadow 0.3s ease",borderRadius:"8px",padding:"2px"},src:"/icons/favicon.png",alt:"",width:24,height:24,onMouseEnter:()=>A(!0),onMouseLeave:()=>A(!1)})}),(0,o.jsx)("div",{style:{marginTop:"3px"},children:"Newboard"})]}),(0,o.jsxs)("div",{style:{marginBottom:"20px",textAlign:"center"},children:[(0,o.jsx)("h1",{style:{fontSize:"24px",color:"#333"},children:"NewBoard Extension"}),(0,o.jsx)("h5",{style:{color:"gray"},children:"Add a new bookmark to your collection."}),(0,o.jsxs)("select",{onChange:J,style:{display:"inline-block",padding:"8px 20px",fontSize:"12px",fontWeight:"bold",color:"white",backgroundColor:"black",border:"none",borderRadius:"5px",cursor:"pointer",textAlign:"center",transition:"background-color 0.3s ease"},children:[j&&(0,o.jsx)("option",{value:j,children:w.find(e=>e.workspace.workspaceId===j).workspace.name},j),w.filter(e=>e.workspace.workspaceId!==j).map(e=>(0,o.jsx)("option",{value:e.workspace.workspaceId,children:e.workspace.name},e.workspace.workspaceId))]})]}),(0,o.jsx)("div",{children:u?(0,o.jsx)("span",{style:{color:"green",fontWeight:"bold"},children:"Saved"}):(0,o.jsxs)("form",{onSubmit:G,style:{display:"flex",flexDirection:"column",gap:"10px"},children:[(0,o.jsxs)("div",{style:{marginBottom:"10px"},children:[(0,o.jsx)("label",{style:{display:"block",marginBottom:"5px",fontWeight:"bold"},children:"Title"}),(0,o.jsx)("input",{name:"title",type:"text",placeholder:"Enter a title",defaultValue:i.title,title:i.title,required:!0,style:{width:"100%",padding:"8px",borderRadius:"4px",border:"1px solid #ccc"}})]}),(0,o.jsxs)("div",{style:{marginBottom:"10px"},children:[(0,o.jsx)("label",{style:{display:"block",marginBottom:"5px",fontWeight:"bold"},children:"URL"}),(0,o.jsx)("input",{name:"url",type:"url",placeholder:"Enter a URL",defaultValue:i.url,title:i.url,required:!0,style:{width:"100%",padding:"8px",borderRadius:"4px",border:"1px solid #ccc"}})]}),(0,o.jsxs)("div",{style:{display:"flex",gap:"10px",width:"100%"},children:[(0,o.jsxs)("div",{style:{flex:1,marginBottom:"10px"},children:[(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{display:"block",marginBottom:"5px",fontWeight:"bold"},children:"Boards"}),(0,o.jsx)("select",{style:{width:"100%",padding:"8px",borderRadius:"4px",border:"1px solid #ccc"},onChange:V,children:(0,o.jsxs)(o.Fragment,{children:[f&&(0,o.jsx)("option",{value:f,children:null===(t=b.find(e=>e.boardId===f))||void 0===t?void 0:t.name},f),b.filter(e=>e.boardId!==f).map(e=>(0,o.jsx)("option",{value:e.boardId,children:e.name},e.boardId))]})})]}),(0,o.jsxs)("div",{style:{margin:"10px 0px"},children:[(0,o.jsx)("input",{type:"checkbox","aria-hidden":"true",className:"hidden-checkbox",tabIndex:"-1",value:"on",id:"make-board-default",checked:R.defaultBoardId===f&&R.defaultListId===x,onChange:P}),(0,o.jsx)("label",{htmlFor:"make-boards-default",style:{fontFamily:"sans-serif"},children:"Set as Default"})]})]}),(0,o.jsx)("div",{style:{flex:1,marginBottom:"10px"},children:(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{display:"block",marginBottom:"5px",fontWeight:"bold"},children:"List"}),(0,o.jsx)("select",{style:{width:"100%",padding:"8px",borderRadius:"4px",border:"1px solid #ccc"},onChange:X,children:0===k.length?(0,o.jsx)("option",{children:"No List"}):(0,o.jsx)(o.Fragment,{children:x&&(0,o.jsxs)("option",{value:x,children:[null===(a=k.find(e=>e.listId===x))||void 0===a?void 0:a.name,k.filter(e=>e.listId!==x).map(e=>(0,o.jsx)("option",{value:e.listId,children:e.name},e.listId))]},x)})})]})})]}),(0,o.jsxs)("div",{style:{display:"flex",gap:"10px"},children:[(0,o.jsx)("button",{type:"submit",disabled:c,style:{width:"100%",padding:"10px",borderRadius:"4px",border:"none",backgroundColor:c?"#ccc":"#A855F7",color:"#fff",fontWeight:"bold",cursor:c?"not-allowed":"pointer"},children:c?(0,o.jsx)("span",{children:"Saving..."}):(0,o.jsx)("span",{children:"Save"})}),(0,o.jsx)("button",{type:"submit",disabled:c,style:{width:"100%",padding:"10px",borderRadius:"4px",border:"none",backgroundColor:c?"#ccc":"#A855F7",color:"#fff",fontWeight:"bold",cursor:c?"not-allowed":"pointer"},onClick:()=>{n("tabs")},children:"Tabs"})]}),E?(0,o.jsx)("h4",{style:{textAlign:"center"},children:E}):null]})})]})}a(9973);var p=a(6467),u=a.n(p);function g(e){let{navigateToPage:t}=e;return(0,o.jsx)("div",{className:u().container,children:(0,o.jsxs)("main",{className:u().main,children:[(0,o.jsx)("h1",{className:u().title,children:"NEXT-CHROME-STARTER"}),(0,o.jsx)("p",{className:u().description,children:"Newboard App extension"}),(0,o.jsx)("h1",{className:u().code,children:"New Page ./components/New/index.js"}),(0,o.jsx)("p",{children:"[ - This is New page content - ]"}),(0,o.jsx)("p",{onClick:()=>t("index"),children:"< Go Back"})]})})}var x=a(2091);let h="\n  query GetMetadata($url: String!) {\n    getMetadata(url: $url) {\n      title\n      description\n      featuredImage\n      favicon\n    }\n  }\n";function f(e){var t;let{navigateToPage:a}=e,[n,i]=(0,l.useState)({}),[r,d]=(0,l.useState)([]),[c,p]=(0,l.useState)(!1),[u,g]=(0,l.useState)([]),[f,m]=(0,l.useState)(""),[b,y]=(0,l.useState)(""),[k,v]=(0,l.useState)(""),[w,I]=(0,l.useState)([]),[j,S]=(0,l.useState)([]),[W,B]=(0,l.useState)([]),[E,C]=(0,l.useState)(!0),_=async e=>{try{let t=await s(h,{url:e});return console.log("meta data",t),t.getMetadata}catch(e){console.log(e)}};(0,l.useEffect)(()=>{let e=async()=>{let e=await s("\n  query GetMyWSs {\n    getMyWSs {\n      workspace {\n        workspaceId\n        name\n      }\n      JWTWithUserRole\n      role\n      activeBoardId\n    }\n  }\n");if(null==e?void 0:e.getMyWSs){B(e.getMyWSs);let t=e.getMyWSs[0].workspace.workspaceId;v(t),F(t)}};e()},[]);let F=async e=>{let t=await s("\n  query getWsBoardsWithoutFolders($workspaceId: String!) {\n    getWsBoardsWithoutFolders(workspaceId: $workspaceId) {\n      name\n      boardId\n      globalOrder\n      lists { \n        listId\n        name\n        bookmarks {\n          link\n        }\n      }\n    }\n  }\n",{workspaceId:e}),a=[];if(null==t?void 0:t.getWsBoardsWithoutFolders)for(let e of(I(a=t.getWsBoardsWithoutFolders),a)){var o;if((null==e?void 0:null===(o=e.lists)||void 0===o?void 0:o.length)>0){y(e.boardId),S(e.lists),e&&e.lists[0]&&m(e.lists[0].listId);break}}};(0,l.useEffect)(()=>{k&&F(k)},[k]),(0,l.useEffect)(()=>{let e=w.find(e=>e.boardId===b);(null==e?void 0:e.lists)&&(S(e.lists),e&&e.lists[0]&&m(e.lists[0].listId))},[b,w]);let T=async e=>{e.preventDefault();let t=[];p(!0),u.map(e=>{let a=e.title,o=e.url,l=_(o),n={title:a||"",link:o,favicon:e.favIconUrl||"",featuredImage:l.featuredImage||"",listId:f,wsId:k,desc:l.description||""};t.push(n)});try{let e=await s("\n  mutation CreateManyBookmark($payload: [CreateManyBookmarks]) {\n  createManyBookmark(payload: $payload)\n}\n",{payload:t});console.log(e),e&&(console.log("Bookmark added successfully"),E?chrome.tabs.query({},e=>{e.forEach(e=>{chrome.tabs.remove(e.id)})}):window.close())}catch(e){console.error("Error creating bookmark:",e),console.log("Error adding bookmark. Please try again.")}finally{p(!1)}console.log("Final: ",t)},M=e=>{y(e.target.value)},R=e=>{m(e.target.value)},L=e=>{v(e.target.value)};(0,l.useEffect)(()=>{chrome.tabs&&chrome.tabs.query({},e=>{let{url:t,title:a,favIconUrl:o}=e[0];g(e)})},[]);let N=e=>{let t=u.filter(t=>t.id!==e);g(t)},[A,z]=(0,l.useState)([]);return(0,l.useEffect)(()=>{u.map(async e=>{try{if(e.link){let t=await s(h,{url:e.link});e.metaData=t.getMetadata,A.push(e)}}catch(t){e.metaData={},A.push(e)}})},[u]),(0,o.jsxs)("div",{style:{display:"flex",flexDirection:"column",width:"400px",alignItems:"center"},children:[(0,o.jsxs)("div",{style:{display:"flex",flexDirection:"row",paddingTop:"10px",justifyContent:"flex-start",paddingLeft:"15px",paddingRight:"15px",width:"100%",alignItems:"center"},children:[(0,o.jsx)(x.x_l,{color:"#A855F7",size:20,onClick:()=>a("index")}),(0,o.jsx)("h1",{style:{margin:0,marginLeft:"15px"},children:"All Tabs"})]}),(0,o.jsx)("ul",{style:{width:"350px",border:"1px solid black",overflow:"hidden",overflowY:"scroll",marginBottom:"30px",height:"190px",paddingLeft:"0px"},children:u&&u.map(e=>(0,o.jsx)("li",{style:{listStyleType:"none",borderBottom:"1px solid black"},children:(0,o.jsxs)("div",{style:{display:"flex",flexDirection:"row",justifyContent:"space-evenly",paddingLeft:"10px",paddingRight:"10px"},children:[(0,o.jsx)("img",{style:{height:"20px",width:"20px",alignSelf:"center",marginRight:"15px"},src:e.favIconUrl}),(0,o.jsx)("p",{style:{fontWeight:600,fontSize:"16px",height:"20px",marginBottom:10,marginTop:10,width:"300px",textOverflow:"ellipsis",whiteSpace:"nowrap",overflow:"hidden"},children:e.title}),(0,o.jsx)("button",{type:"button",style:{fontWeight:700,fontSize:"14px",border:"none",backgroundColor:"white"},onClick:()=>N(e.id),children:(0,o.jsx)(x.lp8,{color:"#A855F7"})})]})},e))}),(0,o.jsx)("label",{style:{display:"block",marginBottom:"5px",fontWeight:"bold",marginLeft:"25px",alignSelf:"flex-start"},children:"Workspace"}),(0,o.jsxs)("div",{style:{display:"flex",flexDirection:"row",gap:"30px",width:"100%",padding:"0px 30px",marginBottom:"15px"},children:[(0,o.jsx)("select",{onChange:L,style:{display:"inline-block",padding:"8px 10px",fontSize:"12px",fontWeight:"bold",color:"black",backgroundColor:"white",borderRadius:"5px",cursor:"pointer",textAlign:"center",transition:"background-color 0.3s ease",border:"1px solid black"},children:W.map(e=>(0,o.jsx)("option",{value:e.workspace.workspaceId,children:e.workspace.name},e.workspace.workspaceId))}),(0,o.jsxs)("div",{style:{margin:"10px 0px"},children:[(0,o.jsx)("input",{type:"checkbox","aria-hidden":"true",className:"hidden-checkbox",tabIndex:"-1",value:"on",id:"make-board-default",checked:E,onChange:()=>C(!E)}),(0,o.jsx)("label",{htmlFor:"make-boards-default",style:{fontFamily:"sans-serif",fontSize:"15px"},children:"Close tabs"})]})]}),(0,o.jsxs)("form",{onSubmit:T,style:{display:"flex",flexDirection:"column"},children:[(0,o.jsxs)("div",{style:{display:"flex",gap:"50px",flexDirection:"row",justifyContent:"space-evenly",paddingLeft:"15px",paddingRight:"15px"},children:[(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{display:"block",marginBottom:"5px",fontWeight:"bold"},children:"Boards"}),(0,o.jsx)("select",{style:{width:"150px",padding:"8px",borderRadius:"4px",border:"1px solid #ccc"},onChange:M,children:(0,o.jsxs)(o.Fragment,{children:[b&&(0,o.jsx)("option",{value:b,children:null===(t=w.find(e=>e.boardId===b))||void 0===t?void 0:t.name},b),w.filter(e=>e.boardId!==b).map(e=>(0,o.jsx)("option",{value:e.boardId,children:e.name},e.boardId))]})})]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{display:"block",marginBottom:"5px",fontWeight:"bold"},children:"List"}),(0,o.jsx)("select",{style:{width:"150px",padding:"8px",borderRadius:"4px",border:"1px solid #ccc"},onChange:R,children:0===j.length?(0,o.jsx)("option",{children:"No List"}):j.map(e=>(0,o.jsx)("option",{value:e.listId,children:e.name},e.listId))})]})]}),(0,o.jsx)("button",{disabled:c,style:{width:"150px",padding:"10px",borderRadius:"4px",height:"40px",marginTop:"10px",marginBottom:"10px",border:"none",backgroundColor:c?"#ccc":"#A855F7",color:"#fff",fontWeight:"bold",cursor:c?"not-allowed":"pointer",alignSelf:"center"},children:"Save All Tabs"})]})]})}var m=a(8506);function b(e){let{navigateToPage:t}=e,a=()=>{chrome&&chrome.tabs.create({url:"http://localhost:3000"})};return(0,o.jsxs)("div",{style:{padding:"20px",fontFamily:"Arial, sans-serif",width:"350px",height:"486px",maxWidth:"600px",margin:"0 auto",textAlign:"center",paddingTop:"150px",backgroundImage:"linear-gradient(to right, #441DE1, #6340F0, #7D5CFF"},children:[(0,o.jsx)("p",{style:{fontSize:"14px",color:"lightgray"},children:"Seize the day, bookmark by bookmark."}),(0,o.jsx)("p",{style:{fontSize:"24px",color:"white"},children:" Log in to Newboard Extension to get started."}),(0,o.jsx)("div",{style:{paddingTop:"30px"},children:(0,o.jsx)("button",{style:{width:"100%",padding:"10px",borderRadius:"4px",border:"none",backgroundColor:"lavender",color:"darkviolet",fontWeight:"bold"},onClick:a,children:"Login"})})]})}function y(){let[e,t]=(0,l.useState)("index"),{token:a,saveToken:n}=(0,m.a)(),i=e=>{console.log("Navigating to page: ".concat(e)),t(e)};return(0,l.useEffect)(()=>{},[e]),(0,l.useEffect)(()=>{chrome&&chrome.storage.local.get("userToken",function(e){"undefined"!=typeof localStorage&&localStorage.setItem("token",e.userToken),n(e.userToken),e.userToken||i("login")})},[]),(0,o.jsxs)(o.Fragment,{children:["index"===e&&(0,o.jsx)(c,{navigateToPage:i}),"new"===e&&(0,o.jsx)(g,{navigateToPage:i}),"tabs"===e&&(0,o.jsx)(f,{navigateToPage:i}),"login"===e&&(0,o.jsx)(b,{navigateToPage:i})]})}},6467:function(e){e.exports={container:"Pages_container__SbWhT",main:"Pages_main__5_Vsf",title:"Pages_title__5_zk8",description:"Pages_description__Vsj9E",code:"Pages_code__vzNOX"}},2868:function(){},4777:function(){},9830:function(){},209:function(){}},function(e){e.O(0,[365,870,774,888,179],function(){return e(e.s=5557)}),_N_E=e.O()}]);