Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create issue #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const Header = () => {
</a>
</Link>

<Button onClick={() => Router.push('/')}>Adicionar novo termo</Button>
<Button onClick={() => Router.push('/new')}>Adicionar novo termo</Button>

<style jsx>
{`
Expand Down
57 changes: 5 additions & 52 deletions layouts/page/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import React, { ReactNode } from 'react'
import Head from 'next/head'

import pkg from '../../package.json'

import { Colors } from 'ui/theme'
import { Row } from 'ui/row'
import { Header } from 'components/header'
import { Footer } from 'components/footer/footer'

export type PageProps = {
children: ReactNode
onChangeWord: () => void
}

if ('document' in global) {
Expand All @@ -23,54 +17,13 @@ if ('document' in global) {
})
}

export const Page = ({ children, onChangeWord }: PageProps) => {
export const Page = ({ children }: PageProps) => {
return (
<>
<Head>
<title>ndi — não diga isso</title>
<meta name="description" content={pkg.description} />

<link rel="apple-touch-icon" href="static/icon.png" />
<link rel="icon" href="static/icon.png" type="image/png" />
<meta name="theme-color" content={Colors.White} />

<meta name="viewport" content="width=device-width" />
<link rel="manifest" href="/manifest.json" />

<link
href="https://fonts.googleapis.com/css?family=Inter:400,700&display=swap"
rel="stylesheet"
/>

<meta property="og:title" content={pkg.name} />
<meta property="og:description" content={pkg.description} />

<meta
name="twitter:image"
content="https://naodigaisso.com/static/cover.png"
/>
<meta name="twitter:card" content="summary_large_image" />

<meta property="og:title" content={pkg.name} />
<meta property="og:description" content={pkg.description} />
<meta
property="og:image"
content="https://naodigaisso.com/static/cover.png"
/>
<meta property="og:url" content="https://naodigaisso.com" />
<meta property="og:type" content="website" />
</Head>

<Row>
<div className="page">
<Header />
<main>{children}</main>
<Footer onChangeWord={onChangeWord} />
</div>
</Row>
<Row>
<main>{children}</main>

<style jsx>{`
.page {
main {
display: flex;
justify-content: space-between;
flex-direction: column;
Expand Down Expand Up @@ -112,6 +65,6 @@ export const Page = ({ children, onChangeWord }: PageProps) => {
width: 100%;
}
`}</style>
</>
</Row>
)
}
40 changes: 39 additions & 1 deletion pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
import React from 'react'
import Document, { Html, Head, Main, NextScript } from 'next/document'

import pkg from '../package.json'

import { Colors } from 'ui/theme'

class MyDocument extends Document {
render() {
return (
<Html lang="pt-br">
<Head />
<Head>
<title>ndi — não diga isso</title>
<meta name="description" content={pkg.description} />

<link rel="apple-touch-icon" href="static/icon.png" />
<link rel="icon" href="static/icon.png" type="image/png" />
<meta name="theme-color" content={Colors.White} />

<meta name="viewport" content="width=device-width" />
<link rel="manifest" href="/manifest.json" />

<link
href="https://fonts.googleapis.com/css?family=Inter:400,700&display=swap"
rel="stylesheet"
/>

<meta property="og:title" content={pkg.name} />
<meta property="og:description" content={pkg.description} />

<meta
name="twitter:image"
content="https://naodigaisso.com/static/cover.png"
/>
<meta name="twitter:card" content="summary_large_image" />

<meta property="og:title" content={pkg.name} />
<meta property="og:description" content={pkg.description} />
<meta
property="og:image"
content="https://naodigaisso.com/static/cover.png"
/>
<meta property="og:url" content="https://naodigaisso.com" />
<meta property="og:type" content="website" />
</Head>

<body>
<Main />
<NextScript />
Expand Down
24 changes: 24 additions & 0 deletions pages/api/create-issue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NextApiRequest, NextApiResponse } from 'next'
import unfetch from 'isomorphic-unfetch'

const createIssue = async (
request: NextApiRequest,
response: NextApiResponse
) => {
const data = await fetch(
'https://api.github.com/repos/bukinoshita/naodigaisso/issues',
{
method: 'POST',
headers: {
authorization: `token ${process.env.GITHUB_TOKEN}`,
},
body: request.body,
}
)

const result = await data.json()

response.json(result)
}

export default createIssue
6 changes: 5 additions & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Page } from 'layouts/page'
import { Word } from 'components/word'

import { fetch } from 'utils/fetch'
import { Header } from 'components/header'
import { Footer } from 'components/footer'

export async function getStaticProps() {
const data = await fetch(`${process.env.NEXT_PUBLIC_API}/pretos`)
Expand All @@ -27,8 +29,10 @@ export const Home = (props: any) => {
useKeypress(KEY_SPACE, onChangeWord)

return (
<Page onChangeWord={onChangeWord}>
<Page>
<Header />
<Word word={word} />
<Footer onChangeWord={onChangeWord} />
</Page>
)
}
Expand Down
29 changes: 29 additions & 0 deletions pages/new.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { useState } from 'react'
import { fetch } from 'utils/fetch'
import { Page } from 'layouts/page'

const New = () => {
const [title, setTitle] = useState<string>('')
const [description, setDescription] = useState<string>('')

const createIssue = () => {
fetch('/api/create-issue', {
method: 'POST',
body: JSON.stringify({ title, body: description }),
})
}

return (
<Page>
<section>
<form onSubmit={createIssue}>
<input />
<textarea></textarea>
<button type="submit">AAA</button>
</form>
</section>
</Page>
)
}

export default New