Compare commits
18 Commits
0.0.2
...
6b8d351fed
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b8d351fed | |||
| fd5093a1f8 | |||
| d3acf05b08 | |||
| bc6bfef6ea | |||
| eedb9a24f3 | |||
| 998c3d490d | |||
| bb3f733ffc | |||
| ce7b5dab6b | |||
| 13d52ec590 | |||
| 71ce77980d | |||
| 5943c08e73 | |||
| 2b26d5cf24 | |||
| bff42d0f0b | |||
| 38dc112d0a | |||
| 939a7eaba2 | |||
| e660c2bcb1 | |||
| 033f82208a | |||
| e38d9ed53b |
11
.drone.yml
11
.drone.yml
@@ -63,6 +63,9 @@ steps:
|
|||||||
|
|
||||||
- name: build-image
|
- name: build-image
|
||||||
image: docker:24
|
image: docker:24
|
||||||
|
environment:
|
||||||
|
API_BASE_URL:
|
||||||
|
from_secret: API_BASE_URL
|
||||||
volumes:
|
volumes:
|
||||||
- name: dockersock
|
- name: dockersock
|
||||||
path: /var/run/docker.sock
|
path: /var/run/docker.sock
|
||||||
@@ -70,7 +73,12 @@ steps:
|
|||||||
- IMAGE_TAG=$(cat /drone/src/LATEST_TAG.txt | tr -d '\n')
|
- IMAGE_TAG=$(cat /drone/src/LATEST_TAG.txt | tr -d '\n')
|
||||||
|
|
||||||
- echo "🔨 Building Docker image apps/blog:$IMAGE_TAG ..."
|
- echo "🔨 Building Docker image apps/blog:$IMAGE_TAG ..."
|
||||||
- docker build --network=host -t apps/blog:$IMAGE_TAG -t apps/blog:latest /drone/src
|
- |
|
||||||
|
docker build --network=host \
|
||||||
|
--build-arg VITE_API_BASE_URL="$API_BASE_URL" \
|
||||||
|
-t apps/blog:$IMAGE_TAG \
|
||||||
|
-t apps/blog:latest \
|
||||||
|
/drone/src
|
||||||
|
|
||||||
- name: push-image
|
- name: push-image
|
||||||
image: docker:24
|
image: docker:24
|
||||||
@@ -127,4 +135,3 @@ steps:
|
|||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
- tag
|
- tag
|
||||||
- custom
|
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
.env
|
||||||
# dependencies
|
# dependencies
|
||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ RUN npm ci
|
|||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build the app
|
# Build the app
|
||||||
RUN npm run build
|
ARG VITE_API_BASE_URL
|
||||||
|
RUN VITE_API_BASE_URL=$VITE_API_BASE_URL npm run build
|
||||||
|
|
||||||
# Stage 2: Production image
|
# Stage 2: Static file server (BusyBox)
|
||||||
FROM alpine:latest
|
FROM busybox:latest
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "material-ui-vite",
|
"name": "aetoskia-blog-app",
|
||||||
"version": "7.0.0",
|
"version": "0.0.8",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -56,10 +56,20 @@ export default function Blog(props: { disableCustomTheme?: boolean }) {
|
|||||||
<Container
|
<Container
|
||||||
maxWidth="lg"
|
maxWidth="lg"
|
||||||
component="main"
|
component="main"
|
||||||
sx={{ display: 'flex', flexDirection: 'column', my: 16, gap: 4 }}
|
sx={{ display: 'flex', flexDirection: 'column', my: 4, gap: 4 }}
|
||||||
>
|
>
|
||||||
{selectedArticle === null ? (
|
{selectedArticle === null ? (
|
||||||
<MainContent articles={articles} onSelectArticle={handleSelectArticle} />
|
<>
|
||||||
|
<MainContent articles={articles} onSelectArticle={handleSelectArticle} />
|
||||||
|
<Latest
|
||||||
|
articles={articles}
|
||||||
|
onSelectArticle={handleSelectArticle}
|
||||||
|
onLoadMore={async (offset, limit) => {
|
||||||
|
// Optional: fetch more from API (if you want true pagination)
|
||||||
|
// await fetchMoreArticles(offset, limit);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<Article article={articles[selectedArticle]} onBack={handleBack} />
|
<Article article={articles[selectedArticle]} onBack={handleBack} />
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -3,92 +3,13 @@ import Avatar from '@mui/material/Avatar';
|
|||||||
import AvatarGroup from '@mui/material/AvatarGroup';
|
import AvatarGroup from '@mui/material/AvatarGroup';
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
import Grid from '@mui/material/Grid';
|
import Grid from '@mui/material/Grid';
|
||||||
import Pagination from '@mui/material/Pagination';
|
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
import { styled } from '@mui/material/styles';
|
import { styled } from '@mui/material/styles';
|
||||||
import NavigateNextRoundedIcon from '@mui/icons-material/NavigateNextRounded';
|
import NavigateNextRoundedIcon from '@mui/icons-material/NavigateNextRounded';
|
||||||
|
import CircularProgress from '@mui/material/CircularProgress';
|
||||||
|
import type { Article } from '../providers/Article'; // ✅ import type for correctness
|
||||||
|
import Fade from '@mui/material/Fade'; // ✅ for smooth appearance
|
||||||
|
|
||||||
const articleInfo = [
|
|
||||||
{
|
|
||||||
tag: 'Engineering',
|
|
||||||
title: 'The future of AI in software engineering',
|
|
||||||
description:
|
|
||||||
'Artificial intelligence is revolutionizing software engineering. Explore how AI-driven tools are enhancing development processes and improving software quality.',
|
|
||||||
authors: [
|
|
||||||
{ name: 'Remy Sharp', avatar: '/static/images/avatar/1.jpg' },
|
|
||||||
{ name: 'Travis Howard', avatar: '/static/images/avatar/2.jpg' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tag: 'Product',
|
|
||||||
title: 'Driving growth with user-centric product design',
|
|
||||||
description:
|
|
||||||
'Our user-centric product design approach is driving significant growth. Learn about the strategies we employ to create products that resonate with users.',
|
|
||||||
authors: [{ name: 'Erica Johns', avatar: '/static/images/avatar/6.jpg' }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tag: 'Design',
|
|
||||||
title: 'Embracing minimalism in modern design',
|
|
||||||
description:
|
|
||||||
'Minimalism is a key trend in modern design. Discover how our design team incorporates minimalist principles to create clean and impactful user experiences.',
|
|
||||||
authors: [{ name: 'Kate Morrison', avatar: '/static/images/avatar/7.jpg' }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tag: 'Company',
|
|
||||||
title: 'Cultivating a culture of innovation',
|
|
||||||
description:
|
|
||||||
'Innovation is at the heart of our company culture. Learn about the initiatives we have in place to foster creativity and drive groundbreaking solutions.',
|
|
||||||
authors: [{ name: 'Cindy Baker', avatar: '/static/images/avatar/3.jpg' }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tag: 'Engineering',
|
|
||||||
title: 'Advancing cybersecurity with next-gen solutions',
|
|
||||||
description:
|
|
||||||
'Our next-generation cybersecurity solutions are setting new standards in the industry. Discover how we protect our clients from evolving cyber threats.',
|
|
||||||
authors: [
|
|
||||||
{ name: 'Agnes Walker', avatar: '/static/images/avatar/4.jpg' },
|
|
||||||
{ name: 'Trevor Henderson', avatar: '/static/images/avatar/5.jpg' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tag: 'Product',
|
|
||||||
title: 'Enhancing customer experience through innovation',
|
|
||||||
description:
|
|
||||||
'Our innovative approaches are enhancing customer experience. Learn about the new features and improvements that are delighting our users.',
|
|
||||||
authors: [{ name: 'Travis Howard', avatar: '/static/images/avatar/2.jpg' }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tag: 'Engineering',
|
|
||||||
title: 'Pioneering sustainable engineering solutions',
|
|
||||||
description:
|
|
||||||
"Learn about our commitment to sustainability and the innovative engineering solutions we're implementing to create a greener future. Discover the impact of our eco-friendly initiatives.",
|
|
||||||
authors: [
|
|
||||||
{ name: 'Agnes Walker', avatar: '/static/images/avatar/4.jpg' },
|
|
||||||
{ name: 'Trevor Henderson', avatar: '/static/images/avatar/5.jpg' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tag: 'Product',
|
|
||||||
title: 'Maximizing efficiency with our latest product updates',
|
|
||||||
description:
|
|
||||||
'Our recent product updates are designed to help you maximize efficiency and achieve more. Get a detailed overview of the new features and improvements that can elevate your workflow.',
|
|
||||||
authors: [{ name: 'Travis Howard', avatar: '/static/images/avatar/2.jpg' }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tag: 'Design',
|
|
||||||
title: 'Designing for the future: trends and insights',
|
|
||||||
description:
|
|
||||||
'Stay ahead of the curve with the latest design trends and insights. Our design team shares their expertise on creating intuitive and visually stunning user experiences.',
|
|
||||||
authors: [{ name: 'Kate Morrison', avatar: '/static/images/avatar/7.jpg' }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
tag: 'Company',
|
|
||||||
title: "Our company's journey: milestones and achievements",
|
|
||||||
description:
|
|
||||||
"Take a look at our company's journey and the milestones we've achieved along the way. From humble beginnings to industry leader, discover our story of growth and success.",
|
|
||||||
authors: [{ name: 'Cindy Baker', avatar: '/static/images/avatar/3.jpg' }],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const StyledTypography = styled(Typography)({
|
const StyledTypography = styled(Typography)({
|
||||||
display: '-webkit-box',
|
display: '-webkit-box',
|
||||||
@@ -160,73 +81,133 @@ function Author({ authors }: { authors: { name: string; avatar: string }[] }) {
|
|||||||
))}
|
))}
|
||||||
</AvatarGroup>
|
</AvatarGroup>
|
||||||
<Typography variant="caption">
|
<Typography variant="caption">
|
||||||
{authors.map((author) => author.name).join(', ')}
|
{authors.map((a) => a.name).join(', ')}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<Typography variant="caption">July 14, 2021</Typography>
|
<Typography variant="caption">Recently Updated</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Latest() {
|
// ---- Latest component ---- //
|
||||||
const [focusedCardIndex, setFocusedCardIndex] = React.useState<number | null>(
|
interface LatestProps {
|
||||||
null,
|
articles: Article[];
|
||||||
);
|
onSelectArticle?: (index: number) => void;
|
||||||
|
onLoadMore?: (offset: number, limit: number) => Promise<void>; // optional async callback
|
||||||
|
}
|
||||||
|
|
||||||
const handleFocus = (index: number) => {
|
export default function Latest({ articles, onSelectArticle, onLoadMore }: LatestProps) {
|
||||||
setFocusedCardIndex(index);
|
const [visibleCount, setVisibleCount] = React.useState(2);
|
||||||
};
|
const [loadingMore, setLoadingMore] = React.useState(false);
|
||||||
|
const [animating, setAnimating] = React.useState(false);
|
||||||
|
const loaderRef = React.useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
const handleBlur = () => {
|
const displayedArticles = articles.slice(0, visibleCount);
|
||||||
setFocusedCardIndex(null);
|
|
||||||
};
|
React.useEffect(() => {
|
||||||
|
if (!loaderRef.current) return;
|
||||||
|
|
||||||
|
const observer = new IntersectionObserver(
|
||||||
|
async (entries) => {
|
||||||
|
const first = entries[0];
|
||||||
|
if (first.isIntersecting && !loadingMore && visibleCount < articles.length) {
|
||||||
|
console.log('🟡 Intersection triggered — loading more blogs...');
|
||||||
|
setLoadingMore(true);
|
||||||
|
|
||||||
|
// simulate API load delay
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
|
||||||
|
if (onLoadMore) {
|
||||||
|
console.log(`📡 Calling onLoadMore(offset=${visibleCount}, limit=2)`);
|
||||||
|
await onLoadMore(visibleCount, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
setAnimating(true);
|
||||||
|
setVisibleCount((prev) => {
|
||||||
|
const newCount = prev + 2;
|
||||||
|
console.log(`✅ Increasing visibleCount from ${prev} → ${newCount}`);
|
||||||
|
return newCount;
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => setAnimating(false), 600);
|
||||||
|
setLoadingMore(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ threshold: 0.5 }
|
||||||
|
);
|
||||||
|
|
||||||
|
const current = loaderRef.current;
|
||||||
|
observer.observe(current);
|
||||||
|
|
||||||
|
console.log('👀 IntersectionObserver attached to loaderRef:', loaderRef.current);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (current) observer.unobserve(current);
|
||||||
|
console.log('🧹 IntersectionObserver detached');
|
||||||
|
};
|
||||||
|
}, [loadingMore, visibleCount, articles.length, onLoadMore]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Box>
|
||||||
<Typography variant="h2" gutterBottom>
|
<Typography variant="h2" gutterBottom>
|
||||||
Latest
|
Latest
|
||||||
</Typography>
|
</Typography>
|
||||||
<Grid container spacing={8} columns={12} sx={{ my: 4 }}>
|
<Grid container spacing={8} columns={12} sx={{ my: 4 }}>
|
||||||
{articleInfo.map((article, index) => (
|
{displayedArticles.map((article, index) => (
|
||||||
<Grid key={index} size={{ xs: 12, sm: 6 }}>
|
<Grid key={index} size={{ xs: 12, sm: 6 }}>
|
||||||
<Box
|
<Fade in timeout={animating ? 700 : 0}>
|
||||||
sx={{
|
<Box
|
||||||
display: 'flex',
|
sx={{
|
||||||
flexDirection: 'column',
|
display: 'flex',
|
||||||
justifyContent: 'space-between',
|
flexDirection: 'column',
|
||||||
gap: 1,
|
justifyContent: 'space-between',
|
||||||
height: '100%',
|
gap: 1,
|
||||||
}}
|
height: '100%',
|
||||||
>
|
transition: 'transform 0.3s ease',
|
||||||
<Typography gutterBottom variant="caption" component="div">
|
'&:hover': { transform: 'translateY(-3px)' },
|
||||||
{article.tag}
|
}}
|
||||||
</Typography>
|
|
||||||
<TitleTypography
|
|
||||||
gutterBottom
|
|
||||||
variant="h6"
|
|
||||||
onFocus={() => handleFocus(index)}
|
|
||||||
onBlur={handleBlur}
|
|
||||||
tabIndex={0}
|
|
||||||
className={focusedCardIndex === index ? 'Mui-focused' : ''}
|
|
||||||
>
|
>
|
||||||
{article.title}
|
<Typography gutterBottom variant="caption" component="div">
|
||||||
<NavigateNextRoundedIcon
|
{article.tag}
|
||||||
className="arrow"
|
</Typography>
|
||||||
sx={{ fontSize: '1rem' }}
|
|
||||||
/>
|
|
||||||
</TitleTypography>
|
|
||||||
<StyledTypography variant="body2" color="text.secondary" gutterBottom>
|
|
||||||
{article.description}
|
|
||||||
</StyledTypography>
|
|
||||||
|
|
||||||
<Author authors={article.authors} />
|
<TitleTypography
|
||||||
</Box>
|
gutterBottom
|
||||||
|
variant="h6"
|
||||||
|
tabIndex={0}
|
||||||
|
onClick={() => onSelectArticle?.(index)}
|
||||||
|
>
|
||||||
|
{article.title}
|
||||||
|
<NavigateNextRoundedIcon className="arrow" sx={{ fontSize: '1rem' }} />
|
||||||
|
</TitleTypography>
|
||||||
|
|
||||||
|
<StyledTypography variant="body2" color="text.secondary" gutterBottom>
|
||||||
|
{article.description}
|
||||||
|
</StyledTypography>
|
||||||
|
|
||||||
|
<Author authors={article.authors} />
|
||||||
|
</Box>
|
||||||
|
</Fade>
|
||||||
</Grid>
|
</Grid>
|
||||||
))}
|
))}
|
||||||
</Grid>
|
</Grid>
|
||||||
<Box sx={{ display: 'flex', flexDirection: 'row', pt: 4 }}>
|
|
||||||
<Pagination hidePrevButton hideNextButton count={10} boundaryCount={10} />
|
<Box
|
||||||
|
ref={loaderRef}
|
||||||
|
sx={{
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
py: 3,
|
||||||
|
opacity: loadingMore ? 1 : 0.6,
|
||||||
|
transition: 'opacity 0.4s ease',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{loadingMore ? (
|
||||||
|
<CircularProgress size={32} thickness={5} />
|
||||||
|
) : (
|
||||||
|
<Typography variant="caption">Scroll to load more...</Typography>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</div>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import { styled } from '@mui/material/styles';
|
|||||||
import SearchRoundedIcon from '@mui/icons-material/SearchRounded';
|
import SearchRoundedIcon from '@mui/icons-material/SearchRounded';
|
||||||
import RssFeedRoundedIcon from '@mui/icons-material/RssFeedRounded';
|
import RssFeedRoundedIcon from '@mui/icons-material/RssFeedRounded';
|
||||||
|
|
||||||
import { useArticles } from '../providers/Article';
|
|
||||||
|
|
||||||
const StyledCard = styled(Card)(({ theme }) => ({
|
const StyledCard = styled(Card)(({ theme }) => ({
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
|
|||||||
@@ -2,18 +2,26 @@ import React, { createContext, useState, useContext, useEffect } from 'react';
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
interface Author {
|
interface Author {
|
||||||
|
_id?: string | null;
|
||||||
|
username: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
email: string;
|
||||||
avatar: string;
|
avatar: string;
|
||||||
|
is_active: boolean;
|
||||||
|
created_at?: string;
|
||||||
|
updated_at?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Article {
|
export interface Article {
|
||||||
id: string;
|
_id?: string | null;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
img: string;
|
||||||
tag: string;
|
tag: string;
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
img: string;
|
content: string;
|
||||||
authors: Author[];
|
authors: Author[];
|
||||||
date?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ArticleContextType {
|
interface ArticleContextType {
|
||||||
@@ -23,7 +31,9 @@ interface ArticleContextType {
|
|||||||
refreshArticles: () => Promise<void>;
|
refreshArticles: () => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Article = createContext<ArticleContextType | undefined>(undefined);
|
const ArticleContext = createContext<ArticleContextType | undefined>(undefined);
|
||||||
|
|
||||||
|
const API_BASE = import.meta.env.VITE_API_BASE_URL;
|
||||||
|
|
||||||
export const ArticleProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
export const ArticleProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||||
const [articles, setArticles] = useState<Article[]>([]);
|
const [articles, setArticles] = useState<Article[]>([]);
|
||||||
@@ -32,88 +42,23 @@ export const ArticleProvider: React.FC<{ children: React.ReactNode }> = ({ child
|
|||||||
|
|
||||||
const fetchArticles = async () => {
|
const fetchArticles = async () => {
|
||||||
try {
|
try {
|
||||||
// ✅ Use static defaults first
|
|
||||||
const defaults = [
|
|
||||||
{
|
|
||||||
img: 'https://picsum.photos/800/450?random=1',
|
|
||||||
tag: 'Engineering',
|
|
||||||
title: 'Revolutionizing software development with cutting-edge tools',
|
|
||||||
description:
|
|
||||||
'Our latest engineering tools are designed to streamline workflows and boost productivity. Discover how these innovations are transforming the software development landscape.',
|
|
||||||
content:
|
|
||||||
'Our latest engineering tools are designed to streamline workflows and boost productivity. Discover how these innovations are transforming the software development landscape.',
|
|
||||||
authors: [
|
|
||||||
{ name: 'Remy Sharp', avatar: '/static/images/avatar/1.jpg' },
|
|
||||||
{ name: 'Travis Howard', avatar: '/static/images/avatar/2.jpg' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
img: 'https://picsum.photos/800/450?random=2',
|
|
||||||
tag: 'Product',
|
|
||||||
title: 'Innovative product features that drive success',
|
|
||||||
description:
|
|
||||||
'Explore the key features of our latest product release that are helping businesses achieve their goals. From user-friendly interfaces to robust functionality, learn why our product stands out.',
|
|
||||||
content:
|
|
||||||
'Explore the key features of our latest product release that are helping businesses achieve their goals. From user-friendly interfaces to robust functionality, learn why our product stands out.',
|
|
||||||
authors: [{ name: 'Erica Johns', avatar: '/static/images/avatar/6.jpg' }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
img: 'https://picsum.photos/800/450?random=3',
|
|
||||||
tag: 'Design',
|
|
||||||
title: 'Designing for the future: trends and insights',
|
|
||||||
description:
|
|
||||||
'Stay ahead of the curve with the latest design trends and insights. Our design team shares their expertise on creating intuitive and visually stunning user experiences.',
|
|
||||||
content:
|
|
||||||
'Stay ahead of the curve with the latest design trends and insights. Our design team shares their expertise on creating intuitive and visually stunning user experiences.',
|
|
||||||
authors: [{ name: 'Kate Morrison', avatar: '/static/images/avatar/7.jpg' }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
img: 'https://picsum.photos/800/450?random=4',
|
|
||||||
tag: 'Company',
|
|
||||||
title: "Our company's journey: milestones and achievements",
|
|
||||||
description:
|
|
||||||
"Take a look at our company's journey and the milestones we've achieved along the way. From humble beginnings to industry leader, discover our story of growth and success.",
|
|
||||||
content:
|
|
||||||
"Take a look at our company's journey and the milestones we've achieved along the way. From humble beginnings to industry leader, discover our story of growth and success.",
|
|
||||||
authors: [{ name: 'Cindy Baker', avatar: '/static/images/avatar/3.jpg' }],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
img: 'https://picsum.photos/800/450?random=45',
|
|
||||||
tag: 'Engineering',
|
|
||||||
title: 'Pioneering sustainable engineering solutions',
|
|
||||||
description:
|
|
||||||
"Learn about our commitment to sustainability and the innovative engineering solutions we're implementing to create a greener future. Discover the impact of our eco-friendly initiatives.",
|
|
||||||
content:
|
|
||||||
"Learn about our commitment to sustainability and the innovative engineering solutions we're implementing to create a greener future. Discover the impact of our eco-friendly initiatives.",
|
|
||||||
authors: [
|
|
||||||
{ name: 'Agnes Walker', avatar: '/static/images/avatar/4.jpg' },
|
|
||||||
{ name: 'Trevor Henderson', avatar: '/static/images/avatar/5.jpg' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
img: 'https://picsum.photos/800/450?random=6',
|
|
||||||
tag: 'Product',
|
|
||||||
title: 'Maximizing efficiency with our latest product updates',
|
|
||||||
description:
|
|
||||||
'Our recent product updates are designed to help you maximize efficiency and achieve more. Get a detailed overview of the new features and improvements that can elevate your workflow.',
|
|
||||||
content:
|
|
||||||
'Our recent product updates are designed to help you maximize efficiency and achieve more. Get a detailed overview of the new features and improvements that can elevate your workflow.',
|
|
||||||
authors: [{ name: 'Travis Howard', avatar: '/static/images/avatar/2.jpg' }],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
// ✅ For now: only use defaults
|
|
||||||
// @ts-ignore
|
|
||||||
setArticles(defaults);
|
|
||||||
setLoading(false);
|
|
||||||
|
|
||||||
// 🔜 Optional: uncomment this to fetch from API when backend is ready
|
|
||||||
/*
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const res = await axios.get('/articles');
|
setError(null);
|
||||||
setArticles(res.data);
|
|
||||||
*/
|
// ✅ Use correct full endpoint from OpenAPI spec
|
||||||
|
const res = await axios.get<Article[]>(`${API_BASE}/articles`, {
|
||||||
|
params: { skip: 0, limit: 10 },
|
||||||
|
});
|
||||||
|
|
||||||
|
// ✅ Normalize if backend sends _id instead of id
|
||||||
|
const formatted = res.data.map((a) => ({
|
||||||
|
...a,
|
||||||
|
id: a._id || undefined,
|
||||||
|
}));
|
||||||
|
|
||||||
|
setArticles(formatted);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
console.error('Failed to fetch articles:', err);
|
||||||
setError(err.message || 'Failed to fetch articles');
|
setError(err.message || 'Failed to fetch articles');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -125,14 +70,14 @@ export const ArticleProvider: React.FC<{ children: React.ReactNode }> = ({ child
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Article.Provider value={{ articles, loading, error, refreshArticles: fetchArticles }}>
|
<ArticleContext.Provider value={{ articles, loading, error, refreshArticles: fetchArticles }}>
|
||||||
{children}
|
{children}
|
||||||
</Article.Provider>
|
</ArticleContext.Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useArticles = (): ArticleContextType => {
|
export const useArticles = (): ArticleContextType => {
|
||||||
const ctx = useContext(Article);
|
const ctx = useContext(ArticleContext);
|
||||||
if (!ctx) throw new Error('useArticles must be used inside ArticleProvider');
|
if (!ctx) throw new Error('useArticles must be used inside ArticleProvider');
|
||||||
return ctx;
|
return ctx;
|
||||||
};
|
};
|
||||||
|
|||||||
9
src/vite-env.d.ts
vendored
Normal file
9
src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/// <reference types="vite/client" />
|
||||||
|
|
||||||
|
interface ImportMetaEnv {
|
||||||
|
readonly VITE_API_BASE_URL: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImportMeta {
|
||||||
|
readonly env: ImportMetaEnv;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user