From efbee265d39a966e33548a8335fc090e06c50441 Mon Sep 17 00:00:00 2001 From: Mitchell Gerber Date: Sun, 14 Jan 2018 23:46:15 -0600 Subject: [PATCH] little bit of everything - it's been a long day --- client/app/assets/avatars/unknown.gif | Bin 0 -> 1060 bytes client/app/assets/search.gif | Bin 0 -> 347 bytes client/app/components/editor/editor.scss | 11 +- client/app/components/editor/editor.tsx | 104 ++++++++++++++---- .../components/login-button/login-button.scss | 6 + .../components/login-button/login-button.tsx | 3 +- client/app/model/reply.ts | 5 +- client/app/model/thread.ts | 10 +- client/app/pages/forum/forum.tsx | 8 +- client/app/pages/home/home.tsx | 4 +- client/app/pages/thread/thread.scss | 12 +- client/app/pages/thread/thread.tsx | 97 ++++++++++++---- .../app/pages/user-account/user-account.tsx | 2 +- client/app/scss/style.scss | 39 ++++++- client/app/services/character.service.ts | 9 +- client/package.json | 2 + client/yarn.lock | 8 ++ lib/myapp/data/reply.ex | 8 +- lib/myapp/data/thread.ex | 14 ++- lib/myapp/data/user.ex | 2 +- .../20180102015706_create_thread.exs | 2 +- test/myapp/data/thread_test.exs | 12 +- test/myapp/data/user_test.exs | 5 + .../controllers/reply_controller_test.exs | 31 ++---- .../controllers/thread_controller_test.exs | 29 ++--- 25 files changed, 298 insertions(+), 125 deletions(-) create mode 100644 client/app/assets/avatars/unknown.gif create mode 100644 client/app/assets/search.gif create mode 100644 client/app/components/login-button/login-button.scss diff --git a/client/app/assets/avatars/unknown.gif b/client/app/assets/avatars/unknown.gif new file mode 100644 index 0000000000000000000000000000000000000000..e14945a3403f4a7d322408e52b6d4f8b1ecf8439 GIT binary patch literal 1060 zcmZ?wbhEHbbYO5`XlDQcH8r)9E0ikIRSfmjR!>m!cT?HFKq)0$WkI`=m6__adgbnN z(+<4{2e3dQJm0ayr!TLst(GVE&A)xr5+s`#5*x50_)kx2PnGxtA#h)y!Ab;tA z2v9a*;CRQt%pv2kVZp&>4q>gB6B`yDZWmDYn&Yu?(a~-R6Eu$OVh5-E4;6!8?`<8*1A+~dA~h7K0ZD%Sv&sRo}HhcUzp6!!e9*m DBt3_V literal 0 HcmV?d00001 diff --git a/client/app/assets/search.gif b/client/app/assets/search.gif new file mode 100644 index 0000000000000000000000000000000000000000..094721f40343901af74c50d9f1fd778d15453e7f GIT binary patch literal 347 zcmV-h0i^y%Nk%w1VG#fo0K^{vl#7?i$I5qfd0Sa#0s;ggA}qJK#}5z}-QVN@DLMc} zSb)mkK$4;?MM<>4LjUe3DkB5`&j9qk0Lq{MypRCPl>pGIK5I+>|H(c>I3OMr0+nkZ z__jQ&iBQ3~s{jB0A^8LW0018VEC2ui01*Hc000Hp;3tYiSsr659z@X$1*?w70RUb; z403uD0nZ>&BMblqLW+O@AQl3LBVz<8NrOOQ!4OzDm(rkt`WyrTg}TGxY)XZ}wE$?S z69NwA!YT;nbqNg(1syyG8XA8qXc-+A7!MH<6B{pAMjjd)77~*Z6d5pOECv7&8xs>2 z9io3%A{hn-8W#XiP97O7Wf~a(v!(&F0gpYXB^k;P$sNubu@w**6%-Y37rp`=1tJg> t5El~T6bBbn8Z{z`1Q(ML6^ZFHA{*}$5cDY-7aJQF`Sh)mmuN-^06QS1Z3qAW literal 0 HcmV?d00001 diff --git a/client/app/components/editor/editor.scss b/client/app/components/editor/editor.scss index ec2992e..1d362ef 100644 --- a/client/app/components/editor/editor.scss +++ b/client/app/components/editor/editor.scss @@ -2,10 +2,10 @@ z-index: 1; top: 0; left: 0; - height: calc(100% - 96px); + height: 100%; width: 100%; position: fixed; - background-color: rgba(0, 0, 0, .5); + background-color: rgba(0, 0, 0, .9); padding-top: 50px; } @@ -15,21 +15,22 @@ flex-direction: column; padding-bottom: 40px; + &__character-count { + align-self: flex-end; + } + &__title { height: 25px; - margin-bottom: 20px; } &__text-area { min-height: 100px; resize: none; - margin-bottom: 20px; overflow-wrap: break-word; } &__preview { min-height: 100px; - background-color: #161616; border-radius: 2px; padding: 5px 10px; overflow-y: auto; diff --git a/client/app/components/editor/editor.tsx b/client/app/components/editor/editor.tsx index c5a6af5..fae057c 100644 --- a/client/app/components/editor/editor.tsx +++ b/client/app/components/editor/editor.tsx @@ -5,15 +5,17 @@ import { ContentContainer } from '../content-container/content-container'; import './editor.scss'; interface Props { - categoryId: string; + categoryId?: string; onClose: (cancel: boolean) => any; + threadId?: string; } interface State { title: string; content: string; contentPreview: string; - characterCount: number; + contentCharacterCount: number; + titleCharacterCount: number; errorMessage?: string; } @@ -24,7 +26,8 @@ export class Editor extends React.Component { title: '', content: '', contentPreview: '', - characterCount: 0, + contentCharacterCount: 0, + titleCharacterCount: 0, }; } @@ -32,12 +35,48 @@ export class Editor extends React.Component { this.setState({ content: event.target.value, contentPreview: marked(event.target.value, { sanitize: true }), - characterCount: event.target.value.length, + contentCharacterCount: event.target.value.length, }); } - onSubmit() { + onTitleChange(event: any) { + this.setState({ + title: event.target.value, + titleCharacterCount: event.target.value.length, + }); + } + onSubmit(event: any) { + event.preventDefault(); + if (this.props.threadId) { + this.newReply(); + } else { + this.newThread(); + } + } + + async newReply() { + const { content } = this.state; + + if (content === '') { + this.setState({ errorMessage: 'Content must not be blank.' }); + return; + } + + const data = { + content, + thread_id: this.props.threadId, + }; + + try { + await axios.post('/api/reply', data); + this.props.onClose(false); + } catch (e) { + this.setState({ errorMessage: 'Server error. Please try again later.' }); + } + } + + async newThread() { const { title, content } = this.state; if (title === '' || content === '') { @@ -51,10 +90,6 @@ export class Editor extends React.Component { category_id: this.props.categoryId, }; - this.newThread(data); - } - - async newThread(data: any) { try { await axios.post('/api/thread', data); this.props.onClose(false); @@ -63,25 +98,46 @@ export class Editor extends React.Component { } } + renderThreadPortion() { + return ( +
+

New Topic

+ + this.onTitleChange(event)} + maxLength={300}/> +
{this.state.contentCharacterCount}/2000
+
+ ); + } + + // TODO: quote + renderReplyPortion() { + return ( +

New Reply

+ ); + } + render() { return (
- -

New Topic

- - this.setState({ title: event.target.value })}/> - -