This repository has been archived by the owner on Sep 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.tsx
227 lines (195 loc) · 9.8 KB
/
index.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import * as React from 'react';
import marked from 'marked';
export interface RealWorldComponentProps {
[key: string]: any;
}
export interface RealWorldComponentState {
[key: string]: any;
}
export interface Article {
body: string;
[key: string]: any;
}
class RealWorldComponent extends React.Component<RealWorldComponentProps, RealWorldComponentState> {
protected article: Article;
constructor(
props: RealWorldComponentProps,
context?: any /* article: Article, User, Comments, $sce, $rootScope */
) {
super(props, context);
this.article = article;
this._Comments = Comments;
this.currentUser = User.current;
$rootScope.setPageTitle(this.article.title);
this.article.body = $sce.trustAsHtml(marked(this.article.body, {sanitize: true}));
Comments.getAll(this.article.slug).then((comments) => (this.comments = comments));
this.resetCommentForm();
}
private resetCommentForm() {
this.commentForm = {
isSubmitting: false,
body: '',
errors: []
};
}
private addComment() {
this.commentForm.isSubmitting = true;
this._Comments.add(this.article.slug, this.commentForm.body).then(
(comment) => {
this.comments.unshift(comment);
this.resetCommentForm();
},
(err) => {
this.commentForm.isSubmitting = false;
this.commentForm.errors = err.data.errors;
}
);
}
private deleteComment(commentId, index) {
this._Comments.destroy(commentId, this.article.slug).then((success) => {
this.comments.splice(index, 1);
});
}
render() {
return (
<div>
<nav className="navbar navbar-light">
<div className="container">
<NavLink className="navbar-brand" to="app.home">
{lowercase($ctrl.appName)}
</NavLink>
{/* Show this for logged out users */}
<ul show-authed="false" className="nav navbar-nav pull-xs-right">
<li className="nav-item">
<NavLink className="nav-link" activeClassName="active" to="app.home">
Home
</NavLink>
</li>
<li className="nav-item">
<NavLink className="nav-link" activeClassName="active" to="app.login">
Sign in
</NavLink>
</li>
<li className="nav-item">
<NavLink className="nav-link" activeClassName="active" to="app.register">
Sign up
</NavLink>
</li>
</ul>
{/* Show this for logged in users */}
<ul show-authed="true" className="nav navbar-nav pull-xs-right">
<li className="nav-item">
<NavLink className="nav-link" activeClassName="active" to="app.home">
Home
</NavLink>
</li>
<li className="nav-item">
<NavLink className="nav-link" activeClassName="active" to="app.editor">
<i className="ion-compose" /> New Article
</NavLink>
</li>
<li className="nav-item">
<NavLink className="nav-link" activeClassName="active" to="app.settings">
<i className="ion-gear-a" /> Settings
</NavLink>
</li>
<li className="nav-item">
<NavLink
className="nav-link"
activeClassName="active"
to="app.profile.main({ username: $ctrl.currentUser.username})">
<img src={$ctrl.currentUser.image} className="user-pic" />
{$ctrl.currentUser.username}
</NavLink>
</li>
</ul>
</div>
</nav>
<div className="editor-page">
<div className="container page">
<div className="row">
<div className="col-md-10 offset-md-1 col-xs-12">
<ListErrors errors="$ctrl.errors" />
<form>
<fieldset disabled={$ctrl.isSubmitting}>
<fieldset className="form-group">
<input
className="form-control form-control-lg"
value={$ctrl.article.title}
type="text"
placeholder="Article Title"
/>
</fieldset>
<fieldset className="form-group">
<input
className="form-control"
value={$ctrl.article.description}
type="text"
placeholder="What's this article about?"
/>
</fieldset>
<fieldset className="form-group">
<textarea
className="form-control"
rows={8}
value={$ctrl.article.body}
placeholder="Write your article (in markdown)">
{' '}
</textarea>
</fieldset>
<fieldset className="form-group">
<input
className="form-control"
type="text"
placeholder="Enter tags"
value={$ctrl.tagField}
onKeyUp={(event: React.SyntheticEvent<HTMLElement>) => {
event.keyCode == 13 && $ctrl.addTag();
}}
/>
<div className="tag-list">
{$ctrl.article.tagList.map((tag, index: number) => {
return (
<span key={`item-${index}`} className="tag-default tag-pill">
<i
className="ion-close-round"
onClick={() => {
$ctrl.removeTag(tag);
}}
/>
{tag}
</span>
);
})}
</div>
</fieldset>
<button
className="btn btn-lg pull-xs-right btn-primary"
type="button"
onClick={() => {
$ctrl.submit();
}}>
Publish Article
</button>
</fieldset>
</form>
</div>
</div>
</div>
</div>
<footer>
<div className="container">
<NavLink className="logo-font" to="app.home">
{lowercase($ctrl.appName)}
</NavLink>
<span className="attribution">
© {date($ctrl.date, 'yyyy')}. An interactive learning project from{' '}
<a href="https://thinkster.io">Thinkster</a>. Code licensed under MIT.
</span>
</div>
</footer>
</div>
);
}
}
export default RealWorldComponent;