Skip to content

Commit

Permalink
playlist created
Browse files Browse the repository at this point in the history
  • Loading branch information
AKAspanion committed Apr 24, 2021
1 parent e5050de commit 6c4762a
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 40 deletions.
36 changes: 33 additions & 3 deletions src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { useDispatch, useSelector } from 'react-redux';
import { Header, Slider, Visualizer } from '../components';
import { useResize } from '../hooks';

import { ADD_SONGS, PAUSE_SONG, PLAY_SONG, RESUME_SONG } from '../redux';
import {
ADD_SONGS,
DELETE_SONG,
PAUSE_SONG,
PLAY_SONG,
RESUME_SONG,
} from '../redux';
import AudioSession from '../services/audio-session';
import { Home, NowPlaying, Playlist } from '../views';
import './styles.css';
Expand All @@ -14,6 +20,7 @@ function App() {

const [ref, size] = useResize();

const input = useRef(null);
const audio = useRef(null);
const dispatch = useDispatch();

Expand Down Expand Up @@ -58,10 +65,15 @@ function App() {
});
}
} catch (error) {
console.log(error);
dispatch(PLAY_SONG(0));
}
};

const stop = () => {
const htmlAudio: HTMLAudioElement = audioPlayer();
htmlAudio.src = '';
};

const nextSong = () => {
if (isSongsThere()) {
dispatch(PLAY_SONG((playState.index + 1) % songs.length));
Expand Down Expand Up @@ -94,6 +106,11 @@ function App() {
}
};

const deleteSong = (index: number) => {
dispatch(PLAY_SONG(-2));
dispatch(DELETE_SONG(index));
};

useEffect(() => {
if (
JSON.stringify(prevPlayState.current) !== JSON.stringify(playState) &&
Expand All @@ -108,6 +125,9 @@ function App() {
dispatch(PLAY_SONG(0));
} else if (index === prevIndex) {
play();
} else if (index === -2) {
// stop song
stop();
} else {
start(index);
}
Expand All @@ -131,15 +151,23 @@ function App() {
}
};

const addSongs = () => {
if (input.current) {
const filePicker: HTMLInputElement = input.current!;
filePicker.click();
}
};

return (
<div ref={ref} className="app__wrapper">
<div className="app__container">
<Header />
<Header onRightIconClick={() => addSongs()} />
<Home
playlist={
<Playlist
songs={songs}
playState={playState}
onDelete={(index: number) => deleteSong(index)}
onClick={(index: number) =>
index === playState.index
? playState.playing
Expand Down Expand Up @@ -169,6 +197,7 @@ function App() {
hidden
multiple
type="file"
ref={input}
accept="audio/mp3"
onChange={e => dispatch(ADD_SONGS(e.target.files))}
/>
Expand All @@ -183,6 +212,7 @@ function App() {
<NowPlaying
percent={range}
width={size.width}
open={playState.index > -1}
playing={playState.playing}
song={songs[playState.index]}
onPlay={() => resumeSong()}
Expand Down
15 changes: 15 additions & 0 deletions src/assets/icons/Delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/assets/icons/Search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/assets/icons/add.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 4 additions & 20 deletions src/assets/icons/back.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/assets/icons/delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/assets/icons/more.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 17 additions & 8 deletions src/components/header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import './styles.css';

import back from '../../assets/icons/back.svg';
import menu from '../../assets/icons/menu.svg';
import more from '../../assets/icons/more.svg';
import add from '../../assets/icons/add.svg';

type HeaderProps = {};
type HeaderProps = {
onLeftIconClick?: Function;
onRightIconClick?: Function;
};

const Header = ({}: HeaderProps) => {
const Header = ({ onLeftIconClick, onRightIconClick }: HeaderProps) => {
return (
<div className="header">
<div className="header__menu__left">
<div className="header__icon">
<img alt="close" src={back} />
<div
className="header__icon"
onClick={() => onLeftIconClick && onLeftIconClick()}
>
<img alt="close" src={more} />
</div>
</div>
<div className="header__menu__right">
<div className="header__icon">
<img alt="close" src={menu} />
<div
className="header__icon"
onClick={() => onRightIconClick && onRightIconClick()}
>
<img alt="close" src={add} />
</div>
</div>
</div>
Expand Down
12 changes: 8 additions & 4 deletions src/components/header/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
justify-content: space-between;
}
.header__menu__left {
padding-left: var(--padding);
padding-left: calc(var(--padding) * 1.15);
}
.header__menu__right {
padding-right: var(--padding);
padding-right: calc(var(--padding) * 1.15);
}

.header__icon {
width: 42px;
height: 42px;
width: 48px;
height: 48px;
display: flex;
cursor: pointer;
border-radius: 24px;
Expand All @@ -25,3 +25,7 @@
.header__icon:hover {
background: var(--bg-color-accent);
}

.header__icon img {
width: 30px;
}
6 changes: 6 additions & 0 deletions src/redux/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import {
T_PLAY_SONG,
T_PAUSE_SONG,
T_RESUME_SONG,
T_REMOVE_SONGS,
} from '../types';

export const ADD_SONGS = (songs: any) => ({
type: T_ADD_SONGS,
songs,
});

export const DELETE_SONG = (index: any) => ({
type: T_REMOVE_SONGS,
index,
});

export const PLAY_SONG = (index: number) => ({
type: T_PLAY_SONG,
index,
Expand Down
2 changes: 1 addition & 1 deletion src/redux/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const songReducer = (state = [], action: any) => {
);
}
case T_REMOVE_SONGS: {
return state.filter((_, index) => index !== action.id);
return state.filter((_, index) => index !== action.index);
}
default: {
return state;
Expand Down
4 changes: 2 additions & 2 deletions src/views/now-playing/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
align-items: flex-end;
justify-content: center;
transform: translateY(150%);
transition: transform 0.3s ease;
transition: transform 0.5s ease;
--padding-here: calc(var(--padding) * 0.8);
}

.nowplaying.nowplaying--open {
transform: translateY(0%);
transition: transform 0.3s ease;
transition: transform 0.5s ease;
}

.nowplaying__container {
Expand Down
11 changes: 10 additions & 1 deletion src/views/playlist/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ import './styles.css';

import play from '../../assets/icons/play.svg';
import pause from '../../assets/icons/pause.svg';
import del from '../../assets/icons/delete.svg';

type PlaylistProps = {
songs: any[];
grid?: boolean;
playState?: any;
onClick: Function;
onClick?: Function;
onDelete?: Function;
};

const Playlist = ({
grid = false,
songs,
onClick,
onDelete,
playState = {},
}: PlaylistProps) => {
const { index, playing } = playState;
Expand All @@ -33,6 +36,12 @@ const Playlist = ({
<div title={name} className="playlist__name">
{name}
</div>
<div
className="playlist__icon playlist__icon--right"
onClick={() => onDelete && onDelete(i)}
>
<img alt="play" src={del} />
</div>
</div>
))}
</div>
Expand Down
8 changes: 7 additions & 1 deletion src/views/playlist/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
width: calc(100% - 56px);
width: calc(100% - 56px - 56px);
}

.playlist__icon--right {
margin-right: 0px;
background: transparent;
margin-left: var(--item-padding);
}

0 comments on commit 6c4762a

Please sign in to comment.