-
Notifications
You must be signed in to change notification settings - Fork 6
Nested comments #109
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
Open
amyhuycu
wants to merge
17
commits into
master
Choose a base branch
from
ac-nested-comments
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Nested comments #109
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
485b237
sample comment
amyhuycu 8f389bd
Merge branch 'master' into ac-nested-comments
amyhuycu af10838
wip, error message if not logged in, wip for input box
amyhuycu 9148d36
wip with editor box, todo find how to update content of each comment …
amyhuycu 3d1486c
wip toggle for ReplyTo button to have a text Editor box; TODO: post t…
amyhuycu 2cf5704
wip, TODO: post ReplyTo comments under its parent comment, not under …
amyhuycu 2b28c8c
wip, not working
amyhuycu c72dbfc
wip, not yet working
amyhuycu c3d239e
toggles editor box for all comments ReplyTos at once with useState
amyhuycu 6f547c4
mild cleanup
amyhuycu 244837d
some wip for toggling show/hide EditorBox
amyhuycu 91e1e2e
comments under the correct nested comment
amyhuycu 493a021
Hide Editor option works with lagging, cleanup code and comments adde…
amyhuycu 45eea9d
only opens one editor box at a time
amyhuycu 2b469bb
removed print stmts / comments
amyhuycu 9659058
closes editor box after submit
amyhuycu 0af23ab
cleaned up code
amyhuycu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Based on CommentInput.tsx | ||
|
||
import axios from "axios"; | ||
import { useRouter } from "next/router"; | ||
import React from "react"; | ||
import useSWR, { trigger } from "swr"; | ||
|
||
import checkLogin from "../../lib/utils/checkLogin"; | ||
import { SERVER_BASE_URL } from "../../lib/utils/constant"; | ||
import storage from "../../lib/utils/storage"; | ||
|
||
|
||
import { Form, Button, Input} from 'antd'; | ||
const { TextArea } = Input; | ||
|
||
var clickedSubmit = false; | ||
|
||
const Editor = ( { onChange, onSubmit, submitting, value } ) => ( | ||
<> | ||
<Form.Item> | ||
<TextArea rows={4} onChange={onChange} value={value} /> | ||
</Form.Item> | ||
<Form.Item> | ||
<Button htmlType="submit" loading={submitting} onClick={onSubmit} type="primary"> | ||
Add Comment | ||
</Button> | ||
</Form.Item> | ||
</> | ||
) | ||
|
||
const EditorBox = ( props ) => { | ||
const { data: currentUser } = useSWR("user", storage); | ||
const isLoggedIn = checkLogin(currentUser); | ||
const router = useRouter(); | ||
const { | ||
query: { pid }, | ||
} = router; | ||
|
||
const [content, setContent] = React.useState(""); | ||
const [isLoading, setLoading] = React.useState(false); | ||
|
||
clickedSubmit = false; | ||
|
||
const handleChange = React.useCallback((e) => { | ||
setContent(e.target.value); | ||
}, []); | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
setLoading(true); | ||
await axios.post( | ||
`${SERVER_BASE_URL}/articles/${encodeURIComponent(String(pid))}/comments`, | ||
JSON.stringify({ | ||
comment: { | ||
body: content, | ||
comment_id: props.commentId, | ||
}, | ||
}), | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Token ${encodeURIComponent(currentUser?.token)}`, | ||
}, | ||
} | ||
); | ||
setLoading(false); | ||
setContent(""); | ||
trigger(`${SERVER_BASE_URL}/articles/${pid}/comments`); | ||
|
||
// This editor box has been submitted, so set the CommentID to -1 to hide the editor box | ||
props.handleClick("-1"); | ||
|
||
}; | ||
|
||
if (!isLoggedIn) { | ||
return ( | ||
null | ||
); | ||
|
||
} else { // is Logged In | ||
return ( | ||
<Editor | ||
onChange={ handleChange } | ||
onSubmit={ handleSubmit } | ||
submitting = { isLoading } | ||
value={ content } | ||
/> | ||
); | ||
} | ||
|
||
}; | ||
|
||
export default EditorBox; |
This file contains hidden or 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 |
---|---|---|
|
@@ -21,4 +21,4 @@ export type Author = { | |
|
||
export type CommentChildren = { | ||
comments: CommentType[]; | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the comment is made the editor should close