-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor home page into a modal on the navbar (#403)
* feat: add row component * feat: add collections to nav * feat: set home page directly to active line
- Loading branch information
Showing
7 changed files
with
145 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { ChevronRight } from 'lucide-react' | ||
import { ReactNode } from 'react' | ||
import { createUseStyles } from 'react-jss' | ||
import { Link } from 'react-router-dom' | ||
|
||
import theme from '../helpers/theme' | ||
|
||
const useStyles = createUseStyles( { | ||
row: { | ||
textDecoration: 'none', | ||
color: theme.Fg, | ||
boxSizing: 'border-box', | ||
width: '100%', | ||
minHeight: '3rem', | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
'&:hover': { | ||
color: theme.Blue, | ||
}, | ||
'& + $row': { | ||
borderTop: [ '1px', 'solid', theme.Separator ], | ||
}, | ||
'& > div': { | ||
display: 'flex', | ||
alignItems: 'center', | ||
|
||
}, | ||
}, | ||
disabled: { | ||
cursor: 'default', | ||
color: 'rgba(120, 120, 120, 0.4)', | ||
'&:hover': { | ||
color: 'rgba(120, 120, 120, 0.4)', | ||
}, | ||
}, | ||
'@media (prefers-color-scheme: dark)': { | ||
row: { | ||
color: theme.FgDarkScheme, | ||
'&:hover': { | ||
color: theme.BlueDarkScheme, | ||
}, | ||
'& + $row': { | ||
borderTopColor: theme.SeparatorDarkScheme, | ||
}, | ||
}, | ||
}, | ||
} ) | ||
|
||
type RowProps = { | ||
to?: string, | ||
children: ReactNode, | ||
onClick?: React.MouseEventHandler<HTMLAnchorElement>, | ||
disabled?: boolean, | ||
} | ||
|
||
const Row = ( { to, disabled, onClick, children }: RowProps ) => { | ||
const classes = useStyles() | ||
return ( | ||
<Link | ||
to={( to && !disabled ) ? to : '#'} | ||
className={`${classes.row} ${disabled ? classes.disabled : ''}`} | ||
onClick={( onClick && !disabled ) ? onClick : ( () => null )} | ||
> | ||
<div>{children}</div> | ||
{to && <div><ChevronRight /></div>} | ||
</Link> | ||
) | ||
} | ||
|
||
export default Row |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Dispatch, SetStateAction, useEffect, useState } from 'react' | ||
|
||
import AsciiGurmukhi from '../components/AsciiGurmukhi' | ||
import Content from '../components/Content' | ||
import Row from '../components/Row' | ||
import Section from '../components/Section' | ||
import { SOURCES_API } from '../lib/consts' | ||
import { SourcesResponse } from '../types/api' | ||
|
||
type CollectionsProps = { | ||
setVisibleCollections: Dispatch<SetStateAction<boolean>>, | ||
} | ||
|
||
const Collections = ( { setVisibleCollections }: CollectionsProps ) => { | ||
const [ sources, setSources ] = useState<SourcesResponse>( [] ) | ||
|
||
useEffect( () => { | ||
fetch( SOURCES_API ) | ||
.then( ( res ) => res.json() ) | ||
.then( setSources ) | ||
.catch( ( err: Error ) => console.error( 'Error fetching Sources', err ) ) | ||
}, [] ) | ||
|
||
const orderId = { 1: 0, 2: 1, 11: 3, 3: 4, 4: 5, 7: 6, 6: 7, 5: 8, 8: 9, 9: 10, 10: 11 } | ||
|
||
return ( | ||
<Content> | ||
<Section> | ||
<h1>Collections</h1> | ||
|
||
{sources | ||
.sort( ( a, b ) => orderId[ a.id ] - orderId[ b.id ] ) | ||
.map( ( { id, nameGurmukhi } ) => ( | ||
<Row | ||
key={id} | ||
to={`/sources/${id}/page/1/line/1`} | ||
onClick={() => setVisibleCollections( false )} | ||
> | ||
<AsciiGurmukhi>{nameGurmukhi}</AsciiGurmukhi> | ||
</Row> | ||
) )} | ||
</Section> | ||
</Content> | ||
) | ||
} | ||
|
||
export default Collections |
This file was deleted.
Oops, something went wrong.