This commit is contained in:
2024-09-05 18:01:00 +02:00
parent b76e3cb1b8
commit 480d47de01
14 changed files with 1900 additions and 184 deletions

View File

@@ -1,24 +1,24 @@
import logo from './logo.svg';
import './App.css';
import React from "react";
import "./styles/App.css";
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";
import PosterSelector from "./components/PosterSelector";
import PosterGallery from "./components/PosterGallery";
import UploadDiary from "./components/UploadDiary";
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
<Router>
<div className="App">
<Routes>
<Route path="/" element={<UploadDiary />} />
<Route path="/PosterSelector" element={<PosterSelector />} />
<Route
path="/posters/:movieName/:movieYear"
element={<PosterGallery />}
/>
</Routes>
</div>
</Router>
);
}

View File

@@ -1,8 +0,0 @@
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

View File

@@ -0,0 +1,108 @@
import React, { useState, useEffect } from "react";
import { useParams } from "react-router-dom";
import axios from "axios";
import {
Container,
Typography,
Grid,
Card,
CardMedia,
CircularProgress,
Box,
makeStyles,
Paper,
} from "@material-ui/core";
const useStyles = makeStyles((theme) => ({
root: {
marginTop: theme.spacing(4),
},
paper: {
padding: theme.spacing(3),
borderRadius: theme.shape.borderRadius,
backgroundColor: "#1c1f23",
},
title: {
color: "white",
marginBottom: theme.spacing(3),
fontSize: "2rem",
fontWeight: "400",
},
posterCard: {
height: "100%",
display: "flex",
flexDirection: "column",
backgroundColor: "transparent",
boxShadow: "none",
},
posterImage: {
paddingTop: "150%",
backgroundSize: "contain",
backgroundPosition: "center",
backgroundRepeat: "no-repeat",
borderRadius: theme.shape.borderRadius,
transition: "transform 0.3s ease-in-out",
},
loadingContainer: {
display: "flex",
justifyContent: "center",
alignItems: "center",
height: "50vh",
},
}));
const PosterGallery = () => {
const classes = useStyles();
const [posters, setPosters] = useState([]);
const [loading, setLoading] = useState(true);
const { movieName, movieYear } = useParams();
useEffect(() => {
const fetchPosters = async () => {
try {
setLoading(true);
const response = await axios.get(
`http://localhost:5000/api/posters/${movieName}/${movieYear}`
);
setPosters(response.data.posters);
} catch (error) {
console.error("Error fetching posters:", error);
} finally {
setLoading(false);
}
};
fetchPosters();
}, [movieName, movieYear]);
return (
<Container className={classes.root}>
<Paper elevation={3} className={classes.paper}>
<Typography variant="h4" gutterBottom className={classes.title}>
Posters for {movieName} ({movieYear})
</Typography>
{loading ? (
<Box className={classes.loadingContainer}>
<CircularProgress />
</Box>
) : (
<Grid container spacing={3}>
{posters.map((poster, index) => (
<Grid item xs={12} sm={6} md={4} lg={3} key={index}>
<Card className={classes.posterCard}>
<CardMedia
className={classes.posterImage}
image={`https://image.tmdb.org/t/p/w500${poster.file_path}`}
title={`${movieName} poster ${index + 1}`}
/>
</Card>
</Grid>
))}
</Grid>
)}
</Paper>
</Container>
);
};
export default PosterGallery;

View File

