Skip to content

Commit

Permalink
quinto dia - final
Browse files Browse the repository at this point in the history
  • Loading branch information
heltonricardo committed Apr 27, 2021
1 parent 0225df2 commit 29bd927
Show file tree
Hide file tree
Showing 13 changed files with 389 additions and 333 deletions.
31 changes: 17 additions & 14 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import format from 'date-fns/format';
import ptBR from 'date-fns/locale/pt-BR';
import format from "date-fns/format";
import ptBR from "date-fns/locale/pt-BR";
import Link from "next/link";

import styles from './styles.module.scss'
import styles from "./styles.module.scss";

export function Header() {
const currentDate = format(new Date(), 'EEEEEE, d MMMM', {
locale: ptBR,
});
const currentDate = format(new Date(), "EEEEEE, d MMMM", {
locale: ptBR,
});

return (
<header className={styles.headerContainer}>
<img src="/logo.svg" alt="Podcastr" />
return (
<header className={styles.headerContainer}>
<Link href="/">
<img src="/logo.svg" alt="Podcastr" />
</Link>

<p>O melhor para você ouvir, sempre</p>
<p>O melhor para você ouvir, sempre</p>

<span>{currentDate}</span>
</header>
);
}
<span>{currentDate}</span>
</header>
);
}
36 changes: 20 additions & 16 deletions src/components/Header/styles.module.scss
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
.headerContainer {
background: var(--white);
height: 6.5rem;
background: var(--white);
height: 6.5rem;

display: flex;
align-items: center;
display: flex;
align-items: center;

padding: 2rem 4rem;
padding: 2rem 4rem;

border-bottom: 1px solid var(--gray-100);
border-bottom: 1px solid var(--gray-100);

p {
margin-left: 2rem;
padding: 0.25rem 0 0.25rem 2rem;
border-left: 1px solid var(--gray-100);
}
p {
margin-left: 2rem;
padding: 0.25rem 0 0.25rem 2rem;
border-left: 1px solid var(--gray-100);
}

span {
margin-left: auto;
text-transform: capitalize;
}
}
span {
margin-left: auto;
text-transform: capitalize;
}

img:hover {
cursor: pointer;
}
}
20 changes: 18 additions & 2 deletions src/components/Player/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ export function Player() {
isPlaying,
isLooping,
isShuffling,
hasPrevious,
hasNext,
togglePlay,
toggleLoop,
toggleShuffle,
setPlayingState,
playNext,
playPrevious,
hasPrevious,
hasNext,
clearPlayerState,
} = usePlayer();

// Anotação 02
Expand All @@ -48,6 +49,19 @@ export function Player() {
});
}

function handleSeek(amount: number) {
audioRef.current.currentTime = amount;
setProgress(amount);
}

function handleEpisodeEnded() {
if (hasNext) {
playNext();
} else {
clearPlayerState();
}
}

const episode = episodeList[currentEpisodeIndex];

return (
Expand Down Expand Up @@ -82,6 +96,7 @@ export function Player() {
<Slider
max={episode.duration}
value={progress}
onChange={handleSeek}
trackStyle={{ backgroundColor: "#04d361" }}
railStyle={{ backgroundColor: "#9f75ff" }}
handleStyle={{ borderColor: "#04d361", borderWidth: 4 }}
Expand All @@ -102,6 +117,7 @@ export function Player() {
autoPlay
loop={isLooping}
onLoadedMetadata={setupProgressListener}
onEnded={handleEpisodeEnded}
// Anotação 05
onPlay={() => setPlayingState(true)}
onPause={() => setPlayingState(false)}
Expand Down
13 changes: 10 additions & 3 deletions src/contexts/PlayerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type PlayerContextData = {
isPlaying: boolean;
isLooping: boolean;
isShuffling: boolean;
hasPrevious: boolean;
hasNext: boolean;
play: (episode: Episode) => void;
playList: (list: Episode[], index: number) => void;
togglePlay: () => void;
Expand All @@ -22,8 +24,7 @@ type PlayerContextData = {
setPlayingState: (state: boolean) => void;
playNext: () => void;
playPrevious: () => void;
hasPrevious: boolean;
hasNext: boolean;
clearPlayerState: () => void;
};

type PlayerContextProviderProps = {
Expand Down Expand Up @@ -71,8 +72,13 @@ export function PlayerContextProvider({
setIsPlaying(state);
}

function clearPlayerState() {
setEpisodeList([]);
setCurrentEpisodeIndex(0);
}

const hasPrevious = currentEpisodeIndex > 0;
const hasNext = currentEpisodeIndex + 1 < episodeList.length;
const hasNext = isShuffling || currentEpisodeIndex + 1 < episodeList.length;

function playNext() {
if (isShuffling) {
Expand Down Expand Up @@ -109,6 +115,7 @@ export function PlayerContextProvider({
playPrevious,
hasPrevious,
hasNext,
clearPlayerState,
}}
>
{children}
Expand Down
38 changes: 21 additions & 17 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@
import Document, { Html, Head, Main, NextScript } from "next/document";

export default class MyDocument extends Document {
render() {
return (
<Html>
<Head>
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Inter&family=Lexend:wght@500;600&display=swap"
rel="stylesheet"
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
render() {
return (
<Html>
<Head>
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href={
"https://fonts.googleapis.com/" +
"css2?family=Inter&family=Lexend:wght@500;600&display=swap"
}
rel="stylesheet"
/>
<link rel="shortcut icon" href="/favicon.png" type="image/png" />
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
7 changes: 6 additions & 1 deletion src/pages/episodes/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { usePlayer } from "../../contexts/PlayerContext";
import { convertDurationToTimeString } from "../../utils/convertDurationToTimeString";
import Link from "next/link";
import Image from "next/image";
import Head from "next/head";
import ptBR from "date-fns/locale/pt-BR";
import styles from "./episode.module.scss";

Expand All @@ -25,10 +26,14 @@ type EpisodeProps = {
};

export default function Episode({ episode }: EpisodeProps) {
const { play } = usePlayer();
const { play } = usePlayer();

return (
<div className={styles.episodeContainer}>
<Head>
<title>{episode.title} | Podcastr</title>
</Head>

<div className={styles.episode}>
<div className={styles.thumbnailContainer}>
<Link href="/">
Expand Down
Loading

0 comments on commit 29bd927

Please sign in to comment.