Skip to content

Commit

Permalink
fix: check new error when feedId array only one and add player tracker
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jul 28, 2024
1 parent ebf2a47 commit 2ef9806
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 13 deletions.
43 changes: 41 additions & 2 deletions src/renderer/src/modules/feed-column/corner-player.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Slider from "@radix-ui/react-slider"
import {
getPlayerAtomValue,
Player,
usePlayerAtomSelector,
usePlayerAtomValue,
Expand Down Expand Up @@ -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)

Expand All @@ -62,6 +98,7 @@ const CornerPlayerImpl = () => {
})

const navigateToEntry = useNavigateEntry()
usePlayerTracker()

if (!entry || !feed) return null

Expand Down Expand Up @@ -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>
)

Expand Down
29 changes: 18 additions & 11 deletions src/renderer/src/queries/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 2ef9806

Please sign in to comment.