Skip to content

Commit

Permalink
Merge branch 'main' into tests-and-ci-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
rohithaug authored Mar 12, 2024
2 parents 13900eb + e724078 commit 47f9972
Show file tree
Hide file tree
Showing 17 changed files with 396 additions and 137 deletions.
6 changes: 1 addition & 5 deletions client/src/pages/blog/[slug]/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,8 @@ const Page = () => {
)}
</>
}

<p className="mb-8 text-justify text-gray-500 whitespace-pre-line">
{postDetails.content}
</p>
<p className="mb-8 text-justify text-gray-500 whitespace-pre-line" dangerouslySetInnerHTML={{ __html: postDetails.content }}></p>
<LikeDislike blogId={router.query.slug}/>

</>
:
<></>
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/blog/components/card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Card = ({ blogId, title, author, category, time, content, imageFileName })
<p className="mb-1 text-sm text-blue-500">{author}</p>&nbsp;&nbsp;
<p className="mb-1 text-sm text-gray-500">{time}</p>
</div>
<p className="mb-3 font-normal text-black-400 max-h-36 overflow-hidden">{content}</p>
<p className="mb-3 font-normal text-black-400 max-h-36 overflow-hidden" dangerouslySetInnerHTML={{ __html: content }}></p>
<a href={`/blog/${blogId || ""}?source=home`} className="inline-flex items-center px-3 py-2 text-sm font-medium text-center text-white bg-blue-700 rounded-lg hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300">
Read more
<svg className="rtl:rotate-180 w-3.5 h-3.5 ms-2" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 10">
Expand Down
25 changes: 12 additions & 13 deletions client/src/pages/blog/components/likedislike.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,19 @@ const LikeDislike = (props) => {
}
}

return (
<div style={{'display': 'flex', 'justify-content': 'flex-end'}}>
<div style={{paddingRight: '20px', borderRight: '1px black solid', display: 'flex', alignItems: 'center'}} className='text-gray-500'>
Feedback
return (
<div className="flex justify-end mb-8">
<div className="pr-4 border-r border-black flex items-center text-gray-500">
Feedback
</div>
<button className="ml-4 mr-3" onClick={handleLikeClick}>
<LikeButtonIcon color={likeClicked ? 'green' : 'black'} />
</button>
<button className="ml-3 mr-2" onClick={handleDislikeClick}>
<DislikeButtonIcon color={dislikeClicked ? 'red' : 'black'} />
</button>
</div>
<button style={{marginLeft: '20px', marginRight: '15px'}} onClick={handleLikeClick}>
<LikeButtonIcon color={likeClicked? 'green' : 'black'} />
</button>
<button style={{marginLeft: '15px', marginRight: '10px'}} onClick={handleDislikeClick}>
<DislikeButtonIcon color={dislikeClicked? 'red' : 'black'} />
</button>

</div>
);
);
};

export default LikeDislike;
159 changes: 159 additions & 0 deletions client/src/pages/dashboard/[slug]/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// IMPORT LIBRARIES
import React, { useState, useEffect } from 'react';
import { useRouter } from 'next/router';
import Cookie from 'js-cookie';

// IMPORT COMPONENTS
import Layout from '../components/layout';
import IndivdualBlogPostMetrics from '../components/individualBlogPostMetrics';
import PieChart from '../components/charts/pieChart';
import Breadcrumb from '../components/breadcrumb';
export default function Page() {
const router = useRouter();
const adminToken = Cookie.get('token') || null;
const [blogPostMetrics, setBlogPostMetrics] = useState(null);
const [blogPostMetricsFetchLoading, setBlogPostMetricsFetchLoading] = useState(true);
const [blogPostMetricsFetchError, setBlogPostMetricsFetchError] = useState(false);
const [blogPostMetricsFetchErrorDetails, setBlogPostMetricsFetchErrorDetails] = useState(null);

const fetchBlogPostMetrics = async (slug) => {
try {
const response = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_ENDPOINT}/analytics/metrics/${slug}`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${adminToken}`
}
});

