Compare commits

..

No commits in common. "d1a9622d96c79527858bd916aff1cba48e45d61e" and "b699dcdd5179574e85587e8321fd62a35c85f453" have entirely different histories.

8 changed files with 14274 additions and 2225 deletions

2
.gitignore vendored
View File

@ -50,5 +50,5 @@ yarn-error.log*
movie movie
server/server server/server
server/main server/main
__debug_bin* __debug_bin
gpt*.txt gpt*.txt

16254
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,8 @@
"react-swipe-handler": "^1.1.2", "react-swipe-handler": "^1.1.2",
"react-swipeable": "^7.0.1", "react-swipeable": "^7.0.1",
"swipeable": "^1.0.5", "swipeable": "^1.0.5",
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4",
"yarn": "^1.22.19"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",

View File

@ -4,7 +4,7 @@ import { createContext } from 'react';
const ConfigContext = createContext(); const ConfigContext = createContext();
export const config = { export const config = {
Host: 'http://192.168.124.2:4444', Host: 'http://192.168.31.121:4444',
}; };
export default ConfigContext; export default ConfigContext;

View File

@ -1,4 +1,4 @@
import React, { useState, useEffect, useContext, useCallback } from 'react'; import React, { useState, useEffect, useContext, useCallback, useReducer } from 'react';
import axios from 'axios'; import axios from 'axios';
import Container from '@mui/material/Container'; import Container from '@mui/material/Container';
import Grid from '@mui/material/Grid'; import Grid from '@mui/material/Grid';
@ -10,49 +10,63 @@ import ConfigContext from './Config';
import MovieCard from './components/MovieCard'; import MovieCard from './components/MovieCard';
import CategoryNav from './components/CategoryNav'; import CategoryNav from './components/CategoryNav';
const Main = () => { const initialState = {
const config = useContext(ConfigContext); lastCategory: 0,
const [loading, setLoading] = useState(false); history: {
const categories = [ 0: { lastPage: 1, scrollPos: 0 },
{ label: '15min', idx: 0 }, 1: { lastPage: 1, scrollPos: 0 },
{ label: '30min', idx: 1 }, 2: { lastPage: 1, scrollPos: 0 },
{ label: '60min', idx: 2 }, 3: { lastPage: 1, scrollPos: 0 },
{ label: '大于60min', idx: 3 }, },
]; pagination: {
const limit = 20;
const getInitialParams = () => {
const storedParams = localStorage.getItem('params');
if (storedParams) {
return JSON.parse(storedParams);
} else {
return {
lastCategory: 0,
history: {
0: { lastPage: 1, scrollPos: 0 },
1: { lastPage: 1, scrollPos: 0 },
2: { lastPage: 1, scrollPos: 0 },
3: { lastPage: 1, scrollPos: 0 },
},
};
}
};
const [params, setParams] = useState(getInitialParams());
const [pagination, setPagination] = useState({
movies: [], movies: [],
page: params.history[params.lastCategory].lastPage, page: 1,
total: 1, total: 1,
length: 1, length: 1,
}); },
loading: false,
};
function reducer(state, action) {
switch (action.type) {
case 'UPDATE_LAST_CATEGORY':
return { ...state, lastCategory: action.payload.lastCategory };
case 'UPDATE_HISTORY':
return {
...state,
history: {
...state.history,
[action.payload.category]: action.payload.newData,
},
};
case 'SET_PAGINATION':
return { ...state, pagination: action.payload.pagination };
case 'SET_LOADING':
return { ...state, loading: action.payload.loading };
default:
return state;
}
}
const Main = () => {
const config = useContext(ConfigContext);
const [state, dispatch] = useReducer(reducer, initialState);
const updateLastCategory = useCallback((newCategory) => {
dispatch({ type: 'UPDATE_LAST_CATEGORY', payload: { lastCategory: newCategory } });
}, []);
const updateHistory = useCallback((category, newData) => {
dispatch({ type: 'UPDATE_HISTORY', payload: { category, newData } });
}, []);
const fetchMovies = useCallback(async (category, page) => { const fetchMovies = useCallback(async (category, page) => {
setLoading(true); dispatch({ type: 'SET_LOADING', payload: { loading: true } });
try { try {
const response = await axios.get( const response = await axios.get(
`${config.Host}/movie/?page=${page}&limit=${limit}&category=${category}` `${config.Host}/movie/?page=${page}&limit=${config.limit}&category=${category}` //
); );
if (response.status === 200) { if (response.status === 200) {
@ -61,104 +75,85 @@ const Main = () => {
if (data.items.length === 0 && page > 1) { if (data.items.length === 0 && page > 1) {
fetchMovies(category, page - 1); fetchMovies(category, page - 1);
} else { } else {
setPagination({ dispatch({
movies: data.items, type: 'SET_PAGINATION',
page: page, payload: {
total: data.total, pagination: {
length: Math.ceil(data.total / limit), movies: data.items,
page: page,
total: data.total,
length: Math.ceil(data.total / config.limit), //
},
},
}); });
} }
} }
} catch (error) { } catch (error) {
console.error('Error fetching movies:', error); console.error('Error fetching movies:', error);
} finally { } finally {
setLoading(false); dispatch({ type: 'SET_LOADING', payload: { loading: false } });
} }
}, [config.Host, limit]); }, [config.Host, config.limit]); //
useEffect(() => { useEffect(() => {
const currentCategory = params.lastCategory; const currentCategory = state.lastCategory;
const currentPage = params.history[currentCategory].lastPage; const currentPage = state.history[currentCategory].lastPage;
fetchMovies(currentCategory, currentPage); fetchMovies(currentCategory, currentPage);
}, [fetchMovies, params]); }, [fetchMovies, state]);
const updateParams = useCallback((newParams) => {
setParams((prevParams) => {
const updatedParams = { ...prevParams, ...newParams };
localStorage.setItem('params', JSON.stringify(updatedParams));
return updatedParams;
});
}, []);
const handlePageChange = useCallback( const handlePageChange = useCallback(
(event, page) => { (event, page) => {
const currentCategory = params.lastCategory; const currentCategory = state.lastCategory;
updateParams({ updateHistory(currentCategory, { ...state.history[currentCategory], lastPage: page });
history: {
...params.history,
[currentCategory]: { ...params.history[currentCategory], lastPage: page },
},
});
fetchMovies(currentCategory, page); fetchMovies(currentCategory, page);
}, },
[fetchMovies, params, updateParams] [fetchMovies, state, updateHistory]
); );
//
const handleCategoryChange = useCallback( const handleCategoryChange = useCallback(
(category) => { (category) => {
const currentPage = params.history[category].lastPage; const currentPage = state.history[category].lastPage;
fetchMovies(category, currentPage); fetchMovies(category, currentPage);
const currentCategory = params.lastCategory; const currentCategory = state.lastCategory;
updateParams({ updateHistory(currentCategory, { ...state.history[currentCategory], scrollPos: window.scrollY });
lastCategory: category, updateLastCategory(category);
history: {
...params.history,
[currentCategory]: { ...params.history[currentCategory], scrollPos: window.scrollY },
},
});
}, },
[fetchMovies, params, updateParams] [fetchMovies, state, updateHistory, updateLastCategory]
); );
const handleRenderComplete = useCallback(() => { const handleRenderComplete = useCallback(() => {
const { scrollPos } = params.history[params.lastCategory]; const { scrollPos } = state.history[state.lastCategory];
window.scrollTo(0, scrollPos); window.scrollTo(0, scrollPos);
}, [params]); }, [state]);
const handleMovieCardClick = () => { const handleMovieCardClick = () => {
const currentCategory = params.lastCategory; const currentCategory = state.lastCategory;
updateParams({ updateHistory(currentCategory, { ...state.history[currentCategory], scrollPos: window.scrollY });
history: {
...params.history,
[currentCategory]: { ...params.history[currentCategory], scrollPos: window.scrollY },
},
});
}; };
return ( return (
<Container style={{ marginTop: 20 }}> <Container style={{ marginTop: 20 }}>
<CategoryNav <CategoryNav
categories={categories} categories={config.categories} //
currentCategory={params.lastCategory} currentCategory={state.lastCategory} //
onCategoryChange={handleCategoryChange} onCategoryChange={handleCategoryChange}
/> />
<PaginationWrapper page={pagination.page} length={pagination.length} onPageChange={handlePageChange} /> <PaginationWrapper page={state.pagination.page} length={state.pagination.length} onPageChange={handlePageChange} />
{loading ? ( {state.loading ? (
<Loading /> <Loading />
) : ( ) : (
<MoviesGrid <MoviesGrid
movies={pagination.movies} movies={state.pagination.movies}
config={config} config={config}
onRenderComplete={handleRenderComplete} onRenderComplete={handleRenderComplete}
onMovieCardClick={handleMovieCardClick} onMovieCardClick={handleMovieCardClick}
/> />
)} )}
<PaginationWrapper page={pagination.page} length={pagination.length} onPageChange={handlePageChange} /> <PaginationWrapper page={state.pagination.page} length={state.pagination.length} onPageChange={handlePageChange} />
</Container> </Container>
); );
}; };
@ -168,7 +163,6 @@ const PaginationWrapper = ({ page, length, onPageChange }) => (
<Pagination count={length} page={page} onChange={onPageChange} /> <Pagination count={length} page={page} onChange={onPageChange} />
</Grid> </Grid>
); );
const MoviesGrid = ({ movies, config, onRenderComplete, onMovieCardClick }) => { const MoviesGrid = ({ movies, config, onRenderComplete, onMovieCardClick }) => {
useEffect(() => { useEffect(() => {
@ -185,7 +179,7 @@ const MoviesGrid = ({ movies, config, onRenderComplete, onMovieCardClick }) => {
<Link <Link
to={`/res/${item.filename}`} to={`/res/${item.filename}`}
style={{ textDecoration: 'none', paddingBottom: 10 }} style={{ textDecoration: 'none', paddingBottom: 10 }}
onClick={onMovieCardClick} // onClick={onMovieCardClick}
> >
<MovieCard movie={item} config={config} /> <MovieCard movie={item} config={config} />
</Link> </Link>

View File

@ -9,15 +9,11 @@ const CategoryNav = ({ categories, currentCategory, onCategoryChange }) => {
}; };
return ( return (
<Tabs <Tabs
value={currentCategory} value={currentCategory}
onChange={handleChange} onChange={handleChange}
indicatorColor="primary" indicatorColor="primary"
textColor="primary" textColor="primary"
ScrollButtonComponent="div"
variant="scrollable"
scrollButtons="auto"
centered centered
> >
{categories.map((category, idx) => ( {categories.map((category, idx) => (

View File

@ -1,10 +1,8 @@
import {React, useContext, useState} from 'react'; import {React, useContext} from 'react';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import Container from '@mui/material/Container'; import Container from '@mui/material/Container';
import Typography from '@mui/material/Typography'; import Typography from '@mui/material/Typography';
import ConfigContext from '../Config'; import ConfigContext from '../Config';
import ReactPlayer from 'react-player';
@ -12,32 +10,21 @@ const VideoPlayer = () => {
const config = useContext(ConfigContext); const config = useContext(ConfigContext);
const { filename } = useParams(); const { filename } = useParams();
const [isFullScreen, setIsFullScreen] = useState(false);
const handleFullScreenChange = (player) => {
setIsFullScreen(!isFullScreen);
if (isFullScreen) {
player.exitFullscreen();
} else {
player.requestFullscreen();
}
};
return ( return (
<Container> <Container>
<Typography variant="h6" gutterBottom> <Typography variant="h6" gutterBottom>
{filename} {filename}
</Typography> </Typography>
<ReactPlayer <video
url={`${config.Host}/res/${filename}`} autoPlay={true}
controls controls
width="100%" style={{ width: '100%', maxHeight: '70vh' }}
height="auto" src={`${config.Host}/res/${filename}`}
playing={isFullScreen} >
onReady={handleFullScreenChange} 您的浏览器不支持HTML5视频播放
/> </video>
</Container> </Container>
); );
}; };
export default VideoPlayer; export default VideoPlayer;

View File

@ -11,28 +11,3 @@ code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace; monospace;
} }
/* 对于较小的屏幕 */
@media only screen and (max-width: 600px) {
.MoviesGrid {
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
}
/* 中等大小屏幕 */
@media only screen and (min-width: 601px) and (max-width: 960px) {
.MoviesGrid {
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
}
/* 大屏幕 */
@media only screen and (min-width: 961px) {
.MoviesGrid {
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}
}