-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6dfe15e
commit 8722d75
Showing
13 changed files
with
154 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { UserLibraryWithSuspense as UserLibrary } from "./src/Library"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@echo/components-library", | ||
"private": true, | ||
"version": "1.0.0", | ||
"scripts": { | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@echo/core-types": "^1.0.0", | ||
"@echo/services-bootstrap": "^1.0.0", | ||
"@echo/services-library": "^1.0.0", | ||
"@effect-rx/rx": "^0.33.8", | ||
"@effect-rx/rx-react": "^0.30.11", | ||
"effect": "^3.2.8" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.2.66", | ||
"@types/react-dom": "^18.2.22" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Library, type Track } from "@echo/core-types"; | ||
import { MainLive } from "@echo/services-bootstrap"; | ||
import { Rx } from "@effect-rx/rx"; | ||
import { Layer, Stream } from "effect"; | ||
import { Suspense, useState } from "react"; | ||
import { LibraryLive } from "@echo/services-library"; | ||
import { useRxSuspenseSuccess } from "@effect-rx/rx-react"; | ||
|
||
const runtime = Rx.runtime(LibraryLive.pipe(Layer.provide(MainLive))); | ||
const observeLibrary = runtime.rx(Stream.unwrap(Library.observeAlbums())); | ||
|
||
const UserLibrary = () => { | ||
const [src, setSrc] = useState<string | undefined>(undefined); | ||
const albums = useRxSuspenseSuccess(observeLibrary).value; | ||
|
||
const playFirstTrack = (tracks: Track[]) => { | ||
const track = tracks[0]; | ||
switch (track.resource.type) { | ||
case "file": | ||
setSrc(track.resource.uri); | ||
break; | ||
case "api": | ||
break; | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<br /> | ||
<audio src={src} autoPlay controls /> | ||
{albums.map((album) => ( | ||
<div key={album.id}> | ||
<h3>{album.name}</h3> | ||
<p>{album.artist.name}</p> | ||
<button onClick={() => playFirstTrack(album.tracks)}>Play</button> | ||
<hr /> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export const UserLibraryWithSuspense = () => ( | ||
<Suspense fallback="Loading library..."> | ||
<UserLibrary /> | ||
</Suspense> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite/client" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"include": [ | ||
"src", | ||
"index.ts" | ||
], | ||
"extends": "../../../tsconfig.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,11 @@ | ||
import { AddProvider } from "@echo/components-add-provider"; | ||
import { UserLibrary } from "@echo/components-library"; | ||
import { ProviderStatus } from "@echo/components-provider-status"; | ||
|
||
export const App = () => ( | ||
<div> | ||
<AddProvider /> | ||
<ProviderStatus /> | ||
<UserLibrary /> | ||
</div> | ||
); | ||
|
||
// const observeLibrary = Effect.gen(function* () { | ||
// const library = yield* Library; | ||
// return yield* library.observeAlbums(); | ||
// }).pipe(Effect.provide(MainLive)); | ||
|
||
// const UserLibrary = () => { | ||
// const [src, setSrc] = useState<string | undefined>(undefined); | ||
// const [albumStream, matcher] = useStream(observeLibrary); | ||
|
||
// const playFirstTrack = (tracks: Track[]) => { | ||
// const track = tracks[0]; | ||
// switch (track.resource.type) { | ||
// case "file": | ||
// setSrc(track.resource.uri); | ||
// break; | ||
// case "api": | ||
// break; | ||
// } | ||
// }; | ||
|
||
// return matcher.pipe( | ||
// Match.tag("empty", () => <h1>Nothing in your library</h1>), | ||
// Match.tag("items", ({ items }) => ( | ||
// <div> | ||
// <audio src={src} autoPlay controls /> | ||
// {items.map(([album, tracks]) => ( | ||
// <div key={album.id}> | ||
// <h1>{album.name}</h1> | ||
// <p>{album.artist.name}</p> | ||
// <button onClick={() => playFirstTrack(tracks)}>Play</button> | ||
// <hr /> | ||
// </div> | ||
// ))} | ||
// </div> | ||
// )), | ||
// Match.tag("failure", () => <h1>Failed to load library</h1>), | ||
// Match.exhaustive, | ||
// )(albumStream); | ||
// }; |