generated from railmapgen/seed-project
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#491 Implement new card-based grid for displaying templates
- Loading branch information
Showing
3 changed files
with
63 additions
and
78 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,62 @@ | ||
import { useRootSelector } from '../../redux'; | ||
import useTemplates from '../hooks/use-templates'; | ||
import { Avatar, Flex, Heading, SimpleGrid, SystemStyleObject, Tag, TagLabel, Text } from '@chakra-ui/react'; | ||
import { RmgCard } from '@railmapgen/rmg-components'; | ||
import useTranslatedName from '../hooks/use-translated-name'; | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
const cardStyles: SystemStyleObject = { | ||
flexDirection: 'column', | ||
p: 2, | ||
|
||
'& h2': { | ||
mb: 2, | ||
}, | ||
}; | ||
|
||
export default function TemplatesGrid() { | ||
const { t } = useTranslation(); | ||
const translateName = useTranslatedName(); | ||
|
||
const { selectedCompany } = useRootSelector(state => state.app); | ||
const { templates } = useTemplates(selectedCompany); | ||
|
||
if (!templates.length) { | ||
return ( | ||
<Flex h="100%" w="100%" alignItems="center" justifyContent="center"> | ||
<Text as="i">No templates available in selected company.</Text> | ||
</Flex> | ||
); | ||
} | ||
|
||
return ( | ||
<SimpleGrid minChildWidth={220} spacing={2} maxH="100%" overflowY="scroll"> | ||
{templates.map(template => ( | ||
<RmgCard key={template.filename} sx={cardStyles}> | ||
<Heading as="h2" size="md"> | ||
{translateName(template.name)} | ||
</Heading> | ||
<Text fontSize="sm"> | ||
{t('Uploader')} | ||
{': '} | ||
<Tag | ||
size="sm" | ||
borderRadius="full" | ||
onClick={() => | ||
window.open( | ||
`https://github.com/railmapgen/rmg-templates/issues?q=is:issue+author:${template.uploadBy}`, | ||
'_blank' | ||
) | ||
} | ||
cursor="pointer" | ||
> | ||
<Avatar src={`https://github.com/${template.uploadBy}.png`} size="xs" ml={-1} mr={2} /> | ||
<TagLabel>{template.uploadBy}</TagLabel> | ||
</Tag> | ||
</Text> | ||
</RmgCard> | ||
))} | ||
</SimpleGrid> | ||
); | ||
} |
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