feat: podcast corner player (#155)
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="#fff" fill-opacity=".01" d="M24 0v24H0V0z"/><path fill="#10161F" d="M10.704 12.858a1 1 0 0 0-.86-1.806zM4.319 7.182a1 1 0 1 0-1.991-.189zM12.499 7v1zm7.5 8.5a1 1 0 1 0 2 0zM4.644 13.02l-.073.998zm5.202-1.968c-1.688.802-3.296 1.106-5.129.971l-.146 1.995c2.184.16 4.137-.211 6.134-1.16zm-4.692 1.277c-.752-1.674-1.01-3.284-.834-5.147l-1.991-.189c-.209 2.198.103 4.157 1 6.156zM12.5 8a7.5 7.5 0 0 1 7.5 7.5h2A9.5 9.5 0 0 0 12.5 6zm-7.17 5.294A7.504 7.504 0 0 1 12.5 8V6a9.502 9.502 0 0 0-9.082 6.706zm-.614-1.27a.52.52 0 0 1 .437.305l-1.824.82a1.48 1.48 0 0 0 1.24.869z"/></svg>
|
||||
|
After Width: | Height: | Size: 662 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="#fff" fill-opacity=".01" d="M24 0v24H0V0z"/><path stroke="#10161F" stroke-linejoin="round" stroke-width="2" d="M11.498 10.656c.047-2.233.07-3.35 1.08-3.906 1.009-.557 1.958.014 3.856 1.155a53.241 53.241 0 0 1 2.142 1.357c1.661 1.11 2.492 1.665 2.491 2.735 0 1.07-.83 1.623-2.492 2.73a54.673 54.673 0 0 1-2.157 1.367c-1.887 1.135-2.83 1.703-3.84 1.146-1.008-.557-1.032-1.667-1.08-3.887a63.588 63.588 0 0 1 0-2.697ZM2.498 10.656c.047-2.233.07-3.35 1.08-3.906 1.009-.557 1.958.014 3.856 1.155.26.157.529.32.804.493 1.845 1.154 2.767 1.73 3.03 2.98.071.343.071.89 0 1.233-.263 1.25-1.186 1.827-3.03 2.98-.282.177-.555.344-.82.503-1.887 1.135-2.83 1.703-3.84 1.146-1.008-.557-1.032-1.667-1.08-3.887a63.725 63.725 0 0 1 0-2.697Z"/></svg>
|
||||
|
After Width: | Height: | Size: 818 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="#fff" fill-opacity=".01" d="M24 0v24H0V0z"/><path fill="#10161F" d="M13.296 12.858a1 1 0 0 1 .86-1.806zm6.385-5.676a1 1 0 0 1 1.991-.189zM11.501 7v1zM4 15.5a1 1 0 1 1-2 0zm15.356-2.48.073.998zm-5.202-1.968c1.688.802 3.296 1.106 5.129.971l.146 1.995c-2.184.16-4.137-.211-6.134-1.16zm4.692 1.277c.752-1.674 1.01-3.284.834-5.147l1.991-.189c.209 2.198-.103 4.157-1 6.156zM11.5 8A7.5 7.5 0 0 0 4 15.5H2A9.5 9.5 0 0 1 11.5 6zm7.17 5.294A7.504 7.504 0 0 0 11.5 8V6c4.276 0 7.89 2.824 9.083 6.706zm.614-1.27a.52.52 0 0 0-.437.305l1.824.82a1.48 1.48 0 0 1-1.24.869z"/></svg>
|
||||
|
After Width: | Height: | Size: 652 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="#fff" fill-opacity=".01" d="M24 0v24H0V0z"/><path stroke="#10161F" stroke-linecap="round" stroke-width="2" d="M8 5v14m8-14v14"/></svg>
|
||||
|
After Width: | Height: | Size: 221 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="#fff" fill-opacity=".01" d="M24 0v24H0V0z"/><path stroke="#10161F" stroke-width="2" d="M5.334 10.424c.062-3.213.093-4.82 1.56-5.667 1.467-.847 2.874-.07 5.69 1.484a81.402 81.402 0 0 1 2.725 1.574c2.746 1.657 4.119 2.485 4.118 4.18 0 1.693-1.373 2.52-4.119 4.176a84.049 84.049 0 0 1-2.746 1.585c-2.8 1.546-4.2 2.32-5.667 1.473-1.467-.846-1.498-2.445-1.56-5.642a81.662 81.662 0 0 1 0-3.163Z"/></svg>
|
||||
|
After Width: | Height: | Size: 484 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="#fff" fill-opacity=".01" d="M24 0v24H0V0z"/><path stroke="#10161F" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 9.763c.614.55 1 1.348 1 2.236 0 .889-.386 1.687-1 2.236m2-6.708A5.985 5.985 0 0 1 21 12a5.985 5.985 0 0 1-2 4.472m-12.005-.176L9.498 18.3c1.807 1.445 2.71 2.168 3.537 1.812.826-.355.92-1.468 1.11-3.694.253-2.991.253-5.843 0-8.834-.19-2.226-.284-3.34-1.11-3.694-.827-.355-1.73.367-3.537 1.813L6.995 7.704a3.634 3.634 0 0 1-2.27.796v0A2.725 2.725 0 0 0 2 11.225v1.55A2.725 2.725 0 0 0 4.725 15.5v0c.825 0 1.626.28 2.27.796"/></svg>
|
||||
|
After Width: | Height: | Size: 654 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="#fff" fill-opacity=".01" d="M24 0v24H0V0z"/><path stroke="#10161F" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 9.763c.614.55 1 1.347 1 2.236 0 .888-.386 1.687-1 2.236m2-6.708a5.985 5.985 0 0 1 2 4.472 5.985 5.985 0 0 1-2 4.472M4 8.597a2.727 2.727 0 0 0-2 2.628v1.55A2.725 2.725 0 0 0 4.725 15.5c.825 0 1.626.28 2.27.796l2.503 2.002c1.807 1.446 2.71 2.168 3.537 1.813.405-.174.634-.53.785-1.111m.475-5c.084-2.137.034-4.24-.15-6.417-.19-2.226-.284-3.34-1.11-3.695-.827-.355-1.73.368-3.537 1.813L7.5 7.3M4.222 4.223l15.556 15.556"/></svg>
|
||||
|
After Width: | Height: | Size: 649 B |
@@ -50,6 +50,7 @@
|
||||
"@radix-ui/react-radio-group": "1.2.0",
|
||||
"@radix-ui/react-scroll-area": "1.1.0",
|
||||
"@radix-ui/react-select": "2.1.1",
|
||||
"@radix-ui/react-slider": "^1.2.0",
|
||||
"@radix-ui/react-slot": "1.1.0",
|
||||
"@radix-ui/react-switch": "1.1.0",
|
||||
"@radix-ui/react-tabs": "1.1.0",
|
||||
|
||||
@@ -79,6 +79,9 @@ importers:
|
||||
'@radix-ui/react-select':
|
||||
specifier: 2.1.1
|
||||
version: 2.1.1(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
'@radix-ui/react-slider':
|
||||
specifier: ^1.2.0
|
||||
version: 1.2.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
'@radix-ui/react-slot':
|
||||
specifier: 1.1.0
|
||||
version: 1.1.0(@types/react@18.3.3)(react@18.3.1)
|
||||
@@ -1956,6 +1959,19 @@ packages:
|
||||
'@types/react-dom':
|
||||
optional: true
|
||||
|
||||
'@radix-ui/react-slider@1.2.0':
|
||||
resolution: {integrity: sha512-dAHCDA4/ySXROEPaRtaMV5WHL8+JB/DbtyTbJjYkY0RXmKMO2Ln8DFZhywG5/mVQ4WqHDBc8smc14yPXPqZHYA==}
|
||||
peerDependencies:
|
||||
'@types/react': '*'
|
||||
'@types/react-dom': '*'
|
||||
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
|
||||
react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
|
||||
peerDependenciesMeta:
|
||||
'@types/react':
|
||||
optional: true
|
||||
'@types/react-dom':
|
||||
optional: true
|
||||
|
||||
'@radix-ui/react-slot@1.0.2':
|
||||
resolution: {integrity: sha512-YeTpuq4deV+6DusvVUW4ivBgnkHwECUu0BiN43L5UCDFgdhsRUWAghhTF5MbvNTPzmiFOx90asDSUjWuCNapwg==}
|
||||
peerDependencies:
|
||||
@@ -8838,6 +8854,25 @@ snapshots:
|
||||
'@types/react': 18.3.3
|
||||
'@types/react-dom': 18.3.0
|
||||
|
||||
'@radix-ui/react-slider@1.2.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)':
|
||||
dependencies:
|
||||
'@radix-ui/number': 1.1.0
|
||||
'@radix-ui/primitive': 1.1.0
|
||||
'@radix-ui/react-collection': 1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
'@radix-ui/react-compose-refs': 1.1.0(@types/react@18.3.3)(react@18.3.1)
|
||||
'@radix-ui/react-context': 1.1.0(@types/react@18.3.3)(react@18.3.1)
|
||||
'@radix-ui/react-direction': 1.1.0(@types/react@18.3.3)(react@18.3.1)
|
||||
'@radix-ui/react-primitive': 2.0.0(@types/react-dom@18.3.0)(@types/react@18.3.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
|
||||
'@radix-ui/react-use-controllable-state': 1.1.0(@types/react@18.3.3)(react@18.3.1)
|
||||
'@radix-ui/react-use-layout-effect': 1.1.0(@types/react@18.3.3)(react@18.3.1)
|
||||
'@radix-ui/react-use-previous': 1.1.0(@types/react@18.3.3)(react@18.3.1)
|
||||
'@radix-ui/react-use-size': 1.1.0(@types/react@18.3.3)(react@18.3.1)
|
||||
react: 18.3.1
|
||||
react-dom: 18.3.1(react@18.3.1)
|
||||
optionalDependencies:
|
||||
'@types/react': 18.3.3
|
||||
'@types/react-dom': 18.3.0
|
||||
|
||||
'@radix-ui/react-slot@1.0.2(@types/react@18.3.3)(react@18.3.1)':
|
||||
dependencies:
|
||||
'@babel/runtime': 7.24.4
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { createAtomHooks } from "@renderer/lib/jotai"
|
||||
import { getStorageNS } from "@renderer/lib/ns"
|
||||
import { atomWithStorage } from "jotai/utils"
|
||||
|
||||
type CornerPlayerAtomValue = {
|
||||
show: boolean
|
||||
type?: "audio"
|
||||
entryId?: string
|
||||
url?: string
|
||||
}
|
||||
|
||||
const cornerPlayerInitialValue: CornerPlayerAtomValue = {
|
||||
show: false,
|
||||
}
|
||||
|
||||
export const [
|
||||
cornerPlayerAtom,
|
||||
useCornerPlayerAtom,
|
||||
useCornerPlayerAtomValue,
|
||||
useSetCornerPlayerAtom,
|
||||
getCornerPlayerAtomValue,
|
||||
setCornerPlayerAtomValue,
|
||||
] = createAtomHooks<CornerPlayerAtomValue>(
|
||||
atomWithStorage(
|
||||
getStorageNS("corner-player"),
|
||||
cornerPlayerInitialValue,
|
||||
undefined,
|
||||
{ getOnInit: true },
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1,149 @@
|
||||
import { createAtomHooks } from "@renderer/lib/jotai"
|
||||
import { getStorageNS } from "@renderer/lib/ns"
|
||||
import { atomWithStorage } from "jotai/utils"
|
||||
|
||||
type PlayerAtomValue = {
|
||||
show: boolean
|
||||
type?: "audio"
|
||||
entryId?: string
|
||||
src?: string
|
||||
status?: "playing" | "paused" | "loading"
|
||||
duration?: number
|
||||
currentTime?: number
|
||||
isMute?: boolean
|
||||
volume?: number
|
||||
playbackRate?: number
|
||||
}
|
||||
|
||||
const playerInitialValue: PlayerAtomValue = {
|
||||
show: false,
|
||||
volume: 0.8,
|
||||
playbackRate: 1,
|
||||
}
|
||||
|
||||
export const [
|
||||
playerAtom,
|
||||
usePlayerAtom,
|
||||
usePlayerAtomValue,
|
||||
useSetPlayerAtom,
|
||||
getPlayerAtomValue,
|
||||
setPlayerAtomValue,
|
||||
] = createAtomHooks<PlayerAtomValue>(
|
||||
atomWithStorage(
|
||||
getStorageNS("player"),
|
||||
playerInitialValue,
|
||||
undefined,
|
||||
{ getOnInit: true },
|
||||
),
|
||||
)
|
||||
|
||||
export const Player = {
|
||||
audio: new Audio(),
|
||||
currentTimeTimer: null as NodeJS.Timeout | null,
|
||||
get() {
|
||||
return getPlayerAtomValue()
|
||||
},
|
||||
play(v: Omit<PlayerAtomValue, "show" | "status" | "playedSeconds">) {
|
||||
const curV = getPlayerAtomValue()
|
||||
if (!v.src || (curV.src === v.src && curV.status === "playing")) {
|
||||
return
|
||||
}
|
||||
|
||||
setPlayerAtomValue({
|
||||
...curV,
|
||||
...v,
|
||||
status: "loading",
|
||||
show: true,
|
||||
})
|
||||
|
||||
if (this.audio.src !== v.src) {
|
||||
this.audio.src = v.src
|
||||
this.audio.currentTime = v.currentTime ?? curV.currentTime ?? 0
|
||||
}
|
||||
this.audio.volume = curV.volume ?? 0.8
|
||||
this.audio.playbackRate = curV.playbackRate ?? 1
|
||||
|
||||
this.currentTimeTimer && clearInterval(this.currentTimeTimer)
|
||||
this.currentTimeTimer = setInterval(() => {
|
||||
setPlayerAtomValue({
|
||||
...getPlayerAtomValue(),
|
||||
currentTime: this.audio.currentTime,
|
||||
})
|
||||
}, 1000)
|
||||
|
||||
return this.audio.play().then(() => {
|
||||
setPlayerAtomValue({
|
||||
...getPlayerAtomValue(),
|
||||
status: "playing",
|
||||
})
|
||||
})
|
||||
},
|
||||
pause() {
|
||||
const curV = getPlayerAtomValue()
|
||||
if (curV.status === "paused") {
|
||||
return
|
||||
}
|
||||
|
||||
setPlayerAtomValue({
|
||||
...curV,
|
||||
status: "paused",
|
||||
currentTime: this.audio.currentTime,
|
||||
})
|
||||
|
||||
return this.audio.pause()
|
||||
},
|
||||
togglePlayAndPause() {
|
||||
const curV = getPlayerAtomValue()
|
||||
if (curV.status === "playing") {
|
||||
return this.pause()
|
||||
} else if (curV.status === "paused") {
|
||||
return this.play(curV)
|
||||
} else {
|
||||
return this.pause()
|
||||
}
|
||||
},
|
||||
close() {
|
||||
setPlayerAtomValue({
|
||||
show: false,
|
||||
currentTime: 0,
|
||||
})
|
||||
|
||||
this.currentTimeTimer && clearInterval(this.currentTimeTimer)
|
||||
|
||||
return this.audio.pause()
|
||||
},
|
||||
seek(time: number) {
|
||||
this.audio.currentTime = time
|
||||
setPlayerAtomValue({
|
||||
...getPlayerAtomValue(),
|
||||
currentTime: time,
|
||||
})
|
||||
},
|
||||
setPlaybackRate(speed: number) {
|
||||
this.audio.playbackRate = speed
|
||||
setPlayerAtomValue({
|
||||
...getPlayerAtomValue(),
|
||||
playbackRate: speed,
|
||||
})
|
||||
},
|
||||
back(time: number) {
|
||||
this.seek(Math.max(this.audio.currentTime - time, 0))
|
||||
},
|
||||
forward(time: number) {
|
||||
this.seek(Math.min(this.audio.currentTime + time, this.audio.duration))
|
||||
},
|
||||
toggleMute() {
|
||||
this.audio.muted = !this.audio.muted
|
||||
setPlayerAtomValue({
|
||||
...getPlayerAtomValue(),
|
||||
isMute: this.audio.muted,
|
||||
})
|
||||
},
|
||||
setVolume(volume: number) {
|
||||
this.audio.volume = volume
|
||||
setPlayerAtomValue({
|
||||
...getPlayerAtomValue(),
|
||||
volume,
|
||||
})
|
||||
},
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
../../hono.ts
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Player, usePlayerAtomValue } from "@renderer/atoms/player"
|
||||
import { FeedIcon } from "@renderer/components/feed-icon"
|
||||
import { RelativeTime } from "@renderer/components/ui/datetime"
|
||||
import { Media } from "@renderer/components/ui/media"
|
||||
@@ -8,6 +9,7 @@ import { cn } from "@renderer/lib/utils"
|
||||
import { EntryTranslation } from "@renderer/modules/entry-column/translation"
|
||||
import { useEntry } from "@renderer/store/entry/hooks"
|
||||
import { useFeedById } from "@renderer/store/feed"
|
||||
import { useState } from "react"
|
||||
|
||||
import { ReactVirtuosoItemPlaceholder } from "../../components/ui/placeholder"
|
||||
import { StarIcon } from "./star-icon"
|
||||
@@ -33,6 +35,8 @@ export function ListItem({
|
||||
|
||||
const feed = useFeedById(entry?.feedId) || entryPreview?.feeds
|
||||
|
||||
const [isHovered, setIsHovered] = useState(false)
|
||||
|
||||
// NOTE: prevent 0 height element, react virtuoso will not stop render any more
|
||||
if (!entry || !feed) return <ReactVirtuosoItemPlaceholder />
|
||||
|
||||
@@ -41,13 +45,15 @@ export function ListItem({
|
||||
entry.entries.publishedAt
|
||||
return (
|
||||
<div
|
||||
onMouseEnter={() => setIsHovered(true)}
|
||||
onMouseLeave={() => setIsHovered(false)}
|
||||
className={cn(
|
||||
"relative flex py-3 pl-3 pr-2",
|
||||
!asRead &&
|
||||
"before:absolute before:-left-0.5 before:top-[18px] before:block before:size-2 before:rounded-full before:bg-theme-accent",
|
||||
)}
|
||||
>
|
||||
<FeedIcon feed={feed} entry={entry.entries} />
|
||||
{!withAudio && <FeedIcon feed={feed} entry={entry.entries} />}
|
||||
<div className="-mt-0.5 line-clamp-4 flex-1 text-sm leading-tight">
|
||||
<div
|
||||
className={cn(
|
||||
@@ -99,14 +105,18 @@ export function ListItem({
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{withAudio && entry.entries?.attachments?.[0].url && (
|
||||
<audio
|
||||
className="mt-2 h-10 w-full"
|
||||
controls
|
||||
src={entry.entries?.attachments?.[0].url}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{withAudio && entry.entries?.attachments?.[0].url && (
|
||||
<AudioCover
|
||||
entryId={entryId}
|
||||
src={entry.entries?.attachments?.[0].url}
|
||||
durationInSeconds={Number.parseInt(String(entry.entries?.attachments?.[0].duration_in_seconds ?? 0), 10)}
|
||||
feedIcon={<FeedIcon feed={feed} entry={entry.entries} size={80} />}
|
||||
isHovered={isHovered}
|
||||
/>
|
||||
)}
|
||||
|
||||
{withDetails && entry.entries.media?.[0] && (
|
||||
<Media
|
||||
src={entry.entries.media[0].url}
|
||||
@@ -123,3 +133,71 @@ export function ListItem({
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function AudioCover({
|
||||
entryId,
|
||||
src,
|
||||
durationInSeconds,
|
||||
feedIcon,
|
||||
isHovered,
|
||||
}: {
|
||||
entryId: string
|
||||
src: string
|
||||
durationInSeconds?: number
|
||||
feedIcon: React.ReactNode
|
||||
isHovered: boolean
|
||||
}) {
|
||||
const playerValue = usePlayerAtomValue()
|
||||
|
||||
const isMeActive = playerValue.src === src
|
||||
const shouldShowPlayButton = isHovered || isMeActive
|
||||
|
||||
const estimatedMins = durationInSeconds ? Math.floor(durationInSeconds / 60) : undefined
|
||||
|
||||
const handleClickPlay = () => {
|
||||
if (!isMeActive) {
|
||||
// switch this to play
|
||||
Player.play({
|
||||
type: "audio",
|
||||
entryId,
|
||||
src,
|
||||
duration: durationInSeconds,
|
||||
currentTime: 0,
|
||||
})
|
||||
} else {
|
||||
// switch between play and pause
|
||||
Player.togglePlayAndPause()
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative ml-2 size-20 shrink-0">
|
||||
{feedIcon}
|
||||
|
||||
<div
|
||||
className={cn("center absolute inset-0 w-full transition-all duration-200 ease-in-out", shouldShowPlayButton ? "opacity-100" : "opacity-0")}
|
||||
onClick={handleClickPlay}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
className="center size-10 rounded-full bg-theme-background opacity-95 hover:bg-theme-accent hover:opacity-100"
|
||||
>
|
||||
<i
|
||||
className={cn("size-6", {
|
||||
"i-mingcute-pause-fill":
|
||||
isMeActive && playerValue.status === "playing",
|
||||
"i-mingcute-loading-fill animate-spin":
|
||||
isMeActive && playerValue.status === "loading",
|
||||
"i-mingcute-play-fill":
|
||||
!isMeActive || playerValue.status === "paused",
|
||||
})}
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="absolute bottom-0 w-full bg-theme-background text-center text-[13px] opacity-50">
|
||||
{estimatedMins ? `${estimatedMins} m` : "- m"}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
import * as Slider from "@radix-ui/react-slider"
|
||||
import { Player, usePlayerAtomValue } from "@renderer/atoms/player"
|
||||
import { FeedIcon } from "@renderer/components/feed-icon"
|
||||
import { softBouncePreset } from "@renderer/components/ui/constants/spring"
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@renderer/components/ui/tooltip"
|
||||
import { cn } from "@renderer/lib/utils"
|
||||
import { useEntry } from "@renderer/store/entry"
|
||||
import { useFeedById } from "@renderer/store/feed"
|
||||
import dayjs from "dayjs"
|
||||
import { AnimatePresence, m } from "framer-motion"
|
||||
import { useEffect, useState } from "react"
|
||||
import Marquee from "react-fast-marquee"
|
||||
|
||||
const handleClickPlay = () => {
|
||||
Player.togglePlayAndPause()
|
||||
}
|
||||
|
||||
export const CornerPlayer = () => {
|
||||
const playerValue = usePlayerAtomValue()
|
||||
const entry = useEntry(playerValue.entryId)
|
||||
const feed = useFeedById(entry?.feedId)
|
||||
|
||||
const { currentTime = 0, duration = 0 } = playerValue
|
||||
const [controlledCurrentTime, setControlledCurrentTime] = useState(currentTime)
|
||||
const [isDraggingProgress, setIsDraggingProgress] = useState(false)
|
||||
useEffect(() => {
|
||||
if (isDraggingProgress) return
|
||||
setControlledCurrentTime(currentTime)
|
||||
}, [currentTime, isDraggingProgress])
|
||||
|
||||
const currentTimeIndicator = dayjs().startOf("y").second(controlledCurrentTime).format("mm:ss")
|
||||
const remainingTimeIndicator = dayjs().startOf("y").second(duration - controlledCurrentTime).format("mm:ss")
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{playerValue.show && entry && feed && (
|
||||
<m.div
|
||||
className="group absolute inset-x-1 bottom-10"
|
||||
initial={{ y: 50, opacity: 0 }}
|
||||
animate={{ y: 0, opacity: 1 }}
|
||||
exit={{ y: 50, opacity: 0 }}
|
||||
transition={{ ...softBouncePreset, duration: 0.1 }}
|
||||
>
|
||||
{/* advanced controls */}
|
||||
<div className="flex translate-y-10 justify-between rounded-t-lg bg-theme-modal-background p-1 opacity-0 shadow backdrop-blur transition-all duration-200 ease-in-out group-hover:translate-y-0 group-hover:opacity-100">
|
||||
<div>
|
||||
<ActionIcon
|
||||
className="i-mingcute-close-fill"
|
||||
onClick={() => Player.close()}
|
||||
label="Close"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<ActionIcon
|
||||
className="i-mingcute-fast-forward-fill"
|
||||
label={<PlaybackRateSelector />}
|
||||
labelDelayDuration={0}
|
||||
/>
|
||||
<ActionIcon
|
||||
className={cn(
|
||||
playerValue.isMute ?
|
||||
"i-mingcute-volume-mute-fill text-red-500" :
|
||||
"i-mingcute-volume-fill",
|
||||
)}
|
||||
onClick={() => Player.toggleMute()}
|
||||
label={<VolumeSlider />}
|
||||
labelDelayDuration={0}
|
||||
/>
|
||||
<ActionIcon
|
||||
className="i-mingcute-back-2-fill"
|
||||
onClick={() => Player.back(10)}
|
||||
label="Back 10s"
|
||||
/>
|
||||
<ActionIcon
|
||||
className="i-mingcute-forward-2-fill"
|
||||
onClick={() => Player.forward(10)}
|
||||
label="Forward 10s"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex rounded-lg bg-theme-modal-background shadow backdrop-blur transition-all duration-200 ease-in-out hover:rounded-b-lg hover:rounded-t-none">
|
||||
{/* play cover */}
|
||||
<div className="relative">
|
||||
<FeedIcon
|
||||
feed={feed}
|
||||
entry={entry.entries}
|
||||
size={50}
|
||||
className="m-0"
|
||||
/>
|
||||
<div className="center absolute inset-0 w-full opacity-0 transition-all duration-200 ease-in-out group-hover:opacity-100">
|
||||
<button
|
||||
type="button"
|
||||
className="center size-10 rounded-full bg-theme-background opacity-95 hover:bg-theme-accent hover:opacity-100"
|
||||
onClick={handleClickPlay}
|
||||
>
|
||||
<i
|
||||
className={cn("size-6", {
|
||||
"i-mingcute-pause-fill": playerValue.status === "playing",
|
||||
"i-mingcute-loading-fill animate-spin":
|
||||
playerValue.status === "loading",
|
||||
"i-mingcute-play-fill": playerValue.status === "paused",
|
||||
})}
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="relative truncate text-center text-sm">
|
||||
<Marquee
|
||||
play={playerValue.status === "playing"}
|
||||
gradient
|
||||
gradientWidth={24}
|
||||
gradientColor="var(--fo-modal-background)"
|
||||
speed={30}
|
||||
>
|
||||
{entry.entries.title}
|
||||
</Marquee>
|
||||
<div className="text-xs text-muted-foreground">{feed.title}</div>
|
||||
|
||||
{/* progress control */}
|
||||
<div className="relative mt-2">
|
||||
<div className="absolute bottom-1 flex w-full items-center justify-between text-theme-disabled opacity-0 duration-200 ease-in-out group-hover:opacity-100">
|
||||
<div className="text-xs">{currentTimeIndicator}</div>
|
||||
<div className="text-xs">
|
||||
-
|
||||
{remainingTimeIndicator}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* slider */}
|
||||
<Slider.Root
|
||||
className="relative flex h-1 w-full items-center transition-all duration-200 ease-in-out"
|
||||
min={0}
|
||||
max={duration}
|
||||
step={1}
|
||||
value={[controlledCurrentTime]}
|
||||
onPointerDown={() => setIsDraggingProgress(true)}
|
||||
onPointerUp={() => setIsDraggingProgress(false)}
|
||||
onValueChange={(value) => setControlledCurrentTime(value[0])}
|
||||
onValueCommit={(value) => Player.seek(value[0])}
|
||||
>
|
||||
<Slider.Track className="relative h-1 w-full grow bg-muted group-hover:bg-theme-disabled">
|
||||
<Slider.Range className="absolute h-1 rounded-md bg-theme-accent" />
|
||||
</Slider.Track>
|
||||
|
||||
{/* indicator */}
|
||||
<Slider.Thumb
|
||||
className="block h-2 w-1 rounded-sm bg-theme-accent"
|
||||
aria-label="Progress"
|
||||
/>
|
||||
</Slider.Root>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</m.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
)
|
||||
}
|
||||
|
||||
const ActionIcon = ({
|
||||
className,
|
||||
onClick,
|
||||
label,
|
||||
labelDelayDuration = 700,
|
||||
}: {
|
||||
className?: string
|
||||
onClick?: () => void
|
||||
label: React.ReactNode
|
||||
labelDelayDuration?: number
|
||||
}) => (
|
||||
<Tooltip delayDuration={labelDelayDuration}>
|
||||
<TooltipTrigger>
|
||||
<button
|
||||
type="button"
|
||||
className="center size-6 rounded-md text-zinc-500 hover:bg-theme-item-hover"
|
||||
onClick={onClick}
|
||||
>
|
||||
<i className={className} />
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{label}</TooltipContent>
|
||||
</Tooltip>
|
||||
)
|
||||
|
||||
const VolumeSlider = () => {
|
||||
const playerValue = usePlayerAtomValue()
|
||||
|
||||
return (
|
||||
<Slider.Root
|
||||
className="relative flex h-10 w-1 flex-col items-center p-1"
|
||||
max={1}
|
||||
step={0.01}
|
||||
orientation="vertical"
|
||||
value={[playerValue.volume ?? 0.8]}
|
||||
onValueChange={(value) => Player.setVolume(value[0])}
|
||||
>
|
||||
<Slider.Track className="relative w-1 grow bg-zinc-500">
|
||||
<Slider.Range className="absolute w-full bg-black dark:bg-white" />
|
||||
</Slider.Track>
|
||||
<Slider.Thumb
|
||||
className="block bg-black dark:bg-white"
|
||||
aria-label="Volume"
|
||||
/>
|
||||
</Slider.Root>
|
||||
)
|
||||
}
|
||||
|
||||
const PlaybackRateSelector = () => {
|
||||
const playerValue = usePlayerAtomValue()
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center">
|
||||
{[0.5, 0.75, 1, 1.25, 1.5, 2].map((rate) => (
|
||||
<button
|
||||
key={rate}
|
||||
type="button"
|
||||
className={cn(
|
||||
"center rounded-md font-mono hover:bg-theme-item-hover",
|
||||
playerValue.playbackRate === rate && "bg-theme-item-hover text-black dark:text-white",
|
||||
playerValue.playbackRate !== rate && "text-zinc-500",
|
||||
)}
|
||||
onClick={() => Player.setPlaybackRate(rate)}
|
||||
>
|
||||
{rate.toFixed(2)}
|
||||
x
|
||||
</button>
|
||||
))}
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import { NetworkStatusIndicator } from "@renderer/modules/app/NetworkStatusIndic
|
||||
import { LoginModalContent } from "@renderer/modules/auth/LoginModalContent"
|
||||
import { FeedColumn } from "@renderer/modules/feed-column"
|
||||
import { AutoUpdater } from "@renderer/modules/feed-column/auto-updater"
|
||||
import { CornerPlayer } from "@renderer/modules/feed-column/corner-player"
|
||||
import { SearchCmdK } from "@renderer/modules/search/cmdk"
|
||||
import type { PropsWithChildren } from "react"
|
||||
import { useRef } from "react"
|
||||
@@ -33,6 +34,9 @@ export function Component() {
|
||||
>
|
||||
<FeedResponsiveResizerContainer containerRef={containerRef}>
|
||||
<FeedColumn>
|
||||
|
||||
<CornerPlayer />
|
||||
|
||||
{APP_VERSION?.[0] === "0" && (
|
||||
<div className="pointer-events-none absolute bottom-3 w-full text-center text-xs opacity-20">
|
||||
Early Access
|
||||
@@ -42,6 +46,7 @@ export function Component() {
|
||||
""}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{ELECTRON && <AutoUpdater />}
|
||||
|
||||
<NetworkStatusIndicator />
|
||||
|
||||