Compare commits
8 Commits
0.0.5
...
6b8d351fed
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b8d351fed | |||
| fd5093a1f8 | |||
| d3acf05b08 | |||
| bc6bfef6ea | |||
| eedb9a24f3 | |||
| 998c3d490d | |||
| bb3f733ffc | |||
| ce7b5dab6b |
14
.drone.yml
14
.drone.yml
@@ -63,6 +63,9 @@ steps:
|
||||
|
||||
- name: build-image
|
||||
image: docker:24
|
||||
environment:
|
||||
API_BASE_URL:
|
||||
from_secret: API_BASE_URL
|
||||
volumes:
|
||||
- name: dockersock
|
||||
path: /var/run/docker.sock
|
||||
@@ -70,7 +73,12 @@ steps:
|
||||
- IMAGE_TAG=$(cat /drone/src/LATEST_TAG.txt | tr -d '\n')
|
||||
|
||||
- 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
|
||||
image: docker:24
|
||||
@@ -108,9 +116,6 @@ steps:
|
||||
|
||||
- name: run-container
|
||||
image: docker:24
|
||||
environment:
|
||||
API_BASE_URL:
|
||||
from_secret: API_BASE_URL
|
||||
volumes:
|
||||
- name: dockersock
|
||||
path: /var/run/docker.sock
|
||||
@@ -123,7 +128,6 @@ steps:
|
||||
--name blog \
|
||||
-p 3002:3000 \
|
||||
-e NODE_ENV=production \
|
||||
-e VITE_API_BASE_URL="$API_BASE_URL" \
|
||||
--restart always \
|
||||
apps/blog:$IMAGE_TAG
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ RUN npm ci
|
||||
COPY . .
|
||||
|
||||
# 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: Static file server (BusyBox)
|
||||
FROM busybox:latest
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "aetoskia-blog-app",
|
||||
"version": "0.0.4",
|
||||
"version": "0.0.8",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -56,12 +56,19 @@ export default function Blog(props: { disableCustomTheme?: boolean }) {
|
||||
<Container
|
||||
maxWidth="lg"
|
||||
component="main"
|
||||
sx={{ display: 'flex', flexDirection: 'column', my: 16, gap: 4 }}
|
||||
sx={{ display: 'flex', flexDirection: 'column', my: 4, gap: 4 }}
|
||||
>
|
||||
{selectedArticle === null ? (
|
||||
<>
|
||||
<MainContent articles={articles} onSelectArticle={handleSelectArticle} />
|
||||
<Latest articles={articles.slice(0, 3)} /> {/* show 3 most recent */}
|
||||
<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} />
|
||||
|
||||
@@ -3,11 +3,12 @@ import Avatar from '@mui/material/Avatar';
|
||||
import AvatarGroup from '@mui/material/AvatarGroup';
|
||||
import Box from '@mui/material/Box';
|
||||
import Grid from '@mui/material/Grid';
|
||||
import Pagination from '@mui/material/Pagination';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import { styled } from '@mui/material/styles';
|
||||
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 StyledTypography = styled(Typography)({
|
||||
@@ -92,25 +93,69 @@ function Author({ authors }: { authors: { name: string; avatar: string }[] }) {
|
||||
interface LatestProps {
|
||||
articles: Article[];
|
||||
onSelectArticle?: (index: number) => void;
|
||||
onLoadMore?: (offset: number, limit: number) => Promise<void>; // optional async callback
|
||||
}
|
||||
|
||||
export default function Latest({ articles, onSelectArticle }: LatestProps) {
|
||||
const [focusedCardIndex, setFocusedCardIndex] = React.useState<number | null>(null);
|
||||
export default function Latest({ articles, onSelectArticle, onLoadMore }: LatestProps) {
|
||||
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 handleFocus = (index: number) => setFocusedCardIndex(index);
|
||||
const handleBlur = () => setFocusedCardIndex(null);
|
||||
const displayedArticles = articles.slice(0, visibleCount);
|
||||
|
||||
// limit to 4-6 items for visual balance
|
||||
const displayedArticles = articles.slice(0, 6);
|
||||
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 (
|
||||
<div>
|
||||
<Box>
|
||||
<Typography variant="h2" gutterBottom>
|
||||
Latest
|
||||
</Typography>
|
||||
<Grid container spacing={8} columns={12} sx={{ my: 4 }}>
|
||||
{displayedArticles.map((article, index) => (
|
||||
<Grid key={index} size={{ xs: 12, sm: 6 }}>
|
||||
<Fade in timeout={animating ? 700 : 0}>
|
||||
<Box
|
||||
sx={{
|
||||
display: 'flex',
|
||||
@@ -118,6 +163,8 @@ export default function Latest({ articles, onSelectArticle }: LatestProps) {
|
||||
justifyContent: 'space-between',
|
||||
gap: 1,
|
||||
height: '100%',
|
||||
transition: 'transform 0.3s ease',
|
||||
'&:hover': { transform: 'translateY(-3px)' },
|
||||
}}
|
||||
>
|
||||
<Typography gutterBottom variant="caption" component="div">
|
||||
@@ -128,29 +175,39 @@ export default function Latest({ articles, onSelectArticle }: LatestProps) {
|
||||
gutterBottom
|
||||
variant="h6"
|
||||
tabIndex={0}
|
||||
onFocus={() => handleFocus(index)}
|
||||
onBlur={handleBlur}
|
||||
onClick={() => onSelectArticle?.(index)}
|
||||
className={focusedCardIndex === index ? 'Mui-focused' : ''}
|
||||
>
|
||||
{article.title}
|
||||
<NavigateNextRoundedIcon
|
||||
className="arrow"
|
||||
sx={{ fontSize: '1rem' }}
|
||||
/>
|
||||
<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>
|
||||
<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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import { styled } from '@mui/material/styles';
|
||||
import SearchRoundedIcon from '@mui/icons-material/SearchRounded';
|
||||
import RssFeedRoundedIcon from '@mui/icons-material/RssFeedRounded';
|
||||
|
||||
import { useArticles } from '../providers/Article';
|
||||
|
||||
const StyledCard = styled(Card)(({ theme }) => ({
|
||||
display: 'flex',
|
||||
|
||||
Reference in New Issue
Block a user