📅  最后修改于: 2023-12-03 15:14:05.915000             🧑  作者: Mango
Captain Tsubasa Episodi是一个基于TypeScript开发的在线观看Captain Tsubasa动画片的网站。该网站使用React框架和Material-UI库搭建,并使用了Redux进行数据管理。
// 定义action类型
type ActionType = "ADD_FAVORITE" | "REMOVE_FAVORITE" | "CLEAR_FAVORITES";
// 定义action creator
export const addFavorite = (item: Item): Action => ({
type: "ADD_FAVORITE",
payload: item
});
export const removeFavorite = (id: string): Action => ({
type: "REMOVE_FAVORITE",
payload: id
});
export const clearFavorites = (): Action => ({
type: "CLEAR_FAVORITES"
});
// 定义reducer
const initialState: State = {
favorites: []
};
export const reducer = (state = initialState, action: Action): State => {
switch (action.type) {
case "ADD_FAVORITE":
return {
...state,
favorites: [...state.favorites, action.payload]
};
case "REMOVE_FAVORITE":
return {
...state,
favorites: state.favorites.filter(item => item.id !== action.payload)
};
case "CLEAR_FAVORITES":
return {
...state,
favorites: []
};
default:
return state;
}
};
interface Props {
item: Item;
onHover: () => void;
onLeave: () => void;
onFavorite: () => void;
isFavorite: boolean;
}
export const ListItem = ({
item,
onHover,
onLeave,
onFavorite,
isFavorite
}: Props) => {
const [showOverlay, setShowOverlay] = useState(false);
const handleMouseEnter = () => {
setShowOverlay(true);
onHover();
};
const handleMouseLeave = () => {
setShowOverlay(false);
onLeave();
};
return (
<div
className="list-item"
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<img src={item.image} alt={item.title} />
{showOverlay && (
<div className="overlay">
<h4>{item.title}</h4>
<div className="actions">
{!isFavorite ? (
<IconButton onClick={onFavorite}>
<FavoriteBorderIcon />
</IconButton>
) : (
<IconButton onClick={onFavorite} color="secondary">
<FavoriteIcon />
</IconButton>
)}
</div>
</div>
)}
</div>
);
};
Captain Tsubasa Episodi是一个使用TypeScript开发的在线观看Captain Tsubasa动画片的网站,使用了React框架和Material-UI库搭建,并使用了Redux进行数据管理。程序员可以通过阅读代码示例,深入了解前端的开发,包括组件化开发、Redux数据管理等方面。