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 { mode, toggle: toggleViewMode } = useStreamViewMode(
|
||||
streamParticle,
|
||||
userId,
|
||||
);
|
||||
const { mode, toggle: toggleViewMode } = useStreamViewMode();
|
||||
|
||||
const {
|
||||
children,
|
||||
|
||||
@@ -1,24 +1,11 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import type { Particle } from '@/api/types';
|
||||
|
||||
export type StreamViewMode = 'player' | 'list';
|
||||
|
||||
// Deprecated: now we always start with player mode
|
||||
function decideMode(
|
||||
streamParticle: Particle & { type: 'stream' },
|
||||
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 } {
|
||||
export function useStreamViewMode(): {
|
||||
mode: StreamViewMode;
|
||||
toggle: () => void;
|
||||
} {
|
||||
const [mode, setMode] = useState<StreamViewMode>('player');
|
||||
const toggle = useCallback(() => {
|
||||
setMode((prev) => (prev === 'player' ? 'list' : 'player'));
|
||||
|
||||
Reference in New Issue
Block a user