Browse Source

Adds video and name statistics

pull/15/head
QuickMythril 7 months ago
parent
commit
29755c987d
  1. 42
      src/hooks/useFetchVideos.tsx
  2. 29
      src/pages/Home/Home.tsx
  3. 22
      src/state/features/globalSlice.ts

42
src/hooks/useFetchVideos.tsx

@ -12,6 +12,9 @@ import {
import { import {
setIsLoadingGlobal, setIsLoadingGlobal,
setUserAvatarHash, setUserAvatarHash,
setTotalVideosPublished,
setTotalNamesPublished,
setVideosPerNamePublished,
} from "../state/features/globalSlice"; } from "../state/features/globalSlice";
import { RootState } from "../state/store"; import { RootState } from "../state/store";
import { fetchAndEvaluateVideos } from "../utils/fetchVideos"; import { fetchAndEvaluateVideos } from "../utils/fetchVideos";
@ -32,6 +35,15 @@ export const useFetchVideos = () => {
const userAvatarHash = useSelector( const userAvatarHash = useSelector(
(state: RootState) => state.global.userAvatarHash (state: RootState) => state.global.userAvatarHash
); );
const totalVideosPublished = useSelector(
(state: RootState) => state.global.totalVideosPublished
);
const totalNamesPublished = useSelector(
(state: RootState) => state.global.totalNamesPublished
);
const videosPerNamePublished = useSelector(
(state: RootState) => state.global.videosPerNamePublished
);
const filteredVideos = useSelector( const filteredVideos = useSelector(
(state: RootState) => state.video.filteredVideos (state: RootState) => state.video.filteredVideos
); );
@ -386,6 +398,35 @@ export const useFetchVideos = () => {
} catch (error) {} } catch (error) {}
}, [videos]); }, [videos]);
const getVideosCount = React.useCallback(
async () => {
try {
let url = `/arbitrary/resources/search?mode=ALL&includemetadata=false&limit=0&service=DOCUMENT&identifier=${QTUBE_VIDEO_BASE}`;
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
const responseData = await response.json();
const totalVideosPublished = responseData.length;
const uniqueNames = new Set(responseData.map(video => video.name));
const totalNamesPublished = uniqueNames.size;
const videosPerNamePublished = (totalVideosPublished / totalNamesPublished).toFixed(2);
dispatch(setTotalVideosPublished(totalVideosPublished));
dispatch(setTotalNamesPublished(totalNamesPublished));
dispatch(setVideosPerNamePublished(videosPerNamePublished));
} catch (error) {
console.log({ error });
} finally {
}
},
[]
);
return { return {
getVideos, getVideos,
checkAndUpdateVideo, checkAndUpdateVideo,
@ -394,5 +435,6 @@ export const useFetchVideos = () => {
getNewVideos, getNewVideos,
checkNewVideos, checkNewVideos,
getVideosFiltered, getVideosFiltered,
getVideosCount,
}; };
}; };

29
src/pages/Home/Home.tsx

@ -64,6 +64,15 @@ export const Home = ({ mode }: HomeProps) => {
const selectedCategoryVideos = useSelector( const selectedCategoryVideos = useSelector(
(state: RootState) => state.video.selectedCategoryVideos (state: RootState) => state.video.selectedCategoryVideos
); );
const totalVideosPublished = useSelector(
(state: RootState) => state.global.totalVideosPublished
);
const totalNamesPublished = useSelector(
(state: RootState) => state.global.totalNamesPublished
);
const videosPerNamePublished = useSelector(
(state: RootState) => state.global.videosPerNamePublished
);
const { videos: globalVideos } = useSelector( const { videos: globalVideos } = useSelector(
(state: RootState) => state.video (state: RootState) => state.video
@ -111,7 +120,7 @@ export const Home = ({ mode }: HomeProps) => {
const afterFetch = useRef(false); const afterFetch = useRef(false);
const isFetching = useRef(false); const isFetching = useRef(false);
const { getVideos, getNewVideos, checkNewVideos, getVideosFiltered } = const { getVideos, getNewVideos, checkNewVideos, getVideosFiltered, getVideosCount } =
useFetchVideos(); useFetchVideos();
const getVideosHandler = React.useCallback( const getVideosHandler = React.useCallback(
@ -149,11 +158,12 @@ export const Home = ({ mode }: HomeProps) => {
); );
useEffect(() => { useEffect(() => {
getVideosCount();
if (isFiltering && filterValue !== prevVal?.current) { if (isFiltering && filterValue !== prevVal?.current) {
prevVal.current = filterValue; prevVal.current = filterValue;
getVideosHandler(); getVideosHandler();
} }
}, [filterValue, isFiltering, filteredVideos]); }, [filterValue, isFiltering, filteredVideos, getVideosCount]);
const getVideosHandlerMount = React.useCallback(async () => { const getVideosHandlerMount = React.useCallback(async () => {
if (firstFetch.current) return; if (firstFetch.current) return;
@ -262,6 +272,20 @@ export const Home = ({ mode }: HomeProps) => {
}; };
return ( return (
<>
<Box sx={{ width: "100%" }}>
<Grid container spacing={2} justifyContent="space-around">
<Grid item xs={12} sm={4}>
Total Videos Published: {totalVideosPublished}
</Grid>
<Grid item xs={12} sm={4}>
Total Names Publishing: {totalNamesPublished}
</Grid>
<Grid item xs={12} sm={4}>
Average Videos per Name: {videosPerNamePublished}
</Grid>
</Grid>
</Box>
<Grid container sx={{ width: "100%" }}> <Grid container sx={{ width: "100%" }}>
<FiltersCol item xs={12} md={2} lg={2} xl={2} sm={3}> <FiltersCol item xs={12} md={2} lg={2} xl={2} sm={3}>
<FiltersContainer> <FiltersContainer>
@ -536,5 +560,6 @@ export const Home = ({ mode }: HomeProps) => {
<ListSuperLikeContainer /> <ListSuperLikeContainer />
</FiltersCol> </FiltersCol>
</Grid> </Grid>
</>
); );
}; };

22
src/state/features/globalSlice.ts

@ -8,6 +8,9 @@ interface GlobalState {
publishNames: string[] | null publishNames: string[] | null
videoPlaying: any | null videoPlaying: any | null
superlikelistAll: any[] superlikelistAll: any[]
totalVideosPublished: number
totalNamesPublished: number
videosPerNamePublished: number
} }
const initialState: GlobalState = { const initialState: GlobalState = {
isLoadingGlobal: false, isLoadingGlobal: false,
@ -15,7 +18,10 @@ const initialState: GlobalState = {
userAvatarHash: {}, userAvatarHash: {},
publishNames: null, publishNames: null,
videoPlaying: null, videoPlaying: null,
superlikelistAll: [] superlikelistAll: [],
totalVideosPublished: null,
totalNamesPublished: null,
videosPerNamePublished: null
} }
export const globalSlice = createSlice({ export const globalSlice = createSlice({
@ -52,6 +58,15 @@ export const globalSlice = createSlice({
setSuperlikesAll: (state, action) => { setSuperlikesAll: (state, action) => {
state.superlikelistAll = action.payload state.superlikelistAll = action.payload
}, },
setTotalVideosPublished: (state, action) => {
state.totalVideosPublished = action.payload
},
setTotalNamesPublished: (state, action) => {
state.totalNamesPublished = action.payload
},
setVideosPerNamePublished: (state, action) => {
state.videosPerNamePublished = action.payload
},
} }
}) })
@ -62,7 +77,10 @@ export const {
setUserAvatarHash, setUserAvatarHash,
addPublishNames, addPublishNames,
setVideoPlaying, setVideoPlaying,
setSuperlikesAll setSuperlikesAll,
setTotalVideosPublished,
setTotalNamesPublished,
setVideosPerNamePublished
} = globalSlice.actions } = globalSlice.actions
export default globalSlice.reducer export default globalSlice.reducer

Loading…
Cancel
Save