Skip to content

Commit

Permalink
Merge pull request #6 from Gimnath-Perera/feat/dummy-data-generation
Browse files Browse the repository at this point in the history
feat: code changes handled
  • Loading branch information
gimnathperera committed Aug 26, 2023
2 parents 6168c65 + f58bc7d commit dc69f30
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 163 deletions.
27 changes: 24 additions & 3 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
'use client';
import { FC } from 'react';
import { FC, useState } from 'react';
import CodeEditor from '@/components/code-editor';
import Header from '@/components/header';
import Result from '@/components/result';

const DEFAULT_INTERFACE = `// You can use typescript interfaces like following;
interface Person {
id: number;
firstName: string;
lastName: string;
age: number;
bio: string;
}
`;

const Home: FC = () => {
const [code, setCode] = useState<string>(DEFAULT_INTERFACE);

const handleOnGenerate = (): void => {
console.log('*********', code);
};

const handleOnCodeChange = (newCode: string): void => {
setCode(newCode);
};

return (
<section className='h-full'>
<Header />
<Header onGenerate={handleOnGenerate} />
<div className='flex justify-center gap-6 h-[calc(100vh-12rem)]'>
<CodeEditor />
<CodeEditor onCodeChange={handleOnCodeChange} initialCode={code} />
<Result />
</div>
</section>
Expand Down
29 changes: 16 additions & 13 deletions components/code-editor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
'use client';
import { FC } from 'react';
import { FC, useCallback, useState } from 'react';
import Editor from '@monaco-editor/react';
import { Spinner } from '@nextui-org/react';

type Props = {};
type Props = { onCodeChange: (code: string) => void; initialCode: string };

const CodeEditor: FC<Props> = ({ onCodeChange, initialCode }) => {
const [code, setCode] = useState<string>(initialCode);

const handleCodeChange = useCallback(
(value: string | undefined): void => {
const newCode = value ?? '';
setCode(newCode);
onCodeChange(newCode);
},
[onCodeChange],
);

const CodeEditor: FC<Props> = ({}) => {
return (
<div className='bg-[#1E1E1E] rounded-lg w-1/2'>
<div className='py-2 h-full'>
<Editor
defaultLanguage='typescript'
defaultValue={`// You can use typescript interfaces like following;
interface Person {
id: 1;
firstName: "Jhon";
lastName: "Doe";
age: 24;
bio: "Architect & UI Designer";
}
`}
theme='vs-dark'
options={{
minimap: {
Expand All @@ -29,6 +30,8 @@ const CodeEditor: FC<Props> = ({}) => {
fontSize: 14,
}}
loading={<Spinner size='sm' />}
onChange={handleCodeChange}
value={code}
/>
</div>
</div>
Expand Down
8 changes: 5 additions & 3 deletions components/header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { FC } from 'react';
import { Dropdown, DropdownTrigger, DropdownMenu, DropdownItem, Button } from '@nextui-org/react';

type Props = {};
type Props = {
onGenerate: () => void;
};

const Header: FC<Props> = () => {
const Header: FC<Props> = ({ onGenerate }) => {
return (
<div className='pb-6 text-center flex items-center justify-between'>
<h1 className='tracking-tight inline font-semibold text-[2.3rem] lg:text-3xl'>
Expand All @@ -20,7 +22,7 @@ const Header: FC<Props> = () => {
<DropdownItem key='edit'>100</DropdownItem>
</DropdownMenu>
</Dropdown>
<Button color='primary' variant='shadow'>
<Button color='primary' variant='shadow' onClick={onGenerate}>
馃獎 Generate
</Button>
</div>
Expand Down
143 changes: 0 additions & 143 deletions components/icons.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
import * as React from 'react';
import { IconSvgProps } from '@/types';

export const Logo: React.FC<IconSvgProps> = ({ size = 36, width, height, ...props }) => (
<svg fill='none' height={size || height} viewBox='0 0 32 32' width={size || width} {...props}>
<path
clipRule='evenodd'
d='M17.6482 10.1305L15.8785 7.02583L7.02979 22.5499H10.5278L17.6482 10.1305ZM19.8798 14.0457L18.11 17.1983L19.394 19.4511H16.8453L15.1056 22.5499H24.7272L19.8798 14.0457Z'
fill='currentColor'
fillRule='evenodd'
/>
</svg>
);

export const DiscordIcon: React.FC<IconSvgProps> = ({ size = 24, width, height, ...props }) => {
return (
<svg height={size || height} viewBox='0 0 24 24' width={size || width} {...props}>
<path
d='M14.82 4.26a10.14 10.14 0 0 0-.53 1.1 14.66 14.66 0 0 0-4.58 0 10.14 10.14 0 0 0-.53-1.1 16 16 0 0 0-4.13 1.3 17.33 17.33 0 0 0-3 11.59 16.6 16.6 0 0 0 5.07 2.59A12.89 12.89 0 0 0 8.23 18a9.65 9.65 0 0 1-1.71-.83 3.39 3.39 0 0 0 .42-.33 11.66 11.66 0 0 0 10.12 0q.21.18.42.33a10.84 10.84 0 0 1-1.71.84 12.41 12.41 0 0 0 1.08 1.78 16.44 16.44 0 0 0 5.06-2.59 17.22 17.22 0 0 0-3-11.59 16.09 16.09 0 0 0-4.09-1.35zM8.68 14.81a1.94 1.94 0 0 1-1.8-2 1.93 1.93 0 0 1 1.8-2 1.93 1.93 0 0 1 1.8 2 1.93 1.93 0 0 1-1.8 2zm6.64 0a1.94 1.94 0 0 1-1.8-2 1.93 1.93 0 0 1 1.8-2 1.92 1.92 0 0 1 1.8 2 1.92 1.92 0 0 1-1.8 2z'
fill='currentColor'
/>
</svg>
);
};

export const TwitterIcon: React.FC<IconSvgProps> = ({ size = 24, width, height, ...props }) => {
return (
<svg height={size || height} viewBox='0 0 24 24' width={size || width} {...props}>
<path
d='M19.633 7.997c.013.175.013.349.013.523 0 5.325-4.053 11.461-11.46 11.461-2.282 0-4.402-.661-6.186-1.809.324.037.636.05.973.05a8.07 8.07 0 0 0 5.001-1.721 4.036 4.036 0 0 1-3.767-2.793c.249.037.499.062.761.062.361 0 .724-.05 1.061-.137a4.027 4.027 0 0 1-3.23-3.953v-.05c.537.299 1.16.486 1.82.511a4.022 4.022 0 0 1-1.796-3.354c0-.748.199-1.434.548-2.032a11.457 11.457 0 0 0 8.306 4.215c-.062-.3-.1-.611-.1-.923a4.026 4.026 0 0 1 4.028-4.028c1.16 0 2.207.486 2.943 1.272a7.957 7.957 0 0 0 2.556-.973 4.02 4.02 0 0 1-1.771 2.22 8.073 8.073 0 0 0 2.319-.624 8.645 8.645 0 0 1-2.019 2.083z'
fill='currentColor'
/>
</svg>
);
};

export const GithubIcon: React.FC<IconSvgProps> = ({ size = 24, width, height, ...props }) => {
return (
<svg height={size || height} viewBox='0 0 24 24' width={size || width} {...props}>
Expand All @@ -46,113 +13,3 @@ export const GithubIcon: React.FC<IconSvgProps> = ({ size = 24, width, height, .
</svg>
);
};

export const MoonFilledIcon: React.FC<IconSvgProps> = ({ size = 24, width, height, ...props }) => (
<svg
aria-hidden='true'
focusable='false'
height={size || height}
role='presentation'
viewBox='0 0 24 24'
width={size || width}
{...props}
>
<path
d='M21.53 15.93c-.16-.27-.61-.69-1.73-.49a8.46 8.46 0 01-1.88.13 8.409 8.409 0 01-5.91-2.82 8.068 8.068 0 01-1.44-8.66c.44-1.01.13-1.54-.09-1.76s-.77-.55-1.83-.11a10.318 10.318 0 00-6.32 10.21 10.475 10.475 0 007.04 8.99 10 10 0 002.89.55c.16.01.32.02.48.02a10.5 10.5 0 008.47-4.27c.67-.93.49-1.519.32-1.79z'
fill='currentColor'
/>
</svg>
);

export const SunFilledIcon: React.FC<IconSvgProps> = ({ size = 24, width, height, ...props }) => (
<svg
aria-hidden='true'
focusable='false'
height={size || height}
role='presentation'
viewBox='0 0 24 24'
width={size || width}
{...props}
>
<g fill='currentColor'>
<path d='M19 12a7 7 0 11-7-7 7 7 0 017 7z' />
<path d='M12 22.96a.969.969 0 01-1-.96v-.08a1 1 0 012 0 1.038 1.038 0 01-1 1.04zm7.14-2.82a1.024 1.024 0 01-.71-.29l-.13-.13a1 1 0 011.41-1.41l.13.13a1 1 0 010 1.41.984.984 0 01-.7.29zm-14.28 0a1.024 1.024 0 01-.71-.29 1 1 0 010-1.41l.13-.13a1 1 0 011.41 1.41l-.13.13a1 1 0 01-.7.29zM22 13h-.08a1 1 0 010-2 1.038 1.038 0 011.04 1 .969.969 0 01-.96 1zM2.08 13H2a1 1 0 010-2 1.038 1.038 0 011.04 1 .969.969 0 01-.96 1zm16.93-7.01a1.024 1.024 0 01-.71-.29 1 1 0 010-1.41l.13-.13a1 1 0 011.41 1.41l-.13.13a.984.984 0 01-.7.29zm-14.02 0a1.024 1.024 0 01-.71-.29l-.13-.14a1 1 0 011.41-1.41l.13.13a1 1 0 010 1.41.97.97 0 01-.7.3zM12 3.04a.969.969 0 01-1-.96V2a1 1 0 012 0 1.038 1.038 0 01-1 1.04z' />
</g>
</svg>
);

export const HeartFilledIcon: React.FC<IconSvgProps> = ({ size = 24, width, height, ...props }) => (
<svg
aria-hidden='true'
focusable='false'
height={size || height}
role='presentation'
viewBox='0 0 24 24'
width={size || width}
{...props}
>
<path
d='M12.62 20.81c-.34.12-.9.12-1.24 0C8.48 19.82 2 15.69 2 8.69 2 5.6 4.49 3.1 7.56 3.1c1.82 0 3.43.88 4.44 2.24a5.53 5.53 0 0 1 4.44-2.24C19.51 3.1 22 5.6 22 8.69c0 7-6.48 11.13-9.38 12.12Z'
fill='currentColor'
strokeLinecap='round'
strokeLinejoin='round'
strokeWidth={1.5}
/>
</svg>
);

export const SearchIcon: React.FC<IconSvgProps> = props => (
<svg
aria-hidden='true'
fill='none'
focusable='false'
height='1em'
role='presentation'
viewBox='0 0 24 24'
width='1em'
{...props}
>
<path
d='M11.5 21C16.7467 21 21 16.7467 21 11.5C21 6.25329 16.7467 2 11.5 2C6.25329 2 2 6.25329 2 11.5C2 16.7467 6.25329 21 11.5 21Z'
stroke='currentColor'
strokeLinecap='round'
strokeLinejoin='round'
strokeWidth='2'
/>
<path
d='M22 22L20 20'
stroke='currentColor'
strokeLinecap='round'
strokeLinejoin='round'
strokeWidth='2'
/>
</svg>
);

export const NextUILogo: React.FC<IconSvgProps> = props => {
const { width, height = 40 } = props;

return (
<svg
fill='none'
height={height}
viewBox='0 0 161 32'
width={width}
xmlns='http://www.w3.org/2000/svg'
{...props}
>
<path
className='fill-black dark:fill-white'
d='M55.6827 5V26.6275H53.7794L41.1235 8.51665H40.9563V26.6275H39V5H40.89L53.5911 23.1323H53.7555V5H55.6827ZM67.4831 26.9663C66.1109 27.0019 64.7581 26.6329 63.5903 25.9044C62.4852 25.185 61.6054 24.1633 61.0537 22.9582C60.4354 21.5961 60.1298 20.1106 60.1598 18.6126C60.132 17.1113 60.4375 15.6228 61.0537 14.2563C61.5954 13.0511 62.4525 12.0179 63.5326 11.268C64.6166 10.5379 65.8958 10.16 67.1986 10.1852C68.0611 10.1837 68.9162 10.3468 69.7187 10.666C70.5398 10.9946 71.2829 11.4948 71.8992 12.1337C72.5764 12.8435 73.0985 13.6889 73.4318 14.6152C73.8311 15.7483 74.0226 16.9455 73.9968 18.1479V19.0773H63.2262V17.4194H72.0935C72.1083 16.4456 71.8952 15.4821 71.4714 14.6072C71.083 13.803 70.4874 13.1191 69.7472 12.6272C68.9887 12.1348 68.1022 11.8812 67.2006 11.8987C66.2411 11.8807 65.3005 12.1689 64.5128 12.7223C63.7332 13.2783 63.1083 14.0275 62.6984 14.8978C62.2582 15.8199 62.0314 16.831 62.0352 17.8546V18.8476C62.009 20.0078 62.2354 21.1595 62.6984 22.2217C63.1005 23.1349 63.7564 23.9108 64.5864 24.4554C65.4554 24.9973 66.4621 25.2717 67.4831 25.2448C68.1676 25.2588 68.848 25.1368 69.4859 24.8859C70.0301 24.6666 70.5242 24.3376 70.9382 23.919C71.3183 23.5345 71.6217 23.0799 71.8322 22.5799L73.5995 23.1604C73.3388 23.8697 72.9304 24.5143 72.4019 25.0506C71.8132 25.6529 71.1086 26.1269 70.3314 26.4434C69.4258 26.8068 68.4575 26.9846 67.4831 26.9663V26.9663ZM78.8233 10.4075L82.9655 17.325L87.1076 10.4075H89.2683L84.1008 18.5175L89.2683 26.6275H87.103L82.9608 19.9317L78.8193 26.6275H76.6647L81.7711 18.5169L76.6647 10.4062L78.8233 10.4075ZM99.5142 10.4075V12.0447H91.8413V10.4075H99.5142ZM94.2427 6.52397H96.1148V22.3931C96.086 22.9446 96.2051 23.4938 96.4597 23.9827C96.6652 24.344 96.9805 24.629 97.3589 24.7955C97.7328 24.9548 98.1349 25.0357 98.5407 25.0332C98.7508 25.0359 98.9607 25.02 99.168 24.9857C99.3422 24.954 99.4956 24.9205 99.6283 24.8853L100.026 26.5853C99.8062 26.6672 99.5805 26.7327 99.3511 26.7815C99.0274 26.847 98.6977 26.8771 98.3676 26.8712C97.6854 26.871 97.0119 26.7156 96.3973 26.4166C95.7683 26.1156 95.2317 25.6485 94.8442 25.0647C94.4214 24.4018 94.2097 23.6242 94.2374 22.8363L94.2427 6.52397ZM118.398 5H120.354V19.3204C120.376 20.7052 120.022 22.0697 119.328 23.2649C118.644 24.4235 117.658 25.3698 116.477 26.0001C115.168 26.6879 113.708 27.0311 112.232 26.9978C110.759 27.029 109.302 26.6835 107.996 25.9934C106.815 25.362 105.827 24.4161 105.141 23.2582C104.447 22.0651 104.092 20.7022 104.115 19.319V5H106.08V19.1831C106.061 20.2559 106.324 21.3147 106.843 22.2511C107.349 23.1459 108.094 23.8795 108.992 24.3683C109.993 24.9011 111.111 25.1664 112.242 25.139C113.373 25.1656 114.493 24.9003 115.495 24.3683C116.395 23.8815 117.14 23.1475 117.644 22.2511C118.16 21.3136 118.421 20.2553 118.402 19.1831L118.398 5ZM128 5V26.6275H126.041V5H128Z'
/>
<path
className='fill-black dark:fill-white'
d='M23.5294 0H8.47059C3.79241 0 0 3.79241 0 8.47059V23.5294C0 28.2076 3.79241 32 8.47059 32H23.5294C28.2076 32 32 28.2076 32 23.5294V8.47059C32 3.79241 28.2076 0 23.5294 0Z'
/>
<path
className='fill-white dark:fill-black'
d='M17.5667 9.21729H18.8111V18.2403C18.8255 19.1128 18.6 19.9726 18.159 20.7256C17.7241 21.4555 17.0968 22.0518 16.3458 22.4491C15.5717 22.8683 14.6722 23.0779 13.6473 23.0779C12.627 23.0779 11.7286 22.8672 10.9521 22.4457C10.2007 22.0478 9.5727 21.4518 9.13602 20.7223C8.6948 19.9705 8.4692 19.1118 8.48396 18.2403V9.21729H9.72854V18.1538C9.71656 18.8298 9.88417 19.4968 10.2143 20.0868C10.5362 20.6506 11.0099 21.1129 11.5814 21.421C12.1689 21.7448 12.8576 21.9067 13.6475 21.9067C14.4374 21.9067 15.1272 21.7448 15.7169 21.421C16.2895 21.1142 16.7635 20.6516 17.0844 20.0868C17.4124 19.4961 17.5788 18.8293 17.5667 18.1538V9.21729ZM23.6753 9.21729V22.845H22.4309V9.21729H23.6753Z'
/>
</svg>
);
};
2 changes: 1 addition & 1 deletion components/navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const Navbar: FC = () => {
<NavbarContent className='basis-1/5 sm:basis-full' justify='start'>
<NavbarBrand as='li' className='gap-3 max-w-fit'>
<NextLink className='flex justify-start items-center gap-1 font-bold text-xl' href='/'>
<Image src={logo} alt='logo' placeholder='blur' width={24} height={24} />
<Image src={logo} alt='logo' width={24} height={24} />
Mocktopus
</NextLink>
</NavbarBrand>
Expand Down

0 comments on commit dc69f30

Please sign in to comment.