1 | | - | /* eslint-disable react/button-has-type */ |
2 | | - | import React, { useCallback } from 'react'; |
3 | | - | import clsx from 'clsx'; |
4 | | - | import { SubmitHandler, useForm } from 'react-hook-form'; |
5 | | - | import { Button, Header, Section, TextInput, Wrapper } from 'components/ui'; |
6 | | - | import styles from './Home.module.scss'; |
| 1 | + | import React from 'react'; |
| 2 | + | import { CardProps } from '../../ui/Card/Card'; |
| 3 | + | import Hero from '../../ui/Hero/Hero'; |
| 4 | + | import Container from 'components/ui/Container/Container'; |
| 5 | + | import CardList from '../../ui/CardList/CardList'; |
| 6 | + | import CardGroups from '../../ui/CardGroups/CardGroups'; |
| 7 | + | import Footer from '../../ui/Footer/Footer'; |
| 8 | + | import CardGroup from '../../ui/CardGroup/CardGroup'; |
7 | 9 | | |
8 | | - | type FormData = { |
9 | | - | address: string; |
| 10 | + | type Props = { |
| 11 | + | suggestions: string[]; |
10 | 12 | | }; |
11 | 13 | | |
12 | | - | export type Props = { |
13 | | - | onSubmit: SubmitHandler<FormData>; |
14 | | - | isLoading?: boolean; |
15 | | - | }; |
| 14 | + | export default function Home({ suggestions }: Props) { |
| 15 | + | // TODO: mock data, remove later |
| 16 | + | const popularCards: CardProps[] = [ |
| 17 | + | { |
| 18 | + | id: 'uExBVGuF', |
| 19 | + | title: 'github.com', |
| 20 | + | icon: 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 21 | + | packageTags: { |
| 22 | + | featuredPackages: ['mdast-util-from-markdown', 'react', 'react-dom'], |
| 23 | + | restPackages: 45, |
| 24 | + | }, |
| 25 | + | }, |
| 26 | + | { |
| 27 | + | id: '1EkL1u5g', |
| 28 | + | title: 'fingerprint.com', |
| 29 | + | icon: 'https://avatars.githubusercontent.com/u/67208791?s=200&v=4', |
| 30 | + | packageTags: { |
| 31 | + | featuredPackages: ['mdast-util-from-markdown', 'react', 'react-dom'], |
| 32 | + | restPackages: 45, |
| 33 | + | }, |
| 34 | + | }, |
| 35 | + | { |
| 36 | + | id: 'mhwO2bPM', |
| 37 | + | title: 'facebook.com', |
| 38 | + | icon: 'https://avatars.githubusercontent.com/u/69631?s=200&v=4', |
| 39 | + | packageTags: { |
| 40 | + | featuredPackages: ['react'], |
| 41 | + | restPackages: 45, |
| 42 | + | }, |
| 43 | + | }, |
| 44 | + | ]; |
16 | 45 | | |
17 | | - | export default function Home({ onSubmit, isLoading }: Props) { |
18 | | - | const { |
19 | | - | register, |
20 | | - | handleSubmit, |
21 | | - | formState: { errors }, |
22 | | - | setError, |
23 | | - | } = useForm<FormData>(); |
| 46 | + | // TODO: mock data, remove later |
| 47 | + | const popularPackages: CardProps[] = [ |
| 48 | + | { |
| 49 | + | id: 'FPsBcl8R', |
| 50 | + | title: '@team-griffin/react-heading-section', |
| 51 | + | description: "This package's job is to automatically determine...", |
| 52 | + | featuredSites: { |
| 53 | + | iconList: [ |
| 54 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 55 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 56 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 57 | + | ], |
| 58 | + | numberOfUses: 5265, |
| 59 | + | }, |
| 60 | + | }, |
| 61 | + | { |
| 62 | + | id: 'emtYcsUh', |
| 63 | + | title: 'unist-util-generated', |
| 64 | + | description: 'unist utility to check if a node is generated', |
| 65 | + | featuredSites: { |
| 66 | + | iconList: [ |
| 67 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 68 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 69 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 70 | + | ], |
| 71 | + | numberOfUses: 5265, |
| 72 | + | }, |
| 73 | + | }, |
| 74 | + | { |
| 75 | + | id: 'TYIwvAfy', |
| 76 | + | title: 'react-smooth', |
| 77 | + | description: 'is a animation library work on React', |
| 78 | + | featuredSites: { |
| 79 | + | iconList: [ |
| 80 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 81 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 82 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 83 | + | ], |
| 84 | + | numberOfUses: 5265, |
| 85 | + | }, |
| 86 | + | }, |
| 87 | + | { |
| 88 | + | id: 'Lq1pEEX7', |
| 89 | + | title: 'unist-util-position', |
| 90 | + | description: 'unist utility to get the positional info of nodes', |
| 91 | + | featuredSites: { |
| 92 | + | iconList: [ |
| 93 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 94 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 95 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 96 | + | ], |
| 97 | + | numberOfUses: 5265, |
| 98 | + | }, |
| 99 | + | }, |
| 100 | + | { |
| 101 | + | id: 'cWOgIbmp', |
| 102 | + | title: 'vfile-message', |
| 103 | + | description: 'Create vfile messages', |
| 104 | + | featuredSites: { |
| 105 | + | iconList: [ |
| 106 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 107 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 108 | + | 'https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg', |
| 109 | + | ], |
| 110 | + | numberOfUses: 5265, |
| 111 | + | }, |
| 112 | + | }, |
| 113 | + | { |
| 114 | + | id: 'UT97Vpoi', |
| 115 | + | title: 'Go to all Popular packages', |
| 116 | + | variant: 'toAll', |
| 117 | + | }, |
| 118 | + | ]; |
24 | 119 | | |
25 | | - | const validate = useCallback( |
26 | | - | (data: FormData) => { |
27 | | - | let { address } = data; |
| 120 | + | // TODO: mock data, remove later |
| 121 | + | const vulnerablePackages: CardProps[] = [ |
| 122 | + | { |
| 123 | + | id: 'LnO9Xynn', |
| 124 | + | title: 'disneyland.omsk.ru/signup', |
| 125 | + | vulnerablePackage: { |
| 126 | + | name: 'mdast-util-from-markdown', |
| 127 | + | }, |
| 128 | + | variant: 'vulnerable', |
| 129 | + | }, |
| 130 | + | { |
| 131 | + | id: '-A74UAy8', |
| 132 | + | title: 'disneyland.omsk.ru/signup', |
| 133 | + | vulnerablePackage: { |
| 134 | + | name: 'mdast-util-from-markdown', |
| 135 | + | moreCount: 1, |
| 136 | + | }, |
| 137 | + | variant: 'vulnerable', |
| 138 | + | }, |
| 139 | + | { |
| 140 | + | id: 'DPa05I2W', |
| 141 | + | title: 'disneyland.omsk.ru/signup', |
| 142 | + | vulnerablePackage: { |
| 143 | + | name: 'mdast-util-from-markdown', |
| 144 | + | }, |
| 145 | + | variant: 'vulnerable', |
| 146 | + | }, |
| 147 | + | ]; |
28 | 148 | | |
29 | | - | if (!address.startsWith('http')) { |
30 | | - | address = `https://${address}`; |
31 | | - | } |
| 149 | + | return ( |
| 150 | + | <> |
| 151 | + | <Hero suggestions={suggestions} /> |
32 | 152 | | |
33 | | - | try { |
34 | | - | address = new URL(address).toString(); // normalize |
35 | | - | onSubmit({ address }); |
36 | | - | } catch (e) { |
37 | | - | setError('address', { message: 'Invalid origin format. Should be: https://example.com' }); |
38 | | - | } |
| 153 | + | <Container> |
| 154 | + | <CardGroups> |
| 155 | + | <CardGroup title='Popular search queries'> |
| 156 | + | <CardList cards={popularCards} /> |
| 157 | + | </CardGroup> |
39 | 158 | | |
40 | | - | // if (address.match(re)) { |
41 | | - | // } else { |
42 | | - | // setError('address', { message: 'Invalid origin format. Should be: https://example.com' }); |
43 | | - | // } |
44 | | - | }, |
45 | | - | [setError] |
46 | | - | ); |
| 159 | + | <CardGroup title='Popular packages'> |
| 160 | + | <CardList cards={popularPackages} /> |
| 161 | + | </CardGroup> |
47 | 162 | | |
48 | | - | const { address: error } = errors; |
| 163 | + | <CardGroup title='Vulnerable sites'> |
| 164 | + | <CardList cards={vulnerablePackages} variant='vertical' /> |
| 165 | + | </CardGroup> |
49 | 166 | | |
50 | | - | return ( |
51 | | - | <Wrapper className={styles.wrapper}> |
52 | | - | <Header /> |
53 | | - | <Section className={styles.content}> |
54 | | - | <h1>Analyze webpack production bundle</h1> |
55 | | - | <form onSubmit={handleSubmit(validate)} noValidate> |
56 | | - | <TextInput |
57 | | - | type='url' |
58 | | - | className={styles.address} |
59 | | - | placeholder='Enter a website URL' |
60 | | - | name='address' |
61 | | - | register={register} |
62 | | - | error={errors.address} |
63 | | - | disabled={isLoading} |
64 | | - | /> |
65 | | - | <Button className={styles.submit} variant='action' type='submit' disabled={isLoading}> |
66 | | - | Start |
67 | | - | </Button> |
| 167 | + | <CardGroup title='Authors of popular packages'> |
| 168 | + | <CardList cards={popularCards} /> |
| 169 | + | </CardGroup> |
| 170 | + | </CardGroups> |
| 171 | + | </Container> |
68 | 172 | | |
69 | | - | {error?.message ? ( |
70 | | - | <p className={clsx(styles.disclaimer, styles.error)}>{error.message}</p> |
71 | | - | ) : ( |
72 | | - | <p className={clsx(styles.disclaimer)}> |
73 | | - | GradeJS will analyze production JavaScript files and match webpack bundled modules to |
74 | | - | 1,826 indexed NPM libraries over 54,735 releases.{' '} |
75 | | - | <a |
76 | | - | href='https://github.com/gradejs/gradejs/discussions/6' |
77 | | - | target='_blank' |
78 | | - | rel='noreferrer' |
79 | | - | className={clsx(styles.learnMore)} |
80 | | - | > |
81 | | - | Learn more |
82 | | - | </a> |
83 | | - | </p> |
84 | | - | )} |
85 | | - | </form> |
86 | | - | </Section> |
87 | | - | </Wrapper> |
| 173 | + | <Footer /> |
| 174 | + | </> |
88 | 175 | | ); |
89 | 176 | | } |
90 | 177 | | |