Skip to content

Commit

Permalink
yarn workspaces and migrate example app to vite react
Browse files Browse the repository at this point in the history
  • Loading branch information
E-Kuerschner committed Jan 5, 2025
1 parent 0eacda7 commit 307d1b7
Show file tree
Hide file tree
Showing 69 changed files with 1,144 additions and 8,516 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jobs:
- name: Enable Corepack
run: corepack enable
- name: Dev Server Setup
run: yarn --cwd ./examples install
run: yarn install
- name: Cypress run
uses: cypress-io/github-action@v2
with:
start: yarn --cwd ./examples run start
start: yarn demos-parcel:start
wait-on: http://localhost:1234/
12 changes: 2 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,5 @@ dist
!.yarn/sdks
!.yarn/versions

examples/.pnp.*
examples/.yarn/*
!examples/.yarn/patches
!examples/.yarn/plugins
!examples/.yarn/releases
!examples/.yarn/sdks
!examples/.yarn/versions

test/cypress/videos
test/cypress/screenshots
packages/react-use-audio-player/test/cypress/videos
packages/react-use-audio-player/test/cypress/screenshots
8 changes: 8 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
nodeLinker: node-modules

packageExtensions:
# deasync didn't add node-gyp as a direct dependency so it fails to build in
# Yarn (https://github.com/yarnpkg/berry/issues/5804), so extend its
# pkg.json config here.
deasync@*:
dependencies:
node-gyp: 'latest'
24 changes: 24 additions & 0 deletions demos/vite-spa/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
50 changes: 50 additions & 0 deletions demos/vite-spa/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react'

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})
```
13 changes: 13 additions & 0 deletions demos/vite-spa/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="./src/index.tsx"></script>
</body>
</html>
29 changes: 29 additions & 0 deletions demos/vite-spa/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "vite-spa",
"packageManager": "[email protected]",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --port 1234",
"demos-vite-spa:start": "cd $INIT_CWD && yarn --cwd $PROJECT_CWD/demos/vite-spa dev",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.11.0",
"react-use-audio-player": "workspace:^"
},
"devDependencies": {
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
"@vitejs/plugin-react": "^4.3.4",
"globals": "^15.14.0",
"sass": "^1.83.1",
"typescript": "~5.6.2",
"vite": "^6.0.5"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions examples/src/App.tsx → demos/vite-spa/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from "react"
import { BrowserRouter, Link, Route, Routes } from "react-router-dom"
import { BasicExample } from "./GlobalAudioSource/AudioPlayerState"
import { Spotifyish } from "./GlobalAudioSource/SoundLibrary"
import { AutoPlayNextSound } from "./GlobalAudioSource/AutoPlayNextSound"
import { MultipleSounds } from "./MultipleSounds"
import { GlobalAudioSource } from "./GlobalAudioSource"
import "./app.scss"
import { Streaming } from "./Streaming"
import "./app.scss"

function ExampleSelect() {
return (
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {
import {
useCallback,
useEffect,
useRef,
Expand All @@ -13,7 +13,7 @@ interface AudioSeekBarProps {
className?: string
}

export const AudioSeekBar: FunctionComponent<AudioSeekBarProps> = props => {
export const AudioSeekBar: FunctionComponent<AudioSeekBarProps> = (props) => {
const { className = "" } = props
const { playing, getPosition, duration, seek } = useGlobalAudioPlayer()
const [pos, setPos] = useState(0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React, { FunctionComponent } from "react"
import { FunctionComponent } from "react"
import { Link } from "react-router-dom"

interface BackToHomeProps {
className?: string
}

export const BackToHome: FunctionComponent<BackToHomeProps> = (props) => {
return <Link className={ props.className || "" } to="/">{"< -"} Example Select</Link>
return (
<Link className={props.className || ""} to="/">
{"< -"} Example Select
</Link>
)
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import React, { useEffect, useState, FunctionComponent } from "react"
import { type FunctionComponent } from "react"
import { useGlobalAudioPlayer } from "react-use-audio-player"

export const AudioControls: FunctionComponent<{}> = () => {
const {
play,
pause,
stop,
mute,
muted,
playing,
loop,
looping
} = useGlobalAudioPlayer()
const { play, pause, stop, mute, muted, playing, loop, looping } =
useGlobalAudioPlayer()

return (
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import React, {
useState,
FunctionComponent,
ChangeEvent,
useEffect
} from "react"
import { useState, FunctionComponent, ChangeEvent, useEffect } from "react"
import { AudioLoadOptions, useGlobalAudioPlayer } from "react-use-audio-player"

export const FileLoader: FunctionComponent = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FunctionComponent } from "react"
import { FunctionComponent } from "react"
import { useGlobalAudioPlayer } from "react-use-audio-player"
import { FileLoader } from "./FileLoader"
import { AudioControls } from "./AudioControls"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { useEffect, useState } from "react"
import { useEffect, useState } from "react"
import { useGlobalAudioPlayer } from "react-use-audio-player"
import { TimeLabel } from "../../TimeLabel"
import "./styles"
import { Howl } from "howler"
import "./styles.css"

const songs = [
"/ch_tunes - jam_10.wav",
Expand All @@ -13,20 +12,14 @@ const songs = [
export function AutoPlayNextSound() {
const [songIndex, setSongIndex] = useState(0)

const {
togglePlayPause,
isReady,
load,
seek,
duration,
playing
} = useGlobalAudioPlayer()
const { togglePlayPause, isReady, load, seek, duration, playing } =
useGlobalAudioPlayer()

useEffect(() => {
load(songs[songIndex], {
autoplay: true,
onend: () => {
setSongIndex(index => {
setSongIndex((index) => {
if (index === songs.length - 1) {
return 0
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import React from "react"
import { useGlobalAudioPlayer } from "react-use-audio-player"
import { AudioSeekBar } from "../AudioSeekBar"
import { TimeLabel } from "../TimeLabel"
import { VolumeControl } from "../VolumeControl"

export const PlayBar = () => {
const {
togglePlayPause,
playing,
isReady,
setRate,
rate,
src
} = useGlobalAudioPlayer()
const { togglePlayPause, playing, isReady, setRate, rate, src } =
useGlobalAudioPlayer()

return (
<div className="playBar">
Expand All @@ -38,7 +31,7 @@ export const PlayBar = () => {
name="rateSelect"
id="rate"
value={rate}
onChange={e => setRate(Number(e.target.value))}
onChange={(e) => setRate(Number(e.target.value))}
>
<option value="0.5">1/2x</option>
<option value="1">1x</option>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react"
import { Link, Outlet, useMatch } from "react-router-dom"
import "./styles.scss"
import { PlayBar } from "./PlayBar"
import "./styles.scss"

const ExampleSelect = () => {
return (
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions demos/vite-spa/src/Globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare module "*.css"
declare module "*.scss"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useCallback, useEffect } from "react"
import { useState, useCallback, useEffect, ChangeEvent } from "react"
import { Link } from "react-router-dom"
import { useAudioPlayer } from "react-use-audio-player"
import "./styles.scss"
Expand All @@ -18,9 +18,10 @@ export const MultipleSounds = () => {
song2.togglePlayPause()
}, [song1.togglePlayPause, song2.togglePlayPause])

const handleFade = useCallback(e => {
setXFadeValue(e.target.value)
const ratio = e.target.value / 100
const handleFade = useCallback((e: ChangeEvent<HTMLInputElement>) => {
const value = Number(e.target.value)
setXFadeValue(value)
const ratio = value / 100
song1.setVolume(1 - ratio)
song2.setVolume(ratio)
}, [])
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react"
import { useEffect, useState } from "react"
import { useGlobalAudioPlayer } from "react-use-audio-player"

const formatTime = (seconds: number) => {
Expand All @@ -19,7 +19,7 @@ const formatTime = (seconds: number) => {

export const TimeLabel = () => {
const [pos, setPos] = useState(0)
const { duration, getPosition, playing } = useGlobalAudioPlayer()
const { duration, getPosition } = useGlobalAudioPlayer()

useEffect(() => {
const i = setInterval(() => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ChangeEvent, useCallback } from "react"
import { ChangeEvent, useCallback } from "react"
import { useGlobalAudioPlayer } from "react-use-audio-player"
import "./VolumeControl.scss"

Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions demos/vite-spa/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { StrictMode } from "react"
import { createRoot } from "react-dom/client"
import App from "./App"
import "./app.scss"

const root = createRoot(document.getElementById("root")!)

root.render(
<StrictMode>
<App />
</StrictMode>
)
Loading

0 comments on commit 307d1b7

Please sign in to comment.