if (!response.ok) {
const errorDetails = await response.json();
setBlogPostMetricsFetchErrorDetails({
statusCode: response.status,
errorMessage: errorDetails?.message || errorDetails || "",
errorDescription: errorDetails?.description || ""
});
setBlogPostMetricsFetchError(true);
setBlogPostMetricsFetchLoading(false);
}
const data = await response.json();
setBlogPostMetrics(data);
setBlogPostMetricsFetchLoading(false);

} catch (error) {
setBlogPostMetricsFetchErrorDetails({
statusCode: 400,
errorMessage: "Unexpected client error",
errorDescription: "Failed to fetch blog post metrics"
});
setBlogPostMetricsFetchError(true);
setBlogPostMetricsFetchLoading(false);
}
};

useEffect(() => {
if (router.query.slug) {
fetchBlogPostMetrics(router.query.slug);
}
}, [router.query.slug]);

if (blogPostMetricsFetchLoading) {
return (
<div class="flex items-center justify-center h-96">
<div class="text-center">
<p class="text-gray-500">Loading blog post metrics...</p>
</div>
</div>
);
}

if (!adminToken) {
router.push('/signin');
}

if (blogPostMetricsFetchError) {
return (
<div className="flex flex-col items-center justify-center min-h-screen">
<h1 className="text-4xl font-bold text-gray-900">{blogPostMetricsFetchErrorDetails.statusCode}: {blogPostMetricsFetchErrorDetails.errorMessage}</h1>
<p className="mt-4 text-lg text-gray-600">{blogPostMetricsFetchErrorDetails.errorDescription}</p>
<button
onClick={() => router.push('/signin')}
className="mt-8 px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 focus:outline-none focus:bg-blue-600"
>
Sign In
</button>
</div>
);
}

return (
<div>
{blogPostMetrics ?
<div>
<Breadcrumb postTitle={blogPostMetrics.blogName} />

<h1 className="text-3xl mb-4 font-normal tracking-tight text-gray-900">Blog Post Metrics</h1>
<IndivdualBlogPostMetrics
blogPostMetrics={blogPostMetrics}
/>

<h1 className="text-3xl mb-4 font-normal tracking-tight text-gray-900">Blog Post Metrics Visualization</h1>
<div className="mb-8 flex flex-col md:flex-row">
<div className="w-full md:w-1/2 p-4">
<PieChart
title="Likes and Dislikes"
labels={["Likes", "Dislikes"]}
datasets={[
{
label: "# of votes",
data: [blogPostMetrics.likes || 0, blogPostMetrics.dislikes || 0],
backgroundColor: ['rgba(75, 192, 192, 0.3)', 'rgba(255, 99, 132, 0.3)'],
borderColor: ['rgb(75, 192, 192)', 'rgb(255, 99, 132)'],
borderWidth: 1
}
]}
/>
</div>
<div className="w-full md:w-1/2 p-4">
<PieChart
title="Source of visit"
labels={["Home", "Direct", "Email"]}
datasets={[
{
label: "# of visits",
data: [
blogPostMetrics.source && blogPostMetrics.source.home ? blogPostMetrics.source.home : 0,
blogPostMetrics.source && blogPostMetrics.source.direct ? blogPostMetrics.source.direct : 0,
blogPostMetrics.source && blogPostMetrics.source.email ? blogPostMetrics.source.email : 0
],
backgroundColor: [
'rgba(255, 206, 86, 0.3)',
'rgba(153, 102, 255, 0.3)',
'rgba(54, 162, 235, 0.3)'
],
borderColor: [
'rgb(255, 206, 86)',
'rgb(153, 102, 255)',
'rgb(54, 162, 235)'
],
borderWidth: 1
}
]}
/>
</div>
</div>
</div>
:
<></>
}
</div>
);
};


Page.getLayout = function getLayout(page) {
return (
<Layout>
{page}
</Layout>
)
}
Loading

0 comments on commit 47f9972

Please sign in to comment.