fix: check new error when feedId array only one and add player tracker

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-07-28 18:11:40 +08:00
parent ebf2a47061
commit 2ef980675c
2 changed files with 59 additions and 13 deletions
@@ -1,5 +1,6 @@
import * as Slider from "@radix-ui/react-slider"
import {
getPlayerAtomValue,
Player,
usePlayerAtomSelector,
usePlayerAtomValue,
@@ -47,12 +48,47 @@ export const CornerPlayer = () => {
</AnimatePresence>
)
}
const usePlayerTracker = () => {
const playerOpenAt = useState(Date.now)[0]
const show = usePlayerAtomSelector((v) => v.show)
useEffect(() => {
const handler = () => {
const playerState = getPlayerAtomValue()
window.posthog?.capture(
"player_open_duration",
{
duration: Date.now() - playerOpenAt,
status: playerState.status,
trigger: "beforeunload",
},
{ transport: "sendBeacon" },
)
}
window.addEventListener("beforeunload", handler)
return () => window.removeEventListener("beforeunload", handler)
}, [])
useEffect(() => {
if (!show) {
const playerState = getPlayerAtomValue()
window.posthog?.capture("player_open_duration", {
duration: Date.now() - playerOpenAt,
status: playerState.status,
trigger: "manual",
})
}
}, [show])
}
const CornerPlayerImpl = () => {
const entryId = usePlayerAtomSelector((v) => v.entryId)
const status = usePlayerAtomSelector((v) => v.status)
const isMute = usePlayerAtomSelector((v) => v.isMute)
const playerValue = { entryId, status, isMute }
const entry = useEntry(playerValue.entryId)
const feed = useFeedById(entry?.feedId)
@@ -62,6 +98,7 @@ const CornerPlayerImpl = () => {
})
const navigateToEntry = useNavigateEntry()
usePlayerTracker()
if (!entry || !feed) return null
@@ -243,7 +280,9 @@ const ActionIcon = ({
{children || <i className={className} />}
</button>
</TooltipTrigger>
<TooltipContent className="bg-theme-modal-background">{label}</TooltipContent>
<TooltipContent className="bg-theme-modal-background">
{label}
</TooltipContent>
</Tooltip>
)
+18 -11
View File
@@ -64,18 +64,25 @@ export const entries = {
}) =>
defineQuery(
["entry-checkNew", id, view, read, fetchedTime],
async () =>
async () => {
const query = {
...getEntriesParams({
id,
view,
}),
read,
insertedAfter: fetchedTime,
}
if (query.feedIdList && query.feedIdList.length === 1) {
query.feedId = query.feedIdList[0]
delete query.feedIdList
}
// @ts-expect-error
apiClient.entries["check-new"].$get({
query: {
...getEntriesParams({
id,
view,
}),
read,
insertedAfter: fetchedTime,
},
}) as Promise<{ data: { has_new: boolean, lastest_at?: string } }>,
return apiClient.entries["check-new"].$get({
query,
}) as Promise<{ data: { has_new: boolean, lastest_at?: string } }>
},
{
rootKey: ["entry-checkNew", id],