add static posts page
This commit is contained in:
parent
94e396bffd
commit
9fd0d86873
16
backend/src/routes/pure_sql_posts.js
Normal file
16
backend/src/routes/pure_sql_posts.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const { sequelize } = require('../db/models');
|
||||||
|
|
||||||
|
// Endpoint to fetch posts using a pure SQL query
|
||||||
|
router.get('/pure-sql-posts', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const [rows] = await sequelize.query('SELECT * FROM posts ORDER BY posted_at DESC');
|
||||||
|
res.json(rows);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching posts:', error);
|
||||||
|
res.status(500).json({ error: 'Internal server error' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@ -85,7 +85,7 @@ const AsideMenuItem = ({ item, isDropdownList = false }: Props) => {
|
|||||||
].join(' ');
|
].join(' ');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li className={'px-3 py-1.5'}>
|
<li className={'px-2 py-1'}>
|
||||||
{item.withDevider && <hr className={`${borders} mb-3`} />}
|
{item.withDevider && <hr className={`${borders} mb-3`} />}
|
||||||
{item.href && (
|
{item.href && (
|
||||||
<Link href={item.href} target={item.target} className={componentClass}>
|
<Link href={item.href} target={item.target} className={componentClass}>
|
||||||
|
|||||||
18
frontend/src/pages/posts.tsx
Normal file
18
frontend/src/pages/posts.tsx
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { ReactElement } from 'react';
|
||||||
|
import LayoutGuest from '../layouts/Guest';
|
||||||
|
|
||||||
|
const PostsPage = () => {
|
||||||
|
return (
|
||||||
|
<div className="container mx-auto p-4">
|
||||||
|
<h1 className="text-2xl font-bold mb-4">Posts</h1>
|
||||||
|
<p>This is a static posts page. Content coming soon!</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
PostsPage.getLayout = function getLayout(page: ReactElement) {
|
||||||
|
return <LayoutGuest>{page}</LayoutGuest>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PostsPage;
|
||||||
@ -41,6 +41,7 @@ export default function WebSite() {
|
|||||||
label: 'home',
|
label: 'home',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{ href: '/posts', label: 'posts' },
|
||||||
{
|
{
|
||||||
href: '/about',
|
href: '/about',
|
||||||
label: 'about',
|
label: 'about',
|
||||||
|
|||||||
48
frontend/src/pages/web_pages/posts.tsx
Normal file
48
frontend/src/pages/web_pages/posts.tsx
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import React, { useEffect, useState } from "react";
|
||||||
|
import WebsiteHeader from "../components/WebsiteHeader";
|
||||||
|
import WebsiteFooter from "../components/WebsiteFooter";
|
||||||
|
|
||||||
|
const PostsPage = () => {
|
||||||
|
const [posts, setPosts] = useState([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchPosts = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/pure-sql-posts');
|
||||||
|
if (response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
|
setPosts(data);
|
||||||
|
} else {
|
||||||
|
console.error('Failed to fetch posts');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching posts:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchPosts();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<WebsiteHeader />
|
||||||
|
<div className="container mx-auto p-4">
|
||||||
|
<h1 className="text-3xl font-bold mb-4">Posts</h1>
|
||||||
|
<div className="grid gap-4 grid-cols-1 md:grid-cols-2">
|
||||||
|
{posts.map((post) => (
|
||||||
|
<div key={post.id} className="bg-white shadow rounded p-4">
|
||||||
|
{/* Display content of the post and posted date. Adjust accordingly if more fields are needed. */}
|
||||||
|
<p className="mt-2">{post.content}</p>
|
||||||
|
<p className="text-sm text-gray-500 mt-2">
|
||||||
|
{new Date(post.posted_at).toLocaleString()}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<WebsiteFooter />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PostsPage;
|
||||||
Loading…
x
Reference in New Issue
Block a user