Skip to content

Commit

Permalink
make config more strict by adding no unchecked index access to tsconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
HaukeSchnau committed Nov 7, 2023
1 parent 2fc8772 commit a43b41b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/components/Image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const StoryImage: FC<StoryImageProps> = ( {
onImageLayout, onLoad,
} ) => {

const [ data, setData ] = useState<{ uri: string, isVideo?: boolean }>(
const [ data, setData ] = useState<{ uri: string | undefined, isVideo?: boolean }>(
{ uri: defaultImage, isVideo: isDefaultVideo },
);

Expand Down
6 changes: 6 additions & 0 deletions src/components/InstagramStories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ const InstagramStories = forwardRef<InstagramStoriesPublicMethods, InstagramStor
);
const seenStory = story.stories[seenStoryIndex + 1] || story.stories[0];

if ( !seenStory ) {

return true;

}

return seenStory.mediaType !== 'video' ? Image.prefetch( seenStory.sourceUrl ) : true;

} );
Expand Down
4 changes: 2 additions & 2 deletions src/components/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ const StoryList: FC<StoryListProps> = ( {
<StoryImage
stories={stories}
activeStory={activeStory}
defaultImage={stories[lastSeenIndex + 1]?.sourceUrl ?? stories[0].sourceUrl}
isDefaultVideo={( stories[lastSeenIndex + 1]?.mediaType ?? stories[0].mediaType ) === 'video'}
defaultImage={stories[lastSeenIndex + 1]?.sourceUrl ?? stories[0]?.sourceUrl}
isDefaultVideo={( stories[lastSeenIndex + 1]?.mediaType ?? stories[0]?.mediaType ) === 'video'}
onImageLayout={onImageLayout}
onLoad={onImageLoad}
paused={paused}
Expand Down
36 changes: 25 additions & 11 deletions src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ const StoryModal = forwardRef<StoryModalPublicMethods, StoryModalProps>( ( {
const userId = useDerivedValue( () => stories[userIndex.value]?.id );
const previousUserId = useDerivedValue( () => stories[userIndex.value - 1]?.id );
const nextUserId = useDerivedValue( () => stories[userIndex.value + 1]?.id );
const previousStory = useDerivedValue(
() => stories[userIndex.value]?.stories[storyIndex.value - 1]?.id,
);
const nextStory = useDerivedValue(
() => stories[userIndex.value]?.stories[storyIndex.value + 1]?.id,
);
const previousStory = useDerivedValue( () => ( storyIndex.value !== undefined
? stories[userIndex.value]?.stories[storyIndex.value - 1]?.id
: undefined ) );
const nextStory = useDerivedValue( () => ( storyIndex.value !== undefined
? stories[userIndex.value]?.stories[storyIndex.value + 1]?.id
: undefined ) );

const animatedStyles = useAnimatedStyle( () => ( { top: y.value } ) );
const backgroundAnimatedStyles = useAnimatedStyle( () => ( {
Expand Down Expand Up @@ -91,7 +91,12 @@ const StoryModal = forwardRef<StoryModalPublicMethods, StoryModalProps>( ( {
} else {

animation.value = 0;
runOnJS( onSeenStoriesChange )( userId.value, currentStory.value );

if ( userId.value !== undefined && currentStory.value !== undefined ) {

runOnJS( onSeenStoriesChange )( userId.value, currentStory.value );

}

}

Expand All @@ -111,7 +116,8 @@ const StoryModal = forwardRef<StoryModalPublicMethods, StoryModalProps>( ( {
( story ) => story.id === seenStories.value[id],
);
const userStories = stories[newUserIndex]?.stories;
currentStory.value = userStories[newStoryIndex + 1]?.id ?? userStories[0]?.id;
currentStory.value = newStoryIndex !== undefined
? userStories?.[newStoryIndex + 1]?.id ?? userStories?.[0]?.id : undefined;

};

Expand Down Expand Up @@ -236,7 +242,11 @@ const StoryModal = forwardRef<StoryModalPublicMethods, StoryModalProps>( ( {
}

const newUserId = stories[Math.round( newX / WIDTH )]?.id;
scrollTo( newUserId );
if ( newUserId !== undefined ) {

scrollTo( newUserId );

}

} else if ( ctx.pressedAt + LONG_PRESS_DURATION < Date.now() ) {

Expand Down Expand Up @@ -266,12 +276,16 @@ const StoryModal = forwardRef<StoryModalPublicMethods, StoryModalProps>( ( {

if ( visible ) {

onShow?.( currentStory.value );
if ( currentStory.value !== undefined ) {

onShow?.( currentStory.value );

}
onLoad?.();

y.value = withTiming( 0, ANIMATION_CONFIG );

} else {
} else if ( currentStory.value !== undefined ) {

onHide?.( currentStory.value );

Expand Down
10 changes: 5 additions & 5 deletions src/core/dto/componentsDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export interface AnimationProps {

export interface StoryImageProps {
stories: InstagramStoryProps['stories'];
activeStory: SharedValue<string>;
defaultImage: string;
activeStory: SharedValue<string | undefined>;
defaultImage: string | undefined;
isDefaultVideo: boolean;
paused: SharedValue<boolean>;
videoProps?: any;
Expand Down Expand Up @@ -97,14 +97,14 @@ export interface IconProps {
export interface StoryContentProps {
stories: InstagramStoryProps['stories'];
active: SharedValue<boolean>;
activeStory: SharedValue<string>;
activeStory: SharedValue<string | undefined>;
}

export interface StoryListProps extends InstagramStoryProps, StoryHeaderProps {
index: number;
x: SharedValue<number>;
activeUser: SharedValue<string>;
activeStory: SharedValue<string>;
activeUser: SharedValue<string | undefined>;
activeStory: SharedValue<string | undefined>;
progress: SharedValue<number>;
seenStories: SharedValue<ProgressStorageProps>;
paused: SharedValue<boolean>;
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"skipLibCheck": false,
"resolveJsonModule": true
"resolveJsonModule": true,
"noUncheckedIndexedAccess": true
},
"include": [
"src/**/*.ts",
Expand All @@ -41,4 +42,4 @@
"jest.config.js",
"commitlint.config.js",
]
}
}

0 comments on commit a43b41b

Please sign in to comment.