1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6997],{3940:(e,t,a)=>{Promise.resolve().then(a.bind(a,50336))},14503:(e,t,a)=>{"use strict";a.d(t,{dj:()=>u,oR:()=>h});var s=a(12115);let r=0,i=new Map,n=e=>{if(i.has(e))return;let t=setTimeout(()=>{i.delete(e),d({type:"REMOVE_TOAST",toastId:e})},1e6);i.set(e,t)},l=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,1)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(e=>e.id===t.toast.id?{...e,...t.toast}:e)};case"DISMISS_TOAST":{let{toastId:a}=t;return a?n(a):e.toasts.forEach(e=>{n(e.id)}),{...e,toasts:e.toasts.map(e=>e.id===a||void 0===a?{...e,open:!1}:e)}}case"REMOVE_TOAST":if(void 0===t.toastId)return{...e,toasts:[]};return{...e,toasts:e.toasts.filter(e=>e.id!==t.toastId)}}},o=[],c={toasts:[]};function d(e){c=l(c,e),o.forEach(e=>{e(c)})}function h(e){let{...t}=e,a=(r=(r+1)%Number.MAX_SAFE_INTEGER).toString(),s=()=>d({type:"DISMISS_TOAST",toastId:a});return d({type:"ADD_TOAST",toast:{...t,id:a,open:!0,onOpenChange:e=>{e||s()}}}),{id:a,dismiss:s,update:e=>d({type:"UPDATE_TOAST",toast:{...e,id:a}})}}function u(){let[e,t]=s.useState(c);return s.useEffect(()=>(o.push(t),()=>{let e=o.indexOf(t);e>-1&&o.splice(e,1)}),[e]),{...e,toast:h,dismiss:e=>d({type:"DISMISS_TOAST",toastId:e})}}},50336:(e,t,a)=>{"use strict";a.d(t,{ObservatoryView:()=>f});var s=a(95155),r=a(12115),i=a(53904),n=a(34869),l=a(97168),o=a(55028);let c={Sudan:[15.5,30.5],Egypt:[26.8,30.8],"South Africa":[-30.6,22.9],Nigeria:[9.1,8.7],Kenya:[0,38],Ethiopia:[9.1,40.5],Morocco:[31.8,-7.1],Algeria:[28,1.7],Tunisia:[34,9],USA:[37.1,-95.7],"New York":[40.7,-74],Canada:[56.1,-106.3],Mexico:[23.6,-102.5],Brazil:[-14.2,-51.9],Argentina:[-38.4,-63.6],UK:[55.4,-3.4],France:[46.2,2.2],Germany:[51.2,10.4],Italy:[41.9,12.6],Spain:[40.5,-3.7],Ukraine:[48.4,31.2],Russia:[61.5,105.3],Poland:[51.9,19.1],Sweden:[60.1,18.6],Norway:[60.5,8.5],Finland:[61.9,25.7],Greece:[39.1,21.8],Netherlands:[52.1,5.3],Belgium:[50.5,4.5],Portugal:[39.4,-8.2],Switzerland:[46.8,8.2],Austria:[47.5,14.5],China:[35.9,104.2],India:[20.6,79],Japan:[36.2,138.3],"South Korea":[35.9,127.8],Indonesia:[-.8,113.9],Thailand:[15.9,101],Vietnam:[14.1,108.3],Philippines:[12.9,121.8],Malaysia:[4.2,101.9],Singapore:[1.3,103.8],Pakistan:[30.4,69.3],Iran:[32.4,53.7],Iraq:[33.2,43.7],"Saudi Arabia":[23.9,45.1],Turkey:[38.9,35.2],Israel:[31,34.9],Palestine:[31.9,35.2],Syria:[34.8,39],Afghanistan:[33.9,67.7],Australia:[-25.3,133.8],"United Nations":[40.7,-74]},d=(0,o.default)(()=>Promise.all([a.e(9484),a.e(1761),a.e(8568)]).then(a.bind(a,18568)).then(e=>e.MapComponent),{loadableGenerated:{webpack:()=>[18568]},ssr:!1,loading:()=>(0,s.jsx)("div",{className:"w-full h-full bg-gray-100 flex items-center justify-center",children:(0,s.jsx)("p",{className:"text-gray-500",children:"Loading map..."})})});function h(e){let{countries:t,onCountrySelect:a,selectedCountry:r}=e,i=[...t.filter(e=>void 0!==c[e.name]).map(e=>({...e,position:c[e.name]}))].sort((e,t)=>t.count-e.count);return(0,s.jsx)("div",{className:"w-full h-full",children:(0,s.jsx)(d,{countries:i,onCountrySelect:a,selectedCountry:r})})}var u=a(14503);function f(){let[e,t]=(0,r.useState)([]),[a,o]=(0,r.useState)([]),[c,d]=(0,r.useState)(!0),[f,m]=(0,r.useState)(null),[x,g]=(0,r.useState)(null),[p,y]=(0,r.useState)(!1),[v,w]=(0,r.useState)(!0);(0,r.useEffect)(()=>{y(!0)},[]);let b=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];d(!0);try{console.log("Requesting news with limit=100...");let a=e?"/api/news?limit=100&refresh=true":"/api/news?limit=100";console.log("Fetching from: ".concat(a));let s=await fetch(a);if(!s.ok)throw Error("Failed to fetch news");let r=await s.json();console.log("Observatory received ".concat(r.length," news articles")),r.length>0?console.log("First 5 articles:",r.slice(0,5)):console.log("No articles received from API"),t(r),o(e=>{let t=new Map;e.forEach(e=>t.set(e.id,e)),r.forEach(e=>t.set(e.id,e));let a=Array.from(t.values());return a.sort((e,t)=>new Date(t.timestamp).getTime()-new Date(e.timestamp).getTime()),console.log("Accumulated ".concat(a.length," unique articles")),a}),m(null)}catch(e){m("Failed to fetch news"),console.error("Error fetching news:",e)}finally{d(!1)}};(0,r.useEffect)(()=>{b()},[]);let N=e=>{let t=["France","USA","Canada","UK","Germany","Japan","China","India","Brazil","Australia","Russia","Italy","Spain","Sudan","New York","United Nations","Ukraine","Egypt","Mexico","South Africa","Nigeria","Argentina","Pakistan","Indonesia","Saudi Arabia","Iran","Turkey","South Korea","Thailand","Vietnam","Philippines","Malaysia","Singapore","Israel","Palestine","Syria","Iraq","Afghanistan","Morocco","Algeria","Tunisia","Kenya","Ethiopia","Greece","Poland","Sweden","Norway","Denmark","Finland","Netherlands","Belgium","Portugal","Switzerland","Austria"].sort((e,t)=>t.length-e.length),a={};return e.forEach(e=>{let s=[e.title||"",e.description||""].join(" ").toLowerCase();t.forEach(t=>{s.includes(t.toLowerCase())&&(a[t]||(a[t]=[]),a[t].some(t=>t.id===e.id)||a[t].push(e))})}),a},j=async()=>{try{if(!(await fetch("/api/news/purge-cache",{method:"POST"})).ok)throw Error("Failed to invalidate cache");(0,u.oR)({title:"Cache purged",description:"News cache has been invalidated. Fetching fresh data..."}),b(!0)}catch(e){console.error("Error invalidating cache:",e),(0,u.oR)({title:"Error",description:"Failed to invalidate cache",variant:"destructive"})}};if(c)return(0,s.jsx)("div",{className:"w-full h-screen flex items-center justify-center",children:(0,s.jsx)(i.A,{className:"h-10 w-10 animate-spin text-gray-400"})});if(f)return(0,s.jsxs)("div",{className:"w-full h-screen flex flex-col items-center justify-center",children:[(0,s.jsx)("p",{className:"text-red-500 mb-4",children:f}),(0,s.jsx)(l.$,{onClick:()=>b(!0),children:"Retry"})]});let S=(()=>{let t=v?a:e;if(!x)return t;let s=N(t)[x]||[];return console.log("Filtered news for ".concat(x,": ").concat(s.length," of ").concat(t.length," total articles")),s})(),A=N(e);return(0,s.jsx)("main",{className:"w-full h-screen bg-white",children:(0,s.jsxs)("div",{className:"w-full h-full px-4 pt-12 pb-4 flex flex-col",children:[(0,s.jsx)("div",{className:"bg-white border-b border-gray-100 py-3 px-6",children:(0,s.jsx)("h1",{className:"text-xl font-bold text-gray-800",children:"Observatoire de La Paix et du Vivre-Ensemble"})}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-6 py-6 px-6 flex-1 overflow-auto bg-gray-50",children:[(0,s.jsx)("div",{className:"h-full overflow-hidden",children:(0,s.jsxs)("div",{className:"bg-white rounded-lg shadow-sm border border-gray-100 h-full flex flex-col",children:[(0,s.jsx)("div",{className:"px-6 py-4 border-b border-gray-100 flex-shrink-0",children:(0,s.jsxs)("div",{className:"flex items-center justify-between",children:[(0,s.jsxs)("h2",{className:"text-lg font-semibold text-gray-800",children:["Latest News",(0,s.jsxs)("span",{className:"text-sm font-normal ml-2 text-gray-500",children:["(",S.length," articles)",e.length<10&&(0,s.jsx)("span",{className:"italic ml-1",children:"(API limitation)"})]})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(l.$,{variant:"outline",size:"sm",onClick:()=>w(!v),className:"h-8 px-3 text-xs",children:v?"Showing All (".concat(a.length,")"):"Showing Latest (".concat(e.length,")")}),(0,s.jsx)(l.$,{variant:"outline",size:"sm",onClick:()=>j(),className:"h-8 px-3 text-xs","aria-label":"Purge cache",children:"Purge Cache"}),(0,s.jsx)(l.$,{variant:"ghost",size:"sm",onClick:()=>b(!0),className:"h-8 w-8 p-0","aria-label":"Refresh news",children:(0,s.jsx)(i.A,{className:"h-4 w-4"})})]})]})}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===S.length?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-gray-500",children:[(0,s.jsx)(n.A,{className:"h-12 w-12 mb-2 text-gray-300"}),(0,s.jsx)("p",{children:x?"No news found for ".concat(x):"No news found"})]}):(0,s.jsx)("ul",{className:"divide-y divide-gray-100",children:S.map(e=>(0,s.jsx)("li",{children:(0,s.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"block hover:bg-gray-50 transition-colors",children:(0,s.jsxs)("div",{className:"px-6 py-4",children:[(0,s.jsxs)("div",{className:"flex justify-between items-start mb-2",children:[(0,s.jsx)("h3",{className:"font-medium text-gray-900 flex-grow",children:e.title}),(0,s.jsx)("span",{className:"text-xs text-gray-500 whitespace-nowrap ml-2",children:e.displayDate})]}),(0,s.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-gray-500",children:e.source}),e.category&&(0,s.jsx)("span",{className:"text-xs bg-gray-100 text-gray-600 rounded-full px-2 py-0.5",children:e.category})]}),(0,s.jsx)("p",{className:"text-sm text-gray-600 mt-2 line-clamp-2",children:e.description})]})})},e.id))})})]})}),(0,s.jsx)("div",{className:"h-full overflow-hidden",children:(0,s.jsxs)("div",{className:"bg-white rounded-lg shadow-sm border border-gray-100 h-full flex flex-col",children:[(0,s.jsx)("div",{className:"px-6 py-4 border-b border-gray-100 flex-shrink-0",children:(0,s.jsxs)("div",{className:"flex justify-between items-center",children:[(0,s.jsxs)("h2",{className:"text-lg font-semibold text-gray-800",children:["World Map",x&&(0,s.jsxs)("span",{className:"text-sm font-normal ml-2 text-gray-500",children:["(Selected: ",x,")"]})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(l.$,{variant:"outline",size:"sm",onClick:()=>g(null),className:"h-8 px-3 text-xs",disabled:!x,children:"Clear Selection"}),(0,s.jsx)(l.$,{variant:"ghost",size:"sm",onClick:()=>b(!0),className:"h-8 w-8 p-0","aria-label":"Refresh news",children:(0,s.jsx)(i.A,{className:"h-4 w-4"})})]})]})}),(0,s.jsx)("div",{className:"flex-1 relative",children:p&&(0,s.jsx)(h,{countries:Object.entries(A).map(e=>{let[t,a]=e;return{name:t,count:a.length}}),onCountrySelect:e=>{g(x===e?null:e)},selectedCountry:x})})]})})]})]})})}},53999:(e,t,a)=>{"use strict";a.d(t,{cn:()=>i});var s=a(52596),r=a(39688);function i(){for(var e=arguments.length,t=Array(e),a=0;a<e;a++)t[a]=arguments[a];return(0,r.QP)((0,s.$)(t))}},97168:(e,t,a)=>{"use strict";a.d(t,{$:()=>c,r:()=>o});var s=a(95155),r=a(12115),i=a(99708),n=a(74466),l=a(53999);let o=(0,n.F)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),c=r.forwardRef((e,t)=>{let{className:a,variant:r,size:n,asChild:c=!1,...d}=e,h=c?i.DX:"button";return(0,s.jsx)(h,{className:(0,l.cn)(o({variant:r,size:n,className:a})),ref:t,...d})});c.displayName="Button"}},e=>{var t=t=>e(e.s=t);e.O(0,[4277,8587,8441,1684,7358],()=>t(3940)),_N_E=e.O()}]); |