-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
175 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<%= react_component "RescriptShow", prerender: false %> | ||
<%= react_component "RescriptShow", prerender: true %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 60 additions & 64 deletions
124
client/app/bundles/comments/rescript/CommentForm/CommentForm.res
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,95 @@ | ||
let reducer = ( | ||
state: CommentFormTypes.state, | ||
action: CommentFormTypes.action | ||
state: CommentFormTypes.state, | ||
action: CommentFormTypes.action, | ||
): CommentFormTypes.state => { | ||
switch (action) { | ||
switch action { | ||
| SetAuthor(author) => {...state, author} | ||
| SetText(text) => {...state, text} | ||
| SetFormType(form) => {...state, form: form} | ||
| SetFormType(form) => {...state, form} | ||
} | ||
} | ||
|
||
|
||
@react.component | ||
let make = (~storeComment: ReScriptShowTypes.storeComment, ~disabled: bool, ~storeCommentError: bool) => { | ||
let make = ( | ||
~storeComment: ReScriptShowTypes.storeComment, | ||
~disabled: bool, | ||
~storeCommentError: bool, | ||
) => { | ||
let (state, dispatch) = React.useReducer( | ||
reducer, { | ||
reducer, | ||
{ | ||
author: "", | ||
text: "", | ||
form: Horizontal | ||
} | ||
form: Horizontal, | ||
}, | ||
) | ||
|
||
let handleAuthorChange = (event) => { | ||
let handleAuthorChange = event => { | ||
let value = ReactEvent.Form.currentTarget(event)["value"] | ||
SetAuthor(value)->dispatch | ||
} | ||
|
||
let handleTextChange = (event) => { | ||
let handleTextChange = event => { | ||
let value = ReactEvent.Form.currentTarget(event)["value"] | ||
SetText(value)->dispatch | ||
} | ||
|
||
let handleSubmit = (event) => { | ||
let handleSubmit = event => { | ||
ReactEvent.Form.preventDefault(event) | ||
storeComment({author: state.author, text: state.text}) | ||
} | ||
|
||
let forms: array<CommentFormTypes.formData> = | ||
[ | ||
let forms: array<CommentFormTypes.formData> = [ | ||
{formName: "Horizontal Form", formType: Horizontal}, | ||
{formName: "Inline Form", formType: Inline}, | ||
{formName: "Stacked Form", formType: Stacked} | ||
{formName: "Stacked Form", formType: Stacked}, | ||
] | ||
|
||
<div> | ||
<div className="flex gap-1 not-prose"> | ||
{ | ||
forms | ||
->Array.map(form | ||
=> ( | ||
<button | ||
key={`form_${form.formName}`} | ||
className={`px-6 py-2 font-semibold border-0 rounded ${state.form == form.formType ? "text-sky-50 bg-sky-600" : "text-sky-600 hover:bg-gray-100"}`} | ||
onClick={event => SetFormType(form.formType)->dispatch} | ||
> | ||
{form.formName->React.string} | ||
</button> | ||
) | ||
)->React.array | ||
} | ||
{forms | ||
->Array.map(form => | ||
<button | ||
key={`form_${form.formName}`} | ||
className={`px-6 py-2 font-semibold border-0 rounded ${state.form == form.formType | ||
? "text-sky-50 bg-sky-600" | ||
: "text-sky-600 hover:bg-gray-100"}`} | ||
onClick={event => SetFormType(form.formType)->dispatch}> | ||
{form.formName->React.string} | ||
</button> | ||
) | ||
->React.array} | ||
</div> | ||
<hr /> | ||
{ | ||
switch state.form { | ||
| Horizontal | ||
=> <HorizontalForm | ||
author={state.author} | ||
handleAuthorChange | ||
text={state.text} | ||
handleTextChange | ||
handleSubmit | ||
disabled | ||
/> | ||
| Stacked | ||
=> <StackedFrom | ||
author={state.author} | ||
handleAuthorChange | ||
text={state.text} | ||
handleTextChange | ||
handleSubmit | ||
disabled | ||
/> | ||
| Inline | ||
=> <InlineForm | ||
author={state.author} | ||
handleAuthorChange | ||
text={state.text} | ||
handleTextChange | ||
handleSubmit | ||
disabled | ||
/> | ||
} | ||
} | ||
|
||
{ | ||
storeCommentError ? <AlertError errorMsg="Can't store the comment!" /> : React.null | ||
} | ||
{switch state.form { | ||
| Horizontal => | ||
<HorizontalForm | ||
author={state.author} | ||
handleAuthorChange | ||
text={state.text} | ||
handleTextChange | ||
handleSubmit | ||
disabled | ||
/> | ||
| Stacked => | ||
<StackedFrom | ||
author={state.author} | ||
handleAuthorChange | ||
text={state.text} | ||
handleTextChange | ||
handleSubmit | ||
disabled | ||
/> | ||
| Inline => | ||
<InlineForm | ||
author={state.author} | ||
handleAuthorChange | ||
text={state.text} | ||
handleTextChange | ||
handleSubmit | ||
disabled | ||
/> | ||
}} | ||
{storeCommentError ? <AlertError errorMsg="Can't store the comment!" /> : React.null} | ||
</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 11 additions & 18 deletions
29
client/app/bundles/comments/rescript/CommentForm/forms/HorizontalForm.res
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.