@@ -0,0 +1,313 @@
import React, { useState, useEffect } from "react";
import axios from "axios";
import { useNavigate, useLocation } from "react-router-dom";
import {
Container,
List,
ListItem,
Grid,
Typography,
LinearProgress,
Box,
Paper,
makeStyles,
Button,
} from "@material-ui/core";
import Pagination from "@mui/material/Pagination";
import { createTheme, ThemeProvider } from "@mui/material/styles";
import queryString from "query-string";
const useStyles = makeStyles((theme) => ({
root: {
marginTop: theme.spacing(4),
},
paper: {
padding: theme.spacing(3),
borderRadius: theme.shape.borderRadius,
backgroundColor: "#1c1f23",
},
title: {
color: "white",
marginBottom: theme.spacing(3),
},
list: {
maxHeight: "800px",
minHeight: "1000px",
},
listItem: {
marginBottom: theme.spacing(2),
"&:hover": {
backgroundColor: theme.palette.action.hover,
},
"&:not(:last-child)": {
borderBottom: `1px solid #667788`,
paddingTop: theme.spacing(0.5),
paddingBottom: theme.spacing(0.5),
},
},
poster: {
width: "50px",
height: "75px",
objectFit: "cover",
marginRight: theme.spacing(2),
borderRadius: theme.shape.borderRadius,
},
movieInfo: {
flexGrow: 1,
},
movieTitle: {
color: "white",
fontFamily: "TiemposTextWeb-Semibold, Georgia, serif",
fontSize: "1.38461538rem",
fontWeight: "400",
"&:hover": {
color: "var(--primary)",
},
},
movieYear: {
color: "#667788",
},
watchedDate: {
color: "#667788",
textAlign: "center",
},
watchedDay: {
fontSize: "2rem",
},
refreshButton: {
marginTop: theme.spacing(2),
},
paginationContainer: {
display: "flex",
justifyContent: "center",
marginTop: theme.spacing(3),
},
progressContainer: {
display: "flex",
justifyContent: "center",
alignItems: "center",
flexDirection: "column",
height: "200px", // Adjust height as needed to keep component size consistent
},
progressLabel: {
marginTop: theme.spacing(2),
color: "white",
},
}));
const paginationTheme = createTheme({
palette: {
mode: "dark",
primary: {
main: "#667788",
},
text: {
primary: "#ffffff",
secondary: "#667788",
},
action: {
hover: "rgba(102, 119, 136, 0.2)",
},
},
components: {
MuiPaginationItem: {
styleOverrides: {
root: {
"&.Mui-selected": {
backgroundColor: "#667788",
color: "#ffffff",
"&:hover": {
backgroundColor: "#778899",
},
},
},
},
},
},
});
const PosterSelector = () => {
const classes = useStyles();
const [movies, setMovies] = useState([]);
const [loading, setLoading] = useState(true);
const [page, setPage] = useState(1);
const [totalPages, setTotalPages] = useState(1);
const [progress, setProgress] = useState(0);
const navigate = useNavigate();
const location = useLocation();
const moviesPerPage = 10;
useEffect(() => {
const parsed = queryString.parse(location.search);
const pageNumber = parsed.page ? parseInt(parsed.page, 10) : 1;
setPage(pageNumber);
fetchMovies(pageNumber);
}, [location.search]);
const fetchMovies = async (pageNumber) => {
try {
setLoading(true);
setProgress(0);
const response = await axios.get(
`http://localhost:5000/api/movies?page=${pageNumber}&limit=${moviesPerPage}`,
{
onDownloadProgress: (progressEvent) => {
const percentCompleted = Math.round(
(progressEvent.loaded * 100) / progressEvent.total
);
setProgress(percentCompleted);
},
}
);
if (response.data.movies) {
setMovies(response.data.movies);
setTotalPages(Math.ceil(response.data.total / moviesPerPage));
}
} catch (error) {
console.error("Error fetching movies:", error);
} finally {
setLoading(false);
}
};
const handleMovieClick = (movieName, movieYear) => {
navigate(
`/posters/${encodeURIComponent(movieName)}/${encodeURIComponent(
movieYear
)}?page=${page}`
);
};
const handleRefreshFiles = async () => {
try {
await axios.delete("http://localhost:5000/api/delete-csv");
navigate("/");
} catch (error) {
console.error("Error deleting CSV file:", error);
}
};
const handlePageChange = (event, value) => {
setPage(value);
navigate(`?page=${value}`);
};
const formatWatchedDate = (dateString) => {
const date = new Date(dateString);
const day = date.getDate().toString().padStart(2, "0");
const month = date
.toLocaleString("default", { month: "short" })
.toUpperCase();
return { day, month };
};
return (
<Container className={classes.root}>
<Paper elevation={3} className={classes.paper}>
<Typography variant="h4" gutterBottom className={classes.title}>
Your diary
</Typography>
{loading ? (
<Box className={classes.progressContainer}>
<LinearProgress variant="determinate" value={progress} />
<Typography className={classes.progressLabel}>
Downloading movies...
</Typography>
</Box>
) : movies.length > 0 ? (
<List className={classes.list}>
{movies.map((movie, index) => (
<ListItem
button
key={index}
onClick={() => handleMovieClick(movie.Name, movie.Year)}
className={classes.listItem}
>
<Grid container alignItems="center">
<Grid item>
<img
src={
`https://image.tmdb.org/t/p/w500${movie.Poster.file_path}` ||
`/api/placeholder/50/75`
}
alt={movie.Name}
className={classes.poster}
/>
</Grid>
<Grid item className={classes.movieInfo}>
<Typography
variant="subtitle1"
className={classes.movieTitle}
>
{movie.Name}
</Typography>
<Typography
variant="body2"
color="textSecondary"
className={classes.movieYear}
>
{movie.Year}
</Typography>
</Grid>
<Grid item>
<Box className={classes.watchedDate}>
{(() => {
const { day, month } = formatWatchedDate(
movie["Watched Date"]
);
return (
<>
<Typography
variant="body2"
className={classes.watchedDay}
>
{day}
</Typography>
<Typography
variant="body2"
className={classes.watchedMonth}
>
{month}
</Typography>
</>
);
})()}
</Box>
</Grid>
</Grid>
</ListItem>
))}
</List>
) : (
<Box>
<Typography variant="body1" color="textSecondary" gutterBottom>
No movies to display. Upload a CSV file to get started.
</Typography>
</Box>
)}
<Box className={classes.paginationContainer}>
<ThemeProvider theme={paginationTheme}>
<Pagination
count={totalPages}
page={page}
onChange={handlePageChange}
color="primary"
/>
</ThemeProvider>
</Box>
<Button
variant="contained"
className={classes.refreshButton}
onClick={handleRefreshFiles}
>
Refresh File
</Button>
</Paper>
</Container>
);
};
export default PosterSelector;

