import { useEffect, useMemo, useReducer, useState } from 'react';
import { MiniTitle } from '../../ui/MiniTitle';
import { useWindowWidth } from '../../hooks/useWindowWidth';
import { Title } from '../../ui/Title';
import { useSwipeable } from 'react-swipeable';
export function Projects() {
return (
Большой опыт в работе с
промышленными предприятиями и учебными заведениями
);
}
function Project({
src,
title,
tags,
}: {
src: string;
title: string;
tags: string[];
}) {
return (
{title}
{tags.map(tag => (
{tag}
))}
);
}
function Slider({
projects,
}: {
projects: { src: string; title: string; tags: string[] }[];
}) {
const width = useWindowWidth();
const baseOffset = useMemo(
() => (width >= 1024 ? 640 : width >= 640 ? 536 : 336),
[width],
);
const [sliderOffset, setSliderOffset] = useState(-baseOffset);
const [slide, setSlide] = useState(0);
const [order, dispatch] = useReducer(
(state: typeof projects, action: string) => {
if (action === 'next') {
setSliderOffset(prev => prev + baseOffset);
return [...state.slice(1), state[2]];
}
if (action === 'prev') {
setSliderOffset(-baseOffset * 2);
return [state[state.length - 3], ...state.slice(0, -1)];
}
return state;
},
[projects[projects.length - 1], ...projects, projects[0]],
);
const handlers = useSwipeable({
onSwipedLeft: () => {
setSlide(prev => (prev === order.length - 3 ? 0 : prev + 1));
dispatch('next');
},
onSwipedRight: () => {
setSlide(prev => (prev === 0 ? order.length - 3 : prev - 1));
dispatch('prev');
},
trackMouse: true,
preventScrollOnSwipe: true,
touchEventOptions: { passive: false },
});
useEffect(() => {
setSliderOffset(-baseOffset);
}, [order, baseOffset, slide]);
return (
{order.map((project, index) => (
))}
);
}