cleanup unnecessary logic and complexity
This commit is contained in:
@@ -213,10 +213,7 @@ function StreamViewInner({ path, streamParticle }: StreamViewProps) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const userId = useAuthStore((s) => s.user?.id);
|
const userId = useAuthStore((s) => s.user?.id);
|
||||||
const { mode, toggle: toggleViewMode } = useStreamViewMode(
|
const { mode, toggle: toggleViewMode } = useStreamViewMode();
|
||||||
streamParticle,
|
|
||||||
userId,
|
|
||||||
);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
children,
|
children,
|
||||||
|
|||||||
@@ -1,24 +1,11 @@
|
|||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import type { Particle } from '@/api/types';
|
|
||||||
|
|
||||||
export type StreamViewMode = 'player' | 'list';
|
export type StreamViewMode = 'player' | 'list';
|
||||||
|
|
||||||
// Deprecated: now we always start with player mode
|
export function useStreamViewMode(): {
|
||||||
function decideMode(
|
mode: StreamViewMode;
|
||||||
streamParticle: Particle & { type: 'stream' },
|
toggle: () => void;
|
||||||
userId: string | undefined,
|
} {
|
||||||
): StreamViewMode {
|
|
||||||
const marker = userId ? streamParticle.playback_markers?.[userId] : undefined;
|
|
||||||
const lastChildAt = streamParticle.last_child_created_at;
|
|
||||||
const caughtUp =
|
|
||||||
!!marker && !!lastChildAt && lastChildAt.getTime() <= marker.getTime();
|
|
||||||
return caughtUp ? 'list' : 'player';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useStreamViewMode(
|
|
||||||
streamParticle: Particle & { type: 'stream' },
|
|
||||||
userId: string | undefined,
|
|
||||||
): { mode: StreamViewMode; toggle: () => void } {
|
|
||||||
const [mode, setMode] = useState<StreamViewMode>('player');
|
const [mode, setMode] = useState<StreamViewMode>('player');
|
||||||
const toggle = useCallback(() => {
|
const toggle = useCallback(() => {
|
||||||
setMode((prev) => (prev === 'player' ? 'list' : 'player'));
|
setMode((prev) => (prev === 'player' ? 'list' : 'player'));
|
||||||
|
|||||||
Reference in New Issue
Block a user