Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jump Links to Player #118

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions remix/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2,
"semi": true,
"arrowParens": "always"
}
2 changes: 1 addition & 1 deletion remix/api/metafile.css.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion remix/api/metafile.js.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion remix/api/metafile.server.json

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions remix/app/components/AudioPlayer/FeaturedAudioPlayer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useRef } from "react";
import { useAudioPlayer } from "react-hook-audio";
import { calculateTime } from "~/lib/timeHelpers";
import { Icon } from "../Icon";
import { useRef } from 'react';
import { useAudioPlayer } from 'react-hook-audio';
import { calculateTime } from '~/lib/timeHelpers';
import { Icon } from '../Icon';

interface FeaturedAudioPlayerProps {
track: string;
Expand All @@ -24,8 +24,6 @@ const FeaturedAudioPlayer = ({ track }: FeaturedAudioPlayerProps) => {
togglePlaying,
} = useAudioPlayer(audioPlayer, progressBar);

console.log({ isPlaying });

return (
<div className="featured-audio-player relative">
<audio
Expand Down
73 changes: 24 additions & 49 deletions remix/app/components/AudioPlayer/WaveformPlayer.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { calculateTime } from "~/lib/timeHelpers";
import { Icon } from "../Icon";
import { useAudioPlayer } from "react-hook-audio";
import { useRef } from "react";
import { calculateTime } from '~/lib/timeHelpers';
import { Icon } from '../Icon';
import { useAudioPlayer } from 'react-hook-audio';
import { useEffect, useRef } from 'react';

interface WaveformPlayerProps {
artwork: string;
episodeTitle: string;
audioPath: string;
episodeNumber: number;
skipTo: number;
skipTo: number | null;
}

const WaveformPlayer = ({
artwork = "/images/podcast-cover.jpg",
artwork = '/images/podcast-cover.jpg',
audioPath,
episodeNumber,
episodeTitle,
skipTo,
}: WaveformPlayerProps) => {
// references
const audioPlayer = useRef<HTMLAudioElement>(); // set up reference for the audio component
const progressBar = useRef<HTMLInputElement>(); // reference for the progress bar
const audioPlayer = useRef<HTMLAudioElement>(null); // set up reference for the audio component
const progressBar = useRef<HTMLInputElement>(null); // reference for the progress bar

// hooks
const {
Expand All @@ -31,25 +32,22 @@ const WaveformPlayer = ({
forwardThirty,
isPlaying,
onLoadedMetadata,
// skipToTime,
skipToTime,
speed,
tapSpaceBar,
togglePlaying,
} = useAudioPlayer(audioPlayer, progressBar);

// useEffect(() => {
// skipToTime(skipTo);
// }, [skipTo]);
useEffect(() => {
if (skipTo !== null) {
skipToTime(skipTo);
}
}, [skipTo]);

return (
<div className="waveform-audio-player border-bastille border-1 p-5 max-w-[660px] my-0 mx-auto relative w-full">
{/* audio element */}
<audio
ref={audioPlayer}
src={audioPath}
preload="metadata"
onLoadedMetadata={onLoadedMetadata}
/>
<audio ref={audioPlayer} src={audioPath} preload="metadata" onLoadedMetadata={onLoadedMetadata} />

{/* album cover */}
<div className="album-cover">
Expand All @@ -63,14 +61,10 @@ const WaveformPlayer = ({
{/* episode meta data */}
<div className="text-left py-0 px-5">
<h4 className="text-gray font-mono text-sm font-normal leading-none mt-0 mb-[10px] mx-0 p-0">
<span className="block sm:inline">COMPRESSED.fm</span>{" "}
<span className="block sm:inline episode-number">
{episodeNumber && `Episode ${episodeNumber}`}
</span>
<span className="block sm:inline">COMPRESSED.fm</span>{' '}
<span className="block sm:inline episode-number">{episodeNumber && `Episode ${episodeNumber}`}</span>
</h4>
<h2 className="font-sans text-xl leading-none m-0 p-0">
{episodeTitle}
</h2>
<h2 className="font-sans text-xl leading-none m-0 p-0">{episodeTitle}</h2>
</div>

{/* play / pause */}
Expand Down Expand Up @@ -106,43 +100,24 @@ const WaveformPlayer = ({
</button>

{/* current time */}
<div className="current-time top-[15px] left-[100px]">
{calculateTime(currentTime)}
</div>
<div className="current-time top-[15px] left-[100px]">{calculateTime(currentTime)}</div>

{/* progress bar */}
<div className="progress-bar">
<input
type="range"
min="0"
max="100"
defaultValue="0"
ref={progressBar}
onChange={changeAudioToPlayhead}
/>
<input type="range" min="0" max="100" defaultValue="0" ref={progressBar} onChange={changeAudioToPlayhead} />
</div>

{/* duration */}
<div className="duration top-[15px] right-5">
{duration && calculateTime(duration)}
</div>
<div className="duration top-[15px] right-5">{duration && calculateTime(duration)}</div>

{/* back thirty */}
<button
type="button"
onClick={backThirty}
className="forwardBackward backward left-[120px] top-[47px]"
>
<button type="button" onClick={backThirty} className="forwardBackward backward left-[120px] top-[47px]">
<Icon name="arrow" className="back rotate-180" />
30
</button>

{/* forward thirty */}
<button
type="button"
onClick={forwardThirty}
className="forwardBackward forward right-0 top-[47px]"
>
<button type="button" onClick={forwardThirty} className="forwardBackward forward right-0 top-[47px]">
30
<Icon name="arrow" />
</button>
Expand Down
10 changes: 5 additions & 5 deletions remix/app/components/EpisodeGrid/Episode.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Link } from "@remix-run/react";
import { EpisodeZeros } from "../EpisodeZeros";
import { formatLongDate } from "~/lib/dateHelpers";
import { MoreLink } from "../MoreLink";
import { Link } from '@remix-run/react';
import { EpisodeZeros } from '../EpisodeZeros';
import { formatLongDate } from '~/lib/dateHelpers';
import { MoreLink } from '../MoreLink';

interface EpisodeProps {
className?: string;
Expand All @@ -19,7 +19,7 @@ const Episode = ({ className, episode }: EpisodeProps) => {
Episode
</span>
<span className="text-yellow text-[132px] font-black leading-none flex items-center">
{EpisodeZeros(episodeNumber)}
{EpisodeZeros(episodeNumber.toString())}
{episodeNumber}
</span>
</div>
Expand Down
10 changes: 7 additions & 3 deletions remix/app/components/EpisodeGrid/EpisodeGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Episode } from "./Episode";
import { Episode as EpisodeComponent } from './Episode';

interface EpisodeGridProps {
header: string;
Expand All @@ -9,7 +9,7 @@ const EpisodeGrid = ({ header, episodes }: EpisodeGridProps) => {
return (
<div
className={`episode-grid grid grid-cols-1 md:grid-cols-2 regular:grid-cols-3 gap-y-14 my-[60px] mx-auto max-w-pageWidth ${
header ? "w-section-header" : "no-section-header"
header ? 'w-section-header' : 'no-section-header'
}`}
>
{header && (
Expand All @@ -19,7 +19,11 @@ const EpisodeGrid = ({ header, episodes }: EpisodeGridProps) => {
)}
{episodes &&
episodes.map((item) => (
<Episode className="episode-card" key={item._id} episode={item} />
<EpisodeComponent
className="episode-card"
key={item._id}
episode={item}
/>
))}
</div>
);
Expand Down
18 changes: 14 additions & 4 deletions remix/app/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ interface Episode {
audioPath: string;
guest: Guest[];
publishedAt: string;
episodeNumber: string;
episodeNumber: number;
episodeCover: {
asset: {
url: string;
};
};
slug: {
current: string
}
current: string;
};
title: string;
briefDescription: string;
cover: string;
relatedEpisodes: Episode[];
//todo: fix anys
timeJump?: TimeJump[];
listLink?: ListLink[];
sponsor?: Sponsor[];
}

interface Faq {
Expand Down Expand Up @@ -83,4 +93,4 @@ interface TimeJump {
_key: string;
time: string;
description: string;
}
}
49 changes: 29 additions & 20 deletions remix/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
import { cssBundleHref } from "@remix-run/css-bundle";
import type { LinksFunction } from "@remix-run/node";
import {
Links,
LiveReload,
Meta,
Outlet,
Scripts,
ScrollRestoration,
useLoaderData,
} from "@remix-run/react";
import stylesheet from "~/tailwind.css";
import { LiveNow } from "./components/LiveNow";
import { getClient } from "./lib/sanity";
import { CurrentlyRecordingQuery } from "./queries/Queries";
import { cssBundleHref } from '@remix-run/css-bundle';
import type { LinksFunction, V2_MetaFunction } from '@remix-run/node';
import { Links, LiveReload, Meta, Outlet, Scripts, ScrollRestoration, useLoaderData } from '@remix-run/react';
import stylesheet from '~/tailwind.css';
import { LiveNow } from './components/LiveNow';
import { getClient } from './lib/sanity';
import { CurrentlyRecordingQuery } from './queries/Queries';

export const links: LinksFunction = () => [
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
{ rel: "stylesheet", href: stylesheet },
...(cssBundleHref ? [{ rel: 'stylesheet', href: cssBundleHref }] : []),
{ rel: 'stylesheet', href: stylesheet },
];

export const loader = async () => {
const data = await getClient().fetch(CurrentlyRecordingQuery);
return { data };
};

export const meta: V2_MetaFunction = () => {
return [
{ title: 'Compressed.fm' },
{
name: 'description',
content:
'A weekly podcast, hosted by Amy Dutton and James Q Quick, all about web design and development with a little bit of zest.',
},
{
name: 'og:image',
content: '/images/podcast-cover.jpg',
},
{
name: 'og:image:alt',
content: 'Compressed.fm Podcast Cover',
},
];
};

export default function App() {
const { data } = useLoaderData();
const { currentlyRecording, recordingOnYouTube, recordingOnTwitch } = data;
Expand All @@ -37,9 +48,7 @@ export default function App() {
<Links />
</head>
<body>
{currentlyRecording ? (
<LiveNow youtube={recordingOnYouTube} twitch={recordingOnTwitch} />
) : null}
{currentlyRecording ? <LiveNow youtube={recordingOnYouTube} twitch={recordingOnTwitch} /> : null}
<Outlet />
<ScrollRestoration />
<Scripts />
Expand Down
34 changes: 11 additions & 23 deletions remix/app/routes/_index/route.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
import { useLoaderData } from "@remix-run/react";
import type { V2_MetaFunction } from "@remix-run/node";
import { getClient } from "~/lib/sanity";
import { useLoaderData } from '@remix-run/react';
import { getClient } from '~/lib/sanity';
import {
HostDetailsQuery,
LegalQuery,
RecentEpisodesQuery,
TagsQuery,
} from "~/queries/Queries";
import { HeaderHome } from "./HeaderHome";
import { Footer } from "~/components/Footer";
import { Podcatchers } from "~/components/Podcatchers";
import { VerticalDivider } from "~/components/VerticalDivider";
import { FeaturedEpisode } from "~/components/FeaturedEpisode";
import { TheHosts } from "./TheHosts";
import { EpisodeGrid } from "~/components/EpisodeGrid/EpisodeGrid";
import { Newsletter } from "~/components/Newsletter";

export const meta: V2_MetaFunction = () => {
return [
{ title: "Compressed.fm" },
{
name: "description",
content:
"A weekly podcast, hosted by Amy Dutton and James Q Quick, all about web design and development with a little bit of zest.",
},
];
};
} from '~/queries/Queries';
import { HeaderHome } from './HeaderHome';
import { Footer } from '~/components/Footer';
import { Podcatchers } from '~/components/Podcatchers';
import { VerticalDivider } from '~/components/VerticalDivider';
import { FeaturedEpisode } from '~/components/FeaturedEpisode';
import { TheHosts } from './TheHosts';
import { EpisodeGrid } from '~/components/EpisodeGrid/EpisodeGrid';
import { Newsletter } from '~/components/Newsletter';

export const loader = async () => {
const episodes = await getClient().fetch(RecentEpisodesQuery);
Expand Down
4 changes: 2 additions & 2 deletions remix/app/routes/_interior.episode.$slug/EpisodeSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EpisodeZeros } from "~/components/EpisodeZeros";
import { formatLongDate } from "~/lib/dateHelpers";
import { EpisodeZeros } from '~/components/EpisodeZeros';
import { formatLongDate } from '~/lib/dateHelpers';

interface EpisodeSummaryProps {
briefDescription: string;
Expand Down
11 changes: 7 additions & 4 deletions remix/app/routes/_interior.episode.$slug/JumpLinks.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { calculateTime } from "~/lib/timeHelpers";
import { calculateTime } from '~/lib/timeHelpers';

interface JumpLinksProps {
className: string;
timeJump: TimeJump[];
handleClick: (time: string) => void;
handleClick: (time: number) => void;
}

const JumpLinks = ({ className, timeJump, handleClick }: JumpLinksProps) => {
const onClick = (e: React.MouseEvent<HTMLButtonElement>, time: string) => {
const onClick = (e: React.MouseEvent<HTMLButtonElement>, timeStr: string) => {
e.preventDefault();
handleClick(time);
const time = Number(timeStr);
if (!isNaN(time)) {
handleClick(time);
}
};

return (
Expand Down
Loading