|
1 | 1 | import { RedocStandalone } from 'redoc'
|
| 2 | +import { useState } from 'react' |
2 | 3 |
|
3 | 4 | import './App.css'
|
4 | 5 |
|
| 6 | +const RocketLogo = (): JSX.Element => <img src="/logo.png" width={80} /> |
| 7 | + |
5 | 8 | const styles = {
|
| 9 | + // Layout |
6 | 10 | container: {
|
| 11 | + fontFamily: '"Inter", sans-serif', |
| 12 | + maxWidth: '1200px', |
| 13 | + margin: '0 auto', |
| 14 | + padding: '0 20px' |
| 15 | + }, |
| 16 | + header: { |
| 17 | + display: 'flex' as const, |
| 18 | + alignItems: 'center', |
| 19 | + justifyContent: 'center', |
| 20 | + flexDirection: 'column' as const, |
| 21 | + padding: '40px 0 30px' |
| 22 | + }, |
| 23 | + branding: { |
| 24 | + display: 'flex' as const, |
| 25 | + alignItems: 'center', |
| 26 | + marginBottom: '20px' |
| 27 | + }, |
| 28 | + content: { |
| 29 | + display: 'flex' as const, |
| 30 | + flexDirection: 'column' as const, |
| 31 | + alignItems: 'center', |
7 | 32 | maxWidth: '600px',
|
8 |
| - margin: 'auto', |
9 |
| - padding: '20px', |
10 |
| - backgroundColor: '#f8f9fa', |
| 33 | + margin: '0 auto 40px', |
11 | 34 | textAlign: 'center' as const
|
12 | 35 | },
|
| 36 | + card: { |
| 37 | + backgroundColor: '#f8f9fa', |
| 38 | + borderRadius: '8px', |
| 39 | + boxShadow: '0 2px 10px rgba(0,0,0,0.08)', |
| 40 | + padding: '40px', |
| 41 | + width: '100%', |
| 42 | + marginTop: '30px' |
| 43 | + }, |
| 44 | + // Typography |
13 | 45 | title: {
|
| 46 | + fontSize: '36px', |
| 47 | + fontWeight: 600, |
14 | 48 | color: '#fb2645',
|
15 |
| - marginBottom: '20px' |
| 49 | + margin: '0 0 0 12px' |
| 50 | + }, |
| 51 | + subTitle: { |
| 52 | + fontSize: '22px', |
| 53 | + fontWeight: 500, |
| 54 | + color: '#333', |
| 55 | + margin: '0 0 24px 0' |
16 | 56 | },
|
17 | 57 | text: {
|
18 | 58 | fontSize: '16px',
|
19 |
| - marginBottom: '10px' |
| 59 | + lineHeight: '24px', |
| 60 | + color: '#555', |
| 61 | + margin: '0 0 24px 0' |
| 62 | + }, |
| 63 | + link: { |
| 64 | + color: '#fb2645', |
| 65 | + textDecoration: 'none', |
| 66 | + fontWeight: 500 |
| 67 | + }, |
| 68 | + // Form elements |
| 69 | + inputGroup: { |
| 70 | + display: 'flex' as const, |
| 71 | + width: '100%', |
| 72 | + marginTop: '20px' |
| 73 | + }, |
| 74 | + input: { |
| 75 | + flex: 1, |
| 76 | + padding: '12px 16px', |
| 77 | + fontSize: '16px', |
| 78 | + borderRadius: '4px 0 0 4px', |
| 79 | + border: '1px solid #ddd', |
| 80 | + borderRight: 'none', |
| 81 | + outline: 'none', |
| 82 | + transition: 'border-color 0.2s' |
| 83 | + }, |
| 84 | + button: { |
| 85 | + backgroundColor: '#fb2645', |
| 86 | + color: 'white', |
| 87 | + border: 'none', |
| 88 | + borderRadius: '0 4px 4px 0', |
| 89 | + padding: '0 24px', |
| 90 | + fontSize: '16px', |
| 91 | + fontWeight: 500, |
| 92 | + cursor: 'pointer', |
| 93 | + transition: 'background-color 0.2s' |
| 94 | + }, |
| 95 | + // Special states |
| 96 | + inputFocused: { |
| 97 | + borderColor: '#fb2645' |
| 98 | + }, |
| 99 | + buttonHover: { |
| 100 | + backgroundColor: '#e51e3a' |
| 101 | + }, |
| 102 | + footer: { |
| 103 | + marginTop: '40px', |
| 104 | + fontSize: '14px', |
| 105 | + color: '#999' |
| 106 | + }, |
| 107 | + // Banner |
| 108 | + banner: { |
| 109 | + fontFamily: '"Inter", sans-serif', |
| 110 | + backgroundColor: '#000000', |
| 111 | + color: 'white', |
| 112 | + textAlign: 'center' as const, |
| 113 | + padding: '12px 0px', |
| 114 | + width: '100%', |
| 115 | + position: 'relative' as const, |
| 116 | + zIndex: 9999, |
| 117 | + boxShadow: '0 2px 4px rgba(0,0,0,0.1)' |
| 118 | + }, |
| 119 | + bannerText: { |
| 120 | + margin: 0, |
| 121 | + fontSize: '15px', |
| 122 | + color: '#fb2645' |
| 123 | + }, |
| 124 | + bannerLink: { |
| 125 | + color: '#fb2645', |
| 126 | + fontWeight: 600, |
| 127 | + textDecoration: 'underline' |
20 | 128 | }
|
21 | 129 | }
|
22 | 130 |
|
23 |
| -function App (): JSX.Element { |
| 131 | +const App = (): JSX.Element => { |
| 132 | + // State to manage URL input |
| 133 | + const [inputUrl, setInputUrl] = useState('') |
| 134 | + const [inputFocused, setInputFocused] = useState(false) |
| 135 | + const [buttonHovered, setButtonHovered] = useState(false) |
| 136 | + |
| 137 | + // Handle URL from query parameters |
24 | 138 | const params = window.location.search
|
25 |
| - const url = params.split('=').length > 1 ? params.split('=')[1] : '' |
| 139 | + const url = |
| 140 | + params.split('=').length > 1 |
| 141 | + ? decodeURIComponent(params.split('=')[1]) |
| 142 | + : '' |
26 | 143 |
|
| 144 | + // Navigate to URL when form is submitted |
| 145 | + const handleSubmit = (e: React.FormEvent): void => { |
| 146 | + e.preventDefault() |
| 147 | + if (inputUrl.trim().length > 0) { |
| 148 | + window.location.href = `?url=${encodeURIComponent(inputUrl.trim())}` |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + // Banner component that shows when URL is present |
| 153 | + const Banner = (): JSX.Element => ( |
| 154 | + <div style={styles.banner}> |
| 155 | + <p style={styles.bannerText}> |
| 156 | + Powered by{' '} |
| 157 | + <a |
| 158 | + href="https://rocketapi.net" |
| 159 | + target="_blank" |
| 160 | + rel="noopener noreferrer" |
| 161 | + style={styles.bannerLink} |
| 162 | + > |
| 163 | + Rocket |
| 164 | + </a>{' '} |
| 165 | + - Build your backend with Rocket. |
| 166 | + </p> |
| 167 | + </div> |
| 168 | + ) |
| 169 | + |
| 170 | + // If no URL parameter is provided, show the landing page |
27 | 171 | if (url.length === 0) {
|
28 | 172 | return (
|
29 |
| - <div style={styles.container}> |
30 |
| - <h1 style={styles.title}>Error: OpenAPI Schema URL Missing</h1> |
31 |
| - <p style={styles.text}> |
32 |
| - You need to pass the OpenAPI schema URL as a query string in the |
33 |
| - following format: |
34 |
| - </p> |
35 |
| - <p style={styles.text}> |
36 |
| - <i>https://redoc.rocketapi.net/?url=your_openapi_schema_url</i> |
37 |
| - </p> |
| 173 | + <div style={{ minHeight: '100vh' }}> |
| 174 | + <div style={styles.container}> |
| 175 | + <header style={styles.header}> |
| 176 | + <div style={styles.branding}> |
| 177 | + <RocketLogo /> |
| 178 | + <h1 style={styles.title}>Rocket API</h1> |
| 179 | + </div> |
| 180 | + </header> |
| 181 | + |
| 182 | + <main style={styles.content}> |
| 183 | + <h2 style={styles.subTitle}>OpenAPI Documentation Viewer</h2> |
| 184 | + <p style={styles.text}> |
| 185 | + Visualize and explore your API documentation with our Redoc UI |
| 186 | + integration. Simply enter your OpenAPI schema URL below to get |
| 187 | + started. |
| 188 | + </p> |
| 189 | + |
| 190 | + <div style={styles.card}> |
| 191 | + <p style={styles.text}>Enter your OpenAPI schema URL:</p> |
| 192 | + |
| 193 | + <form onSubmit={handleSubmit}> |
| 194 | + <div style={styles.inputGroup}> |
| 195 | + <input |
| 196 | + type="url" |
| 197 | + placeholder="https://example.com/openapi.json" |
| 198 | + value={inputUrl} |
| 199 | + onChange={(e) => { |
| 200 | + setInputUrl(e.target.value) |
| 201 | + }} |
| 202 | + onFocus={() => { |
| 203 | + setInputFocused(true) |
| 204 | + }} |
| 205 | + onBlur={() => { |
| 206 | + setInputFocused(false) |
| 207 | + }} |
| 208 | + style={{ |
| 209 | + ...styles.input, |
| 210 | + ...(inputFocused ? styles.inputFocused : {}) |
| 211 | + }} |
| 212 | + /> |
| 213 | + <button |
| 214 | + type="submit" |
| 215 | + onMouseEnter={() => { |
| 216 | + setButtonHovered(true) |
| 217 | + }} |
| 218 | + onMouseLeave={() => { |
| 219 | + setButtonHovered(false) |
| 220 | + }} |
| 221 | + style={{ |
| 222 | + ...styles.button, |
| 223 | + ...(buttonHovered ? styles.buttonHover : {}) |
| 224 | + }} |
| 225 | + > |
| 226 | + View Docs |
| 227 | + </button> |
| 228 | + </div> |
| 229 | + </form> |
| 230 | + </div> |
| 231 | + |
| 232 | + <footer style={styles.footer}> |
| 233 | + <p> |
| 234 | + Visit{' '} |
| 235 | + <a |
| 236 | + href="https://rocketapi.net" |
| 237 | + target="_blank" |
| 238 | + rel="noopener noreferrer" |
| 239 | + style={styles.link} |
| 240 | + > |
| 241 | + rocketapi.net |
| 242 | + </a>{' '} |
| 243 | + for information. |
| 244 | + </p> |
| 245 | + <p style={{ marginTop: '10px', fontSize: '14px', color: '#666' }}> |
| 246 | + Rocket - Build your backend with Rocket. |
| 247 | + </p> |
| 248 | + </footer> |
| 249 | + </main> |
| 250 | + </div> |
38 | 251 | </div>
|
39 | 252 | )
|
40 | 253 | }
|
41 | 254 |
|
| 255 | + // If URL is provided, show the Redoc UI with banner |
42 | 256 | return (
|
43 |
| - <RedocStandalone |
44 |
| - specUrl={url} |
45 |
| - options={{ |
46 |
| - nativeScrollbars: true, |
47 |
| - theme: { colors: { primary: { main: '#fb2645' } } } |
48 |
| - }} |
49 |
| - /> |
| 257 | + <div style={{ backgroundColor: 'white', height: '100vh' }}> |
| 258 | + <Banner /> |
| 259 | + <RedocStandalone |
| 260 | + specUrl={url} |
| 261 | + options={{ |
| 262 | + nativeScrollbars: true, |
| 263 | + theme: { colors: { primary: { main: '#fb2645' } } } |
| 264 | + }} |
| 265 | + /> |
| 266 | + </div> |
50 | 267 | )
|
51 | 268 | }
|
52 | 269 |
|
|
0 commit comments