Skip to content

Commit

Permalink
✨ Enhance ClipContext and related components with input focus management
Browse files Browse the repository at this point in the history
- Added `isInputFocused` state and corresponding setter to `ClipContext` for managing input focus across components.
- Updated `KeyboardShortcuts` to prevent key actions when input is focused.
- Integrated focus management in `SessionSidebar` and `ExtractHighlightsForm` components to track input focus state.
- Improved user experience by ensuring keyboard shortcuts do not interfere with user input.
  • Loading branch information
pblvrt committed Jan 23, 2025
1 parent 3d789b3 commit 702a950
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const ClipProvider = ({
null
);

const [isInputFocused, setIsInputFocused] = useState<boolean>(false);

return (
<ClipContext.Provider
value={{
Expand All @@ -52,6 +54,8 @@ export const ClipProvider = ({
organizationId,
playbackStatus,
setPlaybackStatus,
isInputFocused,
setIsInputFocused,
}}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ const KeyboardShortcuts = ({
playbackRate: number;
currentPlaybackRateIndex: number;
}) => {
const { videoRef, isCreatingClip } = useClipContext();
const { videoRef, isCreatingClip, isInputFocused } = useClipContext();
const { isAddingOrEditingMarker } = useMarkersContext();
const { setStartTime, setEndTime, startTime, endTime } =
useTrimmControlsContext();
const { videoDuration } = useTimelineContext();
const isCreatingClipOrMarker = isCreatingClip || isAddingOrEditingMarker;

const { currentTime, handleSetCurrentTime } = usePlayer(videoRef);

const handleKeyDown = (event: KeyboardEvent) => {
if (isCreatingClipOrMarker) return;
if (isAddingOrEditingMarker || isCreatingClip || isInputFocused) return;
if (!videoRef.current) return;

switch (event.key) {
Expand Down Expand Up @@ -115,7 +114,7 @@ const KeyboardShortcuts = ({
return () => {
window.removeEventListener('keydown', handleKeyDown);
};
}, [currentTime, startTime, endTime, videoRef]);
}, [currentTime, startTime, endTime, videoRef, isCreatingClip, isAddingOrEditingMarker, isInputFocused]);

return (
<HoverCard>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Input } from '@/components/ui/input';
import Clip from './Clip';
import { useClipsSidebar } from './ClipsContext';
import { Skeleton } from '@/components/ui/skeleton';
import { useClipContext } from '../../ClipContext';

const SessionSidebar = () => {
const {
Expand All @@ -23,6 +24,8 @@ const SessionSidebar = () => {
uniqueDates,
isLoading,
} = useClipsSidebar();

const { setIsInputFocused } = useClipContext();

return (
<div className="h-full w-full flex flex-col">
Expand Down Expand Up @@ -52,6 +55,8 @@ const SessionSidebar = () => {
</Select>
<Input
placeholder="Search"
onFocus={() => setIsInputFocused(true)}
onBlur={() => setIsInputFocused(false)}
onChange={(e) => setSearchTerm(e.target.value)}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useRouter } from 'next/navigation';
import { fetchSession } from '@/lib/services/sessionService';
import { fetchMarkers } from '@/lib/services/markerSevice';
import { useMarkersContext } from './markersContext';
import { useClipContext } from '../../ClipContext';
const PRESET_PROMPTS = [
'Extract all talk and panels from this video',
'Extract key moments for short form content',
Expand All @@ -27,6 +28,7 @@ export const ExtractHighlightsForm = ({
transcribeStatus: TranscriptionStatus | null;
aiAnalysisStatus: ProcessingStatus | null;
}) => {
const { setIsInputFocused } = useClipContext();
const { fetchAndSetMarkers } = useMarkersContext();
const [prompt, setPrompt] = useState('');
const [isExtracting, setIsExtracting] = useState(false);
Expand Down Expand Up @@ -113,6 +115,8 @@ export const ExtractHighlightsForm = ({
))}
</div>
<Textarea
onFocus={() => setIsInputFocused(true)}
onBlur={() => setIsInputFocused(false)}
placeholder="Prompt for highlights"
value={prompt}
onChange={(e) => setPrompt(e.target.value)}
Expand Down
2 changes: 2 additions & 0 deletions packages/app/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,6 @@ export type ClipContextType = {
organizationId: string;
playbackStatus: PlaybackStatus | null;
setPlaybackStatus: React.Dispatch<React.SetStateAction<PlaybackStatus | null>>;
isInputFocused: boolean;
setIsInputFocused: React.Dispatch<React.SetStateAction<boolean>>;
};

0 comments on commit 702a950

Please sign in to comment.