Skip to content

Commit

Permalink
feat: scroll to line in search result
Browse files Browse the repository at this point in the history
Related #286
  • Loading branch information
Harjot1Singh committed Apr 22, 2024
1 parent 1137620 commit 7f08a7d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/app/(tabs)/content/(content)/[type]/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLocalSearchParams } from 'expo-router'
import { SearchParams, useLocalSearchParams } from 'expo-router'
import { Suspense } from 'react'

import ContentTemplate from '~/components/templates/Content'
Expand All @@ -9,11 +9,15 @@ export default () => {
const {
id,
type,
} = useLocalSearchParams<'/(tabs)/content/(content)/[type]/[id]'>()
lineId,
} = useLocalSearchParams<
SearchParams<'/(tabs)/content/(content)/[type]/[id]'>
& Partial<{ lineId: string }>
>()

return (
<Suspense fallback={<DefaultFallback />}>
<ContentTemplate id={id} type={type as ContentType} />
<ContentTemplate id={id} type={type as ContentType} lineId={lineId} />
</Suspense>
)
}
6 changes: 4 additions & 2 deletions src/components/templates/Content/Lines/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useLocalSearchParams } from 'expo-router'
import { ComponentType } from 'react'

import { settings, useSetting } from '~/services/settings'
Expand All @@ -12,11 +13,12 @@ type LinesProps = {
}

const Lines = ( { lines, Header }: LinesProps ) => {
const { lineId } = useLocalSearchParams<{ lineId?: string }>()
const [ isReaderMode ] = useSetting( settings.readerMode )

return isReaderMode
? <ReaderLines lines={lines} Header={Header} />
: <GroupedLines lines={lines} Header={Header} />
? <ReaderLines lines={lines} Header={Header} initialLineId={lineId} />
: <GroupedLines lines={lines} Header={Header} initialLineId={lineId} />
}

export default Lines
9 changes: 7 additions & 2 deletions src/components/templates/Content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ComponentType } from 'react'
import { ComponentType, useEffect } from 'react'

import Empty from '~/components/atoms/Empty'
import { useLastViewed } from '~/services/history/last-viewed'

Check failure on line 4 in src/components/templates/Content/index.tsx

View workflow job for this annotation

GitHub Actions / checks / checks (types)

Cannot find module '~/services/history/last-viewed' or its corresponding type declarations.
import { ContentType } from '~/types/data'

import Bani from './Bani'
Expand All @@ -16,9 +17,13 @@ const templates = {
type ContentTemplateProps = {
id: string,
type: ContentType,
lineId?: string,
}

const ContentTemplate = ( { id, type }: ContentTemplateProps ) => {
const ContentTemplate = ( { id, type, lineId }: ContentTemplateProps ) => {
const [ , setLastViewed ] = useLastViewed()
useEffect( () => { setLastViewed( { type, id, lineId } ) }, [ setLastViewed, id, type, lineId ] )

const Template = templates[ type ]

return <Template id={id} />
Expand Down
4 changes: 2 additions & 2 deletions src/components/templates/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const SearchTemplate = () => {
} )
}, [ navigation ] )

const openShabad: ResultsProps['onPress'] = ( { shabad: { id } } ) => router.navigate(
`/content/shabad/${id}`,
const openShabad: ResultsProps['onPress'] = ( { shabad: { id }, line } ) => router.navigate(
`/content/shabad/${id}?lineId=${line.id}`,
)

return (
Expand Down

0 comments on commit 7f08a7d

Please sign in to comment.