forked from clintonwoo/hackernews-react-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit.tsx
140 lines (132 loc) · 4.42 KB
/
submit.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import Link from 'next/link';
import Router from 'next/router';
import React, { useState } from 'react';
import { useMutation } from '@apollo/react-hooks';
import { SUBMIT_NEWS_ITEM_MUTATION } from '../src/data/mutations/submit-news-item-mutation';
import { withDataAndRouter } from '../src/helpers/with-data';
import { MainLayout } from '../src/layouts/main-layout';
import { NewsItemModel } from '../src/data/models';
interface ISubmitPageProps {
currentUrl: string;
}
function SubmitPageView(props: ISubmitPageProps): JSX.Element {
const { currentUrl } = props;
const [title, setTitle] = useState<string>('');
const [url, setUrl] = useState<string>('');
const [text, setText] = useState<string>('');
const [submitNewsItem] = useMutation(SUBMIT_NEWS_ITEM_MUTATION, {
variables: { title, url, text },
onCompleted(res) {
if (res && res.data) {
Router.push(`/item?id=${res.data.submitNewsItem.id}`);
}
},
onError(err) {
console.error(err);
},
});
return (
<MainLayout currentUrl={currentUrl} title="Submit" isNavVisible={false} isFooterVisible={false}>
<tr>
<td>
<form onSubmit={(e): void => e.preventDefault()}>
<input type="hidden" name="fnid" value="GvyHFpy11L26dCAIgGQ9rv" />
<input type="hidden" name="fnop" value="submit-page" />
<script type="text/javascript">
{
"function tlen(el) { var n = el.value.length - 80; el.nextSibling.innerText = n > 0 ? n + ' too long' : ''; }"
}
</script>
<table style={{ border: '0' }}>
<tbody>
<tr>
<td>title</td>
<td>
<input
type="text"
name="title"
defaultValue=""
size={50}
onChange={(e: React.ChangeEvent<HTMLInputElement>): void => {
setTitle(e.target.value);
}}
/>
<span style={{ marginLeft: '10px' }} />
</td>
</tr>
<tr>
<td>url</td>
<td>
<input
type="text"
name="url"
defaultValue=""
size={50}
onChange={(e: React.ChangeEvent<HTMLInputElement>): void => {
setUrl(e.target.value);
}}
/>
</td>
</tr>
<tr>
<td />
<td>
<b>or</b>
</td>
</tr>
<tr>
<td>text</td>
<td>
<textarea
name="text"
rows={4}
cols={49}
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>): void => {
setText(e.target.value);
}}
/>
</td>
</tr>
<tr>
<td />
<td />
</tr>
<tr>
<td />
<td>
<input
type="submit"
value="submit"
onClick={(): Promise<any> => submitNewsItem()}
/>
</td>
</tr>
<tr style={{ height: '20px' }} />
<tr>
<td />
<td>
Leave url blank to submit a question for discussion. If there is no url, the
text (if any) will appear at the top of the thread.
<br />
<br />
You can also submit via{' '}
<Link href="/bookmarklet">
<a rel="nofollow">
<u>bookmarklet</u>
</a>
</Link>
.
</td>
</tr>
</tbody>
</table>
</form>
</td>
</tr>
</MainLayout>
);
}
export const SubmitPage = withDataAndRouter((props) => (
<SubmitPageView currentUrl={props.router.pathname} />
));
export default SubmitPage;