View File

@@ -0,0 +1,206 @@
import React, { useState, useEffect } from "react";
import { useNavigate } from "react-router-dom";
import {
Container,
Grid,
Typography,
Button,
CircularProgress,
makeStyles,
} from "@material-ui/core";
import { CloudUploadOutlined } from "@material-ui/icons";
import CloudDoneOutlinedIcon from "@mui/icons-material/CloudDoneOutlined";
import { useDropzone } from "react-dropzone";
import axios from "axios";
const useStyles = makeStyles((theme) => ({
root: {
padding: theme.spacing(4),
backgroundColor: "#14181c",
minHeight: "100vh",
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
},
card: {
width: "100%",
maxWidth: "600px",
backgroundColor: "#1c1f23",
borderRadius: theme.shape.borderRadius,
boxShadow: theme.shadows[3],
padding: theme.spacing(4),
},
title: {
marginBottom: theme.spacing(3),
fontWeight: "bold",
color: "#ffffff",
},
dropzone: {
border: `2px dashed #00A346`,
borderRadius: theme.shape.borderRadius,
padding: theme.spacing(4),
textAlign: "center",
cursor: "pointer",
"&:hover": {
backgroundColor: "#1f252a",
},
},
dropzoneIcon: {
marginBottom: theme.spacing(2),
color: "#00A346",
},
dropzoneText: {
marginBottom: theme.spacing(2),
color: "#ffffff",
},
progressContainer: {
marginTop: theme.spacing(2),
},
submitButton: {
color: "#fff",
fontSize: "0.8rem",
fontWeight: "900",
textTransform: "uppercase",
letterSpacing: "0.04em",
lineHeight: "2.8rem",
display: "inline-block",
cursor: "pointer",
padding: "0 1rem",
border: "0",
borderRadius: "4px",
outline: "none",
background: "#526e89",
transition: "background-color 0.3s ease",
"&:hover": {
backgroundColor: "#1caff2",
},
},
overviewText: {
color: "#456",
marginTop: theme.spacing(4),
padding: theme.spacing(3),
},
}));
const UploadDiary = () => {
const classes = useStyles();
const [file, setFile] = useState(null);
const [uploading, setUploading] = useState(false);
const navigate = useNavigate();
useEffect(() => {
const checkCSVFile = async () => {
try {
const response = await axios.get("http://localhost:5000/api/check-csv");
if (response.data.fileExists) {
navigate("/PosterSelector");
}
} catch (error) {
console.error("Error checking CSV file:", error);
}
};
checkCSVFile();
}, [navigate]);
const { getRootProps, getInputProps } = useDropzone({
onDrop: (acceptedFiles) => {
setFile(acceptedFiles[0]);
},
maxFiles: 1,
accept: ".csv",
});
const handleUpload = async () => {
if (file) {
setUploading(true);
try {
const formData = new FormData();
formData.append("file", file);
await axios.post("http://localhost:5000/api/upload-csv", formData, {
headers: {
"Content-Type": "multipart/form-data",
},
});
navigate("/PosterSelector");
} catch (error) {
console.error("Error uploading file:", error);
} finally {
setUploading(false);
}
}
};
return (
<Container className={classes.root}>
<div className={classes.card}>
<Typography variant="h4" className={classes.title}>
Upload CSV File
</Typography>
<div {...getRootProps()} className={classes.dropzone}>
<input {...getInputProps()} />
{file ? (
<>
<CloudDoneOutlinedIcon
className={classes.dropzoneIcon}
style={{ fontSize: "4rem" }}
/>
<Typography variant="h6" className={classes.dropzoneText}>
Your file has been uploaded: {file.name}
</Typography>
</>
) : (
<>
<CloudUploadOutlined
className={classes.dropzoneIcon}
style={{ fontSize: "4rem" }}
/>
<Typography variant="h6" className={classes.dropzoneText}>
Drag and drop a CSV file here or click to select
</Typography>
</>
)}
</div>
{file && (
<Grid
container
justify="center"
className={classes.progressContainer}
>
{uploading ? (
<CircularProgress />
) : (
<Button
className={classes.submitButton}
variant="contained"
onClick={handleUpload}
>
SUBMIT
</Button>
)}
</Grid>
)}
</div>
<Typography variant="body1" className={classes.overviewText}>
This tool allows you to easily upload your diary.csv file from
Letterboxd and select your favorite movie poster. Follow these simple
steps:
<br />
<strong>1. Upload Your CSV File:</strong> Drag and drop your diary.csv
file or click to select it from your device.
<br />
<strong>2. Automatic Processing:</strong> Once uploaded, the application
will automatically process the file.
<br />
<strong>3. Poster Selection:</strong> After the file is successfully
uploaded, you'll be redirected to the Poster Selector page, where you
can browse and choose your favorite movie poster based on your
Letterboxd diary.
</Typography>
</Container>
);
};
export default UploadDiary;

View File

@@ -1,13 +0,0 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}

View File

@@ -1,10 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import React from "react";
import ReactDOM from "react-dom/client";
import "./styles/index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
const root = ReactDOM.createRoot(document.getElementById('root'));
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<App />

View File

@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>

Before

Width:  |  Height:  |  Size: 2.6 KiB

7
src/services/api.js Normal file
View File

@@ -0,0 +1,7 @@
import axios from "axios";
const API_BASE_URL = "http://localhost:5000/api";
export const fetchMovies = () => axios.get(`${API_BASE_URL}/movies`);
export const downloadPoster = (movieId) =>
axios.post(`${API_BASE_URL}/download-poster`, { movie_id: movieId });

View File

@@ -1,5 +0,0 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';

View File

@@ -14,18 +14,18 @@
}
.App-header {
background-color: #282c34;
background-color: #14181c;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
color: #ffffff;
}
.App-link {
color: #61dafb;
color: #00a346;
}
@keyframes App-logo-spin {

33
src/styles/index.css Normal file
View File

@@ -0,0 +1,33 @@
body {
margin: 0;
font-family: Avenir, -apple-system, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
html {
background-color: #14181c;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace;
}
:root {
--background: #fff;
--foreground: #2c3e50;
--primary: #1caff2;
--secondary: #000;
--tertiary: rgba(64, 188, 244, 0.5);
--white: #fff;
--off-white: #ebebeb;
--black: #000;
}
.dark {
--background: #14181d;
--foreground: #76a0ca;
--secondary: #fff;
--tertiary: #526e89;
}