Browse Source

refactor, fixed bugs

Alyona Brytvina 2 năm trước cách đây
mục cha
commit
bc30a0fd3d

+ 5 - 67
README.md

@@ -1,70 +1,8 @@
-# Getting Started with Create React App
+# Getting Started with Bonita Player project
 
-This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
+1) Use `npm i` or `npm install` within the root catalog to install necessary modules
+2) Use `npm start` and you can work with the website in your browser
 
-## Available Scripts
+# Demo
+http://bonita.surge.sh/
 
-In the project directory, you can run:
-
-### `npm start`
-
-Runs the app in the development mode.\
-Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
-
-The page will reload when you make changes.\
-You may also see any lint errors in the console.
-
-### `npm test`
-
-Launches the test runner in the interactive watch mode.\
-See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
-
-### `npm run build`
-
-Builds the app for production to the `build` folder.\
-It correctly bundles React in production mode and optimizes the build for the best performance.
-
-The build is minified and the filenames include the hashes.\
-Your app is ready to be deployed!
-
-See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
-
-### `npm run eject`
-
-**Note: this is a one-way operation. Once you `eject`, you can't go back!**
-
-If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
-
-Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
-
-You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
-
-## Learn More
-
-You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
-
-To learn React, check out the [React documentation](https://reactjs.org/).
-
-### Code Splitting
-
-This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
-
-### Analyzing the Bundle Size
-
-This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
-
-### Making a Progressive Web App
-
-This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
-
-### Advanced Configuration
-
-This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
-
-### Deployment
-
-This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
-
-### `npm run build` fails to minify
-
-This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

+ 5 - 5
src/api/playlists.js

@@ -1,5 +1,5 @@
 import { getGql } from '../utils/getGql';
-import { BACKEND_URL } from '../constants';
+import { BACKEND_URL, LIMIT } from '../constants';
 
 export const getPlaylists = () => getGql(`query nonEmptyPlaylists($query: String){
   PlaylistFind(query: $query) {
@@ -38,8 +38,8 @@ export const getPlaylistsWithPage = (page = 1) => getGql(`
     tracks: {$exists: true, $ne: []},
   },
   {
-    limit: [20],
-    skip: [(page - 1) * 20],
+    limit: [LIMIT.PLAYLISTS_ON_PAGE],
+    skip: [(page - 1) * LIMIT.PLAYLISTS_ON_PAGE],
   }])
   ,
 });
@@ -99,8 +99,8 @@ export const getUserPlaylist = ({userId, page = 1}) => getGql(`
       tracks: {$exists: true, $ne: []},
     },
     {
-      limit: [20],
-      skip: [(page - 1) * 20],
+      limit: [LIMIT.PLAYLISTS_ON_PAGE],
+      skip: [(page - 1) * LIMIT.PLAYLISTS_ON_PAGE],
     },
   ]),
 });

+ 16 - 7
src/api/tracks.js

@@ -1,11 +1,15 @@
 import { getGql } from '../utils/getGql';
-import { BACKEND_URL } from '../constants';
+import { BACKEND_URL, LIMIT } from '../constants';
 
 export const getTracksCount = () => getGql(`
-      query getCount {
-          TrackCount(query:"[{}]")
+      query getCount($query: String) {
+          TrackCount(query:$query)
       } 
-  `);
+  `, {
+  query: JSON.stringify([{
+    originalFileName: {$exists: true, $ne: ''},
+  }]),
+});
 
 export const getTracksWithPage = (page = 1) => getGql(`
       query skipTracks($query: String) {
@@ -16,7 +20,7 @@ export const getTracksWithPage = (page = 1) => getGql(`
   `, {
   query: JSON.stringify([
     {originalFileName: {$exists: true, $ne: ''}},
-    {skip: [(page - 1) * 100]}]),
+    {skip: [(page - 1) * LIMIT.TRACKS_ON_PAGE]}]),
 })
   .then(data => data.map(track => ({
     ...track,
@@ -32,7 +36,7 @@ export const getUserTracks = ({userId, page = 1}) => getGql(`
   `, {
   query: JSON.stringify([
     {___owner: userId},
-    {skip: [(page - 1) * 100]}]),
+    {skip: [(page - 1) * LIMIT.TRACKS_ON_PAGE]}]),
 })
   .then(data => data.map(track => ({
     ...track,
@@ -43,4 +47,9 @@ export const getUserTracksCount = (userId) => getGql(`
       query getCount($query: String){
            TrackCount(query: $query)
       } 
-  `, {query: JSON.stringify([{___owner: userId}])});
+  `, {
+  query: JSON.stringify([{
+    ___owner: userId,
+    originalFileName: {$exists: true, $ne: ''},
+  }]),
+});

+ 2 - 5
src/components/Filter/Filter.jsx

@@ -3,13 +3,10 @@ import {
 } from '@mui/material';
 import FileUploadIcon from '@mui/icons-material/FileUpload';
 import React from 'react';
-import { Link } from 'react-router-dom';
-import { ROUTES } from '../../constants';
-import { forwardToPage } from '../../utils/history';
 
 export const Filter = ({
-  onClickUpload, linkToUser, linkToAll,
-  selectedFilter, categoryName, count, onSelect,
+  onClickUpload, selectedFilter,
+  categoryName, count, onSelect,
 }) => (
   <Box
     sx={{

+ 29 - 19
src/components/Header/Header.jsx

@@ -41,25 +41,35 @@ export const Header = () => {
             </Button>
           </Link>
         </Box>
-        <Link
-          to={user !== null ? ROUTES.PROFILE_PAGE : ROUTES.LOGIN_PAGE}
-        >
-          <IconButton
-            size="large"
-            color="inherit"
-          >
-            {user !== null && user !== undefined
-              ? (
-                <Avatar
-                  className="avatar"
-                  sx={{width: 30, height: 30}}
-                  src={buildUrl(user?.avatar?.url ?? '')}
-                />
-              ) : (
-                <LoginIcon/>
-              )}
-          </IconButton>
-        </Link>
+        {localStorage.getItem('authToken')
+          ? (
+            <Link
+              to={user !== null ? ROUTES.PROFILE_PAGE : ROUTES.LOGIN_PAGE}
+            >
+              <IconButton
+                size="large"
+                color="inherit"
+              >
+                {user !== null && user !== undefined
+                  ? (
+                    <Avatar
+                      className="avatar"
+                      sx={{width: 30, height: 30}}
+                      src={buildUrl(user?.avatar?.url ?? '')}
+                    />
+                  ) : (
+                    <LoginIcon/>
+                  )}
+              </IconButton>
+            </Link>
+          ) : (
+            <IconButton
+              size="large"
+              color="inherit"
+            >
+              <LoginIcon/>
+            </IconButton>
+          )}
       </Toolbar>
     </AppBar>
   );

+ 114 - 48
src/components/Player/Player.jsx

@@ -1,4 +1,4 @@
-import React, { useEffect } from 'react';
+import React, { useEffect, useState } from 'react';
 import {
   Box, CircularProgress, IconButton, Typography,
 } from '@mui/material';
@@ -9,6 +9,10 @@ import {
   PauseRounded,
   PlayArrowRounded,
 } from '@mui/icons-material';
+import CloseIcon from '@mui/icons-material/Close';
+import ArrowDropUpIcon from '@mui/icons-material/ArrowDropUp';
+import ExpandLessIcon from '@mui/icons-material/ExpandLess';
+import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
 import { PlayerBar } from '../PlayerBar/PlayerBar';
 import { regex } from '../../utils/regex';
 import {
@@ -22,6 +26,7 @@ import { VolumeControl } from '../VolumeControl/VolumeControl';
 export const Player = () => {
   const dispatch = useDispatch();
   const playerState = useSelector(state => state.player);
+  const [minimizePlayer, setMinimizePlayer] = useState(false);
 
   const togglePlayPause = () => {
     const {trackList, currentPlayingTrackId} = playerState;
@@ -52,52 +57,113 @@ export const Player = () => {
   const trackIndex = playerState.trackList.findIndex(track => track._id === playerState.currentPlayingTrackId);
 
   return (
-    <Box sx={{
-      width: '100%',
-      height: '30vh',
-      position: 'sticky',
-      bottom: '0',
-      backgroundColor: 'white',
-      display: playerState.audio === null ? 'none' : 'flex',
-      alignItems: 'center',
-      flexDirection: 'column',
-    }}
-    >
-      <PlayerBar/>
-      <Typography variant="caption">
-        {regex(playerState.trackList?.[trackIndex]?.originalFileName ?? '')}
-      </Typography>
-      <Box
-        sx={{
-          marginTop: '10px',
-        }}
-      >
-        <IconButton
-          color="primary"
-          onClick={onBackward}
-        >
-          <FastRewindRounded fontSize="large"/>
-        </IconButton>
-        <IconButton
-          onClick={togglePlayPause}
-          color="primary"
-        >
-          {playerState.duration === 0
-            ? <CircularProgress/>
-            : playerState.isPlaying
-              ? <PauseRounded fontSize="large"/>
-              : <PlayArrowRounded fontSize="large"/>}
-        </IconButton>
-        <IconButton
-          color="primary"
-          onClick={onForward}
-        >
-          <FastForwardRounded
-            fontSize="large"
-          />
-        </IconButton>
-      </Box>
-      <VolumeControl />
-    </Box>
+    <>
+      {!minimizePlayer
+        ? (
+          <Box
+            sx={{
+              width: '100%',
+              height: '30vh',
+              position: 'sticky',
+              bottom: '0',
+              backgroundColor: 'white',
+              display: playerState.audio === null ? 'none' : 'flex',
+              alignItems: 'center',
+              flexDirection: 'column',
+            }}
+          >
+            <PlayerBar/>
+            <Box sx={{
+              display: 'flex',
+              alignItems: 'center',
+              flexDirection: ' row',
+              justifyContent: 'end',
+              width: '100%',
+              height: '0',
+            }}
+            >
+              <IconButton onClick={() => setMinimizePlayer(!minimizePlayer)}>
+                <ExpandMoreIcon color="primary" fontSize="large"/>
+              </IconButton>
+            </Box>
+            <Typography variant="subtitle2">
+              {regex(playerState.trackList?.[trackIndex]?.originalFileName ?? '')}
+            </Typography>
+            <Box
+              sx={{
+                marginTop: '10px',
+              }}
+            >
+              <IconButton
+                color="primary"
+                onClick={onBackward}
+              >
+                <FastRewindRounded fontSize="large"/>
+              </IconButton>
+              <IconButton
+                onClick={togglePlayPause}
+                color="primary"
+              >
+                {playerState.duration === 0
+                  ? <CircularProgress/>
+                  : playerState.isPlaying
+                    ? <PauseRounded fontSize="large"/>
+                    : <PlayArrowRounded fontSize="large"/>}
+              </IconButton>
+              <IconButton
+                color="primary"
+                onClick={onForward}
+              >
+                <FastForwardRounded
+                  fontSize="large"
+                />
+              </IconButton>
+            </Box>
+            <VolumeControl/>
+          </Box>
+        )
+        : (
+          <Box sx={{
+            width: '100%',
+            height: '50px',
+            position: 'sticky',
+            bottom: '0',
+            backgroundColor: 'white',
+            display: 'flex',
+            justifyContent: 'center',
+            alignItems: 'center',
+            borderTop: '1px solid #9c27b0',
+          }}
+          >
+            <Box sx={{
+              display: 'flex',
+              alignItems: 'center',
+              justifyContent: 'center',
+              width: '100%',
+            }}
+            >
+              <Typography variant="subtitle2">
+                {regex(playerState.trackList?.[trackIndex]?.originalFileName ?? '')}
+              </Typography>
+            </Box>
+            <Box sx={{
+              width: '0',
+            }}
+            >
+              <Box sx={{
+                display: 'flex',
+                alignItems: 'center',
+                justifyContent: 'end',
+                // width: '10%',
+              }}
+              >
+                <IconButton onClick={() => setMinimizePlayer(!minimizePlayer)}>
+                  <ExpandLessIcon color="primary" fontSize="large"/>
+                </IconButton>
+              </Box>
+            </Box>
+          </Box>
+        )}
+    </>
   );
 };

+ 13 - 9
src/components/PlayerBar/PlayerBar.jsx

@@ -1,8 +1,9 @@
 import React, { useEffect, useState } from 'react';
 import {
-  Box, Slider, styled, Typography,
+  Box, IconButton, Slider, styled, Typography,
 } from '@mui/material';
 import { useDispatch, useSelector } from 'react-redux';
+import CloseIcon from '@mui/icons-material/Close';
 import { actionChangeTime } from '../../store/types/playerTypes';
 
 export const PlayerBar = () => {
@@ -65,16 +66,19 @@ export const PlayerBar = () => {
               : Math.floor(playerState.audio?.duration)
         }
       />
-      <Box
-        sx={{
-          display: 'flex',
-          alignItems: 'center',
-          justifyContent: 'space-between',
-        }}
+      <Box sx={{
+        display: 'flex',
+        alignItems: 'center',
+        justifyContent: 'center',
+        flexDirection: ' row',
+        width: '100%',
+      }}
       >
-        <TinyText>{formatDuration(playerState.audio?.currentTime)}</TinyText>
         <TinyText>
-          -
+          {formatDuration(playerState.audio?.currentTime)}
+        </TinyText>
+          &nbsp;/&nbsp;
+        <TinyText>
           {formatDuration(playerState.audio?.duration)}
         </TinyText>
       </Box>

+ 48 - 3
src/components/Skeleton/SkeletonProduct.jsx

@@ -1,13 +1,16 @@
 import React from 'react';
 import {
-  Box, Grid, Paper, Skeleton,
+  Box, Grid, Skeleton,
 } from '@mui/material';
 
 export const SkeletonProduct = () => (
-  <Box sx={{width: '600px', height: '100%', ml: '20px'}}>
+  <Box sx={{width: '90%', height: '100%', ml: '20px'}}>
     {
       Array(7).fill(undefined).map((item, index) => (
-        <Skeleton key={index} width="100%" height={70} animation="wave"/>
+        <Box sx={{display: 'flex'}} key={index}>
+          <Skeleton sx={{mr: '10px'}} width="5%" height={70} animation="wave"/>
+          <Skeleton width="80%" height={70} animation="wave"/>
+        </Box>
       ))
     }
   </Box>
@@ -22,6 +25,11 @@ export const SkeletonProductPlaylists = () => (
       Array(12).fill(undefined).map((item, index) => (
         <Grid
           key={index}
+          sx={{
+            display: 'flex',
+            alignItems: 'center',
+            justifyContent: 'center',
+          }}
           item
         >
           <Skeleton
@@ -30,10 +38,47 @@ export const SkeletonProductPlaylists = () => (
             width={155}
             height={190}
             sx={{
+              position: 'relative',
+              zIndex: '1',
               margin: '24px 0 0 20px',
               borderRadius: '5%',
             }}
           />
+          <Skeleton
+            animation="wave"
+            variant="circular"
+            width={125}
+            height={125}
+            sx={{
+              position: 'absolute',
+              bgcolor: 'grey.300',
+              borderRadius: '50%',
+              margin: '24px 0 0 20px',
+            }}
+          />
+          <Skeleton
+            animation="wave"
+            variant="circular"
+            width={40}
+            height={40}
+            sx={{
+              position: 'absolute',
+              bgcolor: 'white.100',
+              borderRadius: '50%',
+              margin: '24px 0 0 20px',
+            }}
+          />
+          <Skeleton
+            variant="circular"
+            width={8}
+            height={8}
+            sx={{
+              position: 'absolute',
+              bgcolor: 'white.900',
+              borderRadius: '50%',
+              margin: '24px 0 0 20px',
+            }}
+          />
         </Grid>
       ))
     }

+ 3 - 3
src/components/SnackBar/SnackBar.jsx

@@ -6,7 +6,7 @@ import { actionResetSnackBar } from '../../store/types/snackBarTypes';
 export const SnackBar = () => {
   const dispatch = useDispatch();
   const state = useSelector(state => state?.snackBar);
-  const {message, isOpen} = state;
+  const {message, isOpen, type} = state;
 
   const handleClose = (event, reason) => {
     if (reason === 'clickaway') {
@@ -18,12 +18,12 @@ export const SnackBar = () => {
   return (
     <Snackbar
       open={isOpen}
-      autoHideDuration={3000}
+      autoHideDuration={type === 'error' ? 10000 : 3000}
       onClose={handleClose}
       anchorOrigin={{vertical: 'bottom', horizontal: 'right'}}
     >
       <Alert
-        severity="success"
+        severity={type?.length === 0 ? 'success' : type}
         onClose={handleClose}
       >
         {message}

+ 1 - 1
src/components/TrackList/TrackList.jsx

@@ -28,7 +28,7 @@ export const TrackList = ({tracks, isLoading}) => {
 
   return (
     <Box sx={{
-      minHeight: '70vh',
+      minHeight: '90vh',
     }}
     >
       {isLoading ? (

+ 5 - 2
src/constants/index.js

@@ -1,5 +1,3 @@
-import React from 'react';
-
 export const BACKEND_URL = 'http://player.asmer.fs.a-level.com.ua';
 
 export const ALERT_TYPES = {
@@ -23,3 +21,8 @@ export const ROUTES = {
 };
 
 export const DEFAULT_VOLUME = 1;
+
+export const LIMIT = {
+  TRACKS_ON_PAGE: 100,
+  PLAYLISTS_ON_PAGE: 20,
+};

src/hooks/usePagination.jsx → src/hooks/usePagination.js


+ 22 - 17
src/pages/MainPage/MainPage.jsx

@@ -44,23 +44,28 @@ export const MainPage = () => {
         tracks={tracksState.trackList}
         isLoading={tracksState.isLoading}
       />
-      <Stack
-        spacing={2}
-        position="static"
-        bottom="0"
-        sx={{
-          display: 'flex',
-          alignItems: 'center',
-          mb: '3%',
-        }}
-      >
-        <Pagination
-          page={page}
-          count={Math.ceil(tracksState.totalCount / 100)}
-          onChange={handleChange}
-          color="primary"
-        />
-      </Stack>
+      {tracksState.totalCount !== 0
+        ? (
+          <Stack
+            spacing={2}
+            position="static"
+            bottom="0"
+            sx={{
+              display: 'flex',
+              alignItems: 'center',
+              mb: '3%',
+            }}
+          >
+            <Pagination
+              page={page}
+              count={Math.ceil(tracksState.totalCount / 100)}
+              onChange={handleChange}
+              color="primary"
+            />
+          </Stack>
+        ) : (
+          <></>
+        )}
     </Box>
   );
 };

+ 23 - 19
src/pages/PlaylistsPage/PlaylistsPage.jsx

@@ -48,8 +48,7 @@ export const PlaylistsPage = () => {
         <SkeletonProductPlaylists />
       ) : (
         <Grid
-          spacing={3}
-          columns={10}
+          spacing={4}
           style={{
             margin: '0',
             width: '100%',
@@ -110,23 +109,28 @@ export const PlaylistsPage = () => {
           ))}
         </Grid>
       )}
-      <Stack
-        spacing={2}
-        position="static"
-        bottom="0"
-        sx={{
-          display: 'flex',
-          alignItems: 'center',
-          m: '3%',
-        }}
-      >
-        <Pagination
-          page={page}
-          count={Math.ceil(totalCount / 20)}
-          onChange={handleChange}
-          color="primary"
-        />
-      </Stack>
+      {totalCount !== 0
+        ? (
+          <Stack
+            spacing={2}
+            position="static"
+            bottom="0"
+            sx={{
+              display: 'flex',
+              alignItems: 'center',
+              m: '3%',
+            }}
+          >
+            <Pagination
+              page={page}
+              count={Math.ceil(totalCount / 20)}
+              onChange={handleChange}
+              color="primary"
+            />
+          </Stack>
+        ) : (
+          <></>
+        )}
     </Box>
   );
 };

+ 7 - 5
src/pages/ProfilePage/ProfilePage.jsx

@@ -46,7 +46,7 @@ export const ProfilePage = () => {
 
   const logOut = () => {
     localStorage.removeItem('authToken');
-    dispatch(actionLogOut());
+    dispatch(actionLogOut(null));
     history.push('/login');
   };
 
@@ -56,12 +56,14 @@ export const ProfilePage = () => {
 
   const closeAndGetChangedNick = () => {
     setOpenNick(!openNick);
-    dispatch(actionSetNick(currentNick));
+    if (currentNick !== null && currentNick.trim().length !== 0) {
+      dispatch(actionSetNick(currentNick));
+    }
   };
   return (
     <Box
       sx={{
-        m: '10px 0',
+        m: '10px 0 100px',
         display: 'flex',
         alignItems: 'center',
         justifyContent: 'center',
@@ -139,7 +141,7 @@ export const ProfilePage = () => {
                     sx={{
                       mr: '5px',
                     }}
-                    value={currentNick}
+                    value={currentNick === null ? '' : currentNick}
                     onChange={onChangeNick}
                     endAdornment={(
                       <InputAdornment position="end">
@@ -162,7 +164,7 @@ export const ProfilePage = () => {
                     }}
                     item
                   >
-                    {user.nick === null || user?.nick?.length === 0
+                    {user.nick === null || user.nick?.trim().length === 0
                       ? (
                         <Box sx={{display: 'flex'}}>
                           <InputLabel>Enter nick</InputLabel>

+ 5 - 5
src/pages/RegisterPage/RegisterPage.jsx

@@ -30,7 +30,7 @@ export const RegisterPage = () => {
   const [pswConfirmDirty, setConfirmPswDirty] = useState(false);
 
   const isPswValid = password?.length >= 4 && password?.length <= 20;
-  const isConfirmPswValid = password?.length >= 4 && password?.length <= 20;
+  const isConfirmPswValid = confirmPsw?.length >= 4 && confirmPsw?.length <= 20;
   const isLoginValid = login?.length >= 2 && login?.length <= 10;
 
   const dispatch = useDispatch();
@@ -52,7 +52,7 @@ export const RegisterPage = () => {
     if (password === confirmPsw) {
       dispatch(actionRegister({login, password}));
 
-      if (auth.login.length !== 0 && auth.authToken?.length !== 0) {
+      if (auth?.login?.length !== 0 && auth?.authToken?.length !== 0) {
         setOpenSnackBar(!openSnackBar);
       }
     }
@@ -146,7 +146,7 @@ export const RegisterPage = () => {
         {
           (password !== null && confirmPsw !== null)
             ? (password !== confirmPsw) || (!isPswValid && !isConfirmPswValid)
-              ? (<Box>The password confirmation does not match</Box>)
+              ? (<Typography variant="caption" sx={{mt: '10px'}}>The password confirmation does not match.</Typography>)
               : ''
             : ''
         }
@@ -156,10 +156,10 @@ export const RegisterPage = () => {
         color="primary"
         variant="contained"
         sx={{
-          margin: '20px 0',
+          margin: '10px 0 20px 0',
         }}
         onClick={signUp}
-        disabled={!(isLoginValid && isPswValid && isConfirmPswValid)}
+        disabled={!isLoginValid || !isPswValid || !isConfirmPswValid}
         fullWidth
       >
         Sign up

+ 4 - 3
src/pages/SelectedPlaylistPage/SelectedPlaylistPage.jsx

@@ -4,6 +4,7 @@ import { Box } from '@mui/material';
 import { useParams } from 'react-router-dom';
 import { actionFetchOnePlaylist } from '../../store/types/playlistTypes';
 import { TrackList } from '../../components/TrackList/TrackList';
+import { SkeletonProduct } from '../../components/Skeleton/SkeletonProduct';
 
 export const SelectedPlaylistPage = () => {
   const playlists = useSelector(state => state.playlists);
@@ -16,9 +17,9 @@ export const SelectedPlaylistPage = () => {
 
   return (
     <Box>
-      <TrackList
-        tracks={playlists?.selectedPlaylist ?? []}
-      />
+      {playlists.isLoading
+        ? <SkeletonProduct/>
+        : <TrackList tracks={playlists?.selectedPlaylist ?? []} isLoading={playlists.isLoading}/>}
     </Box>
   );
 };

+ 34 - 16
src/pages/UploadPlaylist/UploadPlaylist.jsx

@@ -3,7 +3,7 @@ import {
   Typography,
   Box, Paper, Grid, Button, Avatar, InputLabel, Input,
 } from '@mui/material';
-import { useDispatch, useSelector } from 'react-redux';
+import { useDispatch } from 'react-redux';
 import { arrayMoveImmutable } from 'array-move';
 import AudioFileIcon from '@mui/icons-material/AudioFile';
 import { Dropzone } from '../../components/Dropzone/Dropzone';
@@ -13,9 +13,10 @@ import { actionCreatePlaylist } from '../../store/types/playlistTypes';
 export const UploadPlaylist = () => {
   const dispatch = useDispatch();
   const [files, setFiles] = useState([]);
-
   const [playlistName, setPlaylistName] = useState(null);
+
   const [isNameDirty, setIsNameDirty] = useState(false);
+  const [isDisabled, setIsDisabled] = useState(true);
 
   const onDrop = useCallback(acceptedFiles => {
     setFiles(oldFiles => ([
@@ -32,10 +33,11 @@ export const UploadPlaylist = () => {
     setPlaylistName(e.target.value);
   };
 
-  const isNameValid = playlistName?.length >= 5 && playlistName?.length < 20;
+  const isNameValid = playlistName?.length >= 5 && playlistName?.length < 20 && playlistName?.trim().length !== 0;
 
   const createPlaylist = () => {
     dispatch(actionCreatePlaylist({playlistName, files}));
+    setIsDisabled(!isDisabled);
   };
 
   return (
@@ -82,19 +84,35 @@ export const UploadPlaylist = () => {
             ? (
               <Typography>If you want to create a playlist drag and drop an audio file</Typography>
             ) : (
-              <Button
-                type="submit"
-                color="primary"
-                variant="contained"
-                sx={{
-                  margin: '20px 0',
-                }}
-                onClick={createPlaylist}
-                disabled={!(isNameValid)}
-                fullWidth
-              >
-                Create playlist
-              </Button>
+              isDisabled
+                ? (
+                  <Button
+                    type="submit"
+                    color="primary"
+                    variant="contained"
+                    sx={{
+                      margin: '20px 0',
+                    }}
+                    onClick={createPlaylist}
+                    disabled={!(isNameValid)}
+                    fullWidth
+                  >
+                    Create playlist
+                  </Button>
+                ) : (
+                  <Button
+                    type="submit"
+                    color="primary"
+                    variant="contained"
+                    sx={{
+                      margin: '20px 0',
+                    }}
+                    disabled
+                    fullWidth
+                  >
+                    Uploading
+                  </Button>
+                )
             )}
         </Box>
       </Paper>

+ 31 - 15
src/pages/UploadTracks/UploadTracks.jsx

@@ -3,7 +3,7 @@ import {
   Typography,
   Box, Paper, Grid, Avatar, Button,
 } from '@mui/material';
-import { useDispatch, useSelector } from 'react-redux';
+import { useDispatch } from 'react-redux';
 import { arrayMoveImmutable } from 'array-move';
 import AudioFileIcon from '@mui/icons-material/AudioFile';
 import { Dropzone } from '../../components/Dropzone/Dropzone';
@@ -13,9 +13,11 @@ import { actionSetUploadTrack } from '../../store/types/uploadTypes';
 export const UploadTracks = () => {
   const dispatch = useDispatch();
   const [files, setFiles] = useState([]);
+  const [isDisabled, setIsDisabled] = useState(true);
 
   const addTrack = () => {
     dispatch(actionSetUploadTrack(files));
+    setIsDisabled(!isDisabled);
   };
 
   const onDrop = useCallback(acceptedFiles => {
@@ -61,20 +63,34 @@ export const UploadTracks = () => {
           {files.length === 0
             ? (
               <Typography>If you want to add tracks drag and drop an audio file</Typography>
-            ) : (
-              <Button
-                type="submit"
-                color="primary"
-                variant="contained"
-                sx={{
-                  margin: '20px 0',
-                }}
-                onClick={addTrack}
-                fullWidth
-              >
-                Upload tracks
-              </Button>
-            )}
+            ) : isDisabled
+              ? (
+                <Button
+                  type="submit"
+                  color="primary"
+                  variant="contained"
+                  sx={{
+                    margin: '20px 0',
+                  }}
+                  onClick={addTrack}
+                  fullWidth
+                >
+                  Upload tracks
+                </Button>
+              ) : (
+                <Button
+                  type="submit"
+                  color="primary"
+                  variant="contained"
+                  sx={{
+                    margin: '20px 0',
+                  }}
+                  disabled
+                  fullWidth
+                >
+                  Uploading
+                </Button>
+              )}
         </Box>
       </Paper>
     </Box>

+ 5 - 0
src/store/reducers/playlistsReducer.js

@@ -37,6 +37,11 @@ export function playlistsReducer(state = initialState, action) {
         ...state,
         selectedPlaylist: action.payload,
       };
+    case types.FETCH_USER_PLAYLISTS:
+      return {
+        ...state,
+        isLoading: true,
+      };
     case types.FETCH_USER_PLAYLISTS_SUCCESS:
       return {
         ...state,

+ 0 - 7
src/store/reducers/snackBarReducer.js

@@ -1,12 +1,5 @@
 import types from '../types/snackBarTypes';
 
-export const ALERT_TYPES = {
-  SUCCESS: 'success',
-  ERROR: 'error',
-  WARNING: 'warning',
-  INFO: 'info',
-};
-
 const initialState = {
   isOpen: false,
   type: '',

+ 5 - 0
src/store/reducers/tracksReducer.js

@@ -20,6 +20,11 @@ export function tracksReducer(state = initialState, action) {
         totalCount: action.payload.totalCount,
         isLoading: false,
       };
+    case types.FETCH_USER_TRACKS:
+      return {
+        ...state,
+        isLoading: true,
+      };
     case types.FETCH_USER_TRACKS_SUCCESS:
       return {
         ...state,

+ 0 - 8
src/store/reducers/uploadReducer.js

@@ -7,19 +7,11 @@ const initialState = {
 
 export function uploadReducer(state = initialState, action) {
   switch (action.type) {
-    case types.SET_UPLOAD_FILE:
-      return {
-        ...state,
-      };
     case types.SET_UPLOAD_FILE_SUCCESS:
       return {
         ...state,
         file: action.payload,
       };
-    case types.SET_UPLOAD_TRACK:
-      return {
-        ...state,
-      };
     case types.SET_UPLOAD_TRACK_SUCCESS:
       return {
         ...state,

+ 17 - 14
src/store/sagas/authSaga.js

@@ -16,28 +16,30 @@ import {
 import { forwardToPage } from '../../utils/history';
 import { jwtDecode } from '../../utils/jwtDecode';
 import { actionSetSnackBar } from '../types/snackBarTypes';
-import { ALERT_TYPES } from '../reducers/snackBarReducer';
-import { ROUTES } from '../../constants';
+import { ROUTES, ALERT_TYPES } from '../../constants';
 
 function* loginWorker(action) {
   try {
     localStorage.removeItem('authToken');
     const authToken = yield call(login, action.payload);
 
-    localStorage.setItem('authToken', authToken);
-    yield put(actionLoginSuccess({authToken, login: action.payload.login}));
-    const token = yield call(jwtDecode, authToken);
-    const {id} = token.sub;
+    if (authToken === null) {
+      yield put(actionSetSnackBar({type: ALERT_TYPES.ERROR, message: 'The login or password isn\'t correct! '}));
+    } else {
+      localStorage.setItem('authToken', authToken);
+      yield put(actionLoginSuccess({authToken, login: action.payload.login}));
+      const token = yield call(jwtDecode, authToken);
+      const {id} = token.sub;
 
-    const user = yield call(findUserById, id);
+      const user = yield call(findUserById, id);
 
-    yield put(actionFindUserByIdSuccess(user));
-    yield put(actionSetUser(user));
+      yield put(actionFindUserByIdSuccess(user));
+      yield put(actionSetUser(user));
 
-    yield call(forwardToPage, ROUTES.MAIN_PAGE);
-
-    if (user._id.length !== 0) {
-      yield put(actionSetSnackBar({type: ALERT_TYPES.SUCCESS, message: 'Success!'}));
+      yield call(forwardToPage, ROUTES.MAIN_PAGE);
+      if (user._id.length !== 0) {
+        yield put(actionSetSnackBar({type: ALERT_TYPES.SUCCESS, message: 'Success!'}));
+      }
     }
   } catch (e) {
     yield put(actionLoginFail(e.message));
@@ -72,7 +74,8 @@ function* setNickWorker(action) {
 }
 
 function* logOutWorker(action) {
-  yield put(actionSetUser());
+  yield put(actionSetUser(action.payload));
+  yield put(actionLoginSuccess({...action.payload}));
 }
 
 export function* authSaga() {

+ 1 - 2
src/store/sagas/playlistsSaga.js

@@ -21,9 +21,8 @@ import types, {
 import { getGqlForUpload } from '../../utils/getGqlForUpload';
 import { uploadTracks } from '../../api/upload';
 import { actionSetSnackBar } from '../types/snackBarTypes';
-import { ALERT_TYPES } from '../reducers/snackBarReducer';
 import { forwardToPage } from '../../utils/history';
-import { ROUTES } from '../../constants';
+import { ROUTES, ALERT_TYPES} from '../../constants';
 
 function* getAllPlaylists(action) {
   try {

+ 5 - 3
src/store/sagas/uploadSaga.js

@@ -9,14 +9,16 @@ import { jwtDecode } from '../../utils/jwtDecode';
 import { setAvatar, uploadTracks } from '../../api/upload';
 import { actionSetUser } from '../types/authTypes';
 import { actionSetSnackBar } from '../types/snackBarTypes';
-import { ALERT_TYPES } from '../reducers/snackBarReducer';
 import { forwardToPage } from '../../utils/history';
-import { ROUTES } from '../../constants';
+import { ROUTES, ALERT_TYPES } from '../../constants';
 
 function* uploadFileWorker(action) {
   const auth = yield select(state => state.auth.authToken);
 
-  const response = yield call(getGqlForUpload, {data: action.payload, formName: 'photo', fetchPart: 'upload'});
+  const formData = new FormData();
+  formData.append('photo', action.payload);
+
+  const response = yield call(getGqlForUpload, {formData, fetchPart: 'upload'});
   const avatarId = response._id;
 
   const token = yield call(jwtDecode, auth);

+ 1 - 1
src/store/store.js

@@ -13,7 +13,7 @@ import { playlistsReducer } from './reducers/playlistsReducer';
 import { playlistsSaga } from './sagas/playlistsSaga';
 import { uploadSaga } from './sagas/uploadSaga';
 import { uploadReducer } from './reducers/uploadReducer';
-import { loadState, saveState, stateToStorageSelector } from '../helpers';
+import { loadState, saveState, stateToStorageSelector } from '../utils/localStorage';
 import { snackBarReducer } from './reducers/snackBarReducer';
 
 const sagaMiddleware = createSagaMiddleware();

+ 0 - 2
src/store/types/playerTypes.js

@@ -1,8 +1,6 @@
 const types = {
   PAUSE: 'PAUSE',
   PLAY: 'PLAY',
-  SET_AUDIO: 'SET_AUDIO',
-  SET_CURRENT_TRACK_ID: 'SET_CURRENT_TRACK_ID',
   SET_PLAYER_STATE: 'SET_PLAYER_STATE',
   PREVIOUS_TRACK: 'PREVIOUS_TRACK',
   NEXT_TRACK: 'NEXT_TRACK',

+ 5 - 4
src/helpers/index.jsx

@@ -1,7 +1,9 @@
-import React from 'react';
-
 export const saveState = state => {
-  localStorage.setItem('state', JSON.stringify(state));
+  if (!localStorage.getItem('authToken')) {
+    localStorage.removeItem('state');
+  } else {
+    localStorage.setItem('state', JSON.stringify(state));
+  }
 };
 
 export const stateToStorageSelector = state => ({
@@ -17,7 +19,6 @@ export const loadState = () => {
     }
 
     const state = JSON.parse(serializedState);
-
     saveState(state);
 
     return state;

+ 3 - 6
src/utils/regex.js

@@ -1,6 +1,3 @@
-import React from 'react';
-
-export const regex = (name) => {
-  const result = name.replace(/\.(mp3|mp4|music-2021.com)$/i, '');
-  return result.replace(/(\(.*?\))/g, '');
-};
+export const regex = (name) => name
+  .replace(/\.(mp3|mp4|music-2021.com|wav|flac)$/i, '')
+  .replace(/(\(.*?\))/g, '');