This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Edit Posts, Comments and Infinitely Scroll Posts in a Community #16
Conversation
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
I forgot to carry over the 'action' variable across to the redux store, which made the infinite scroll wouldn't work.
When scrolling for posts, the last fetch for data should have set the 'hasMore' to false, but didn't. Instead it would do another fetch and set it when the data was empty. Instead, the 'hasMore' should be set to false when the results are less than the limit for pagination.
Steem posts you authored can now be edited and resubmitted to the Steem blockchain.
When editing a post, but decided to not and cancel it, or to instead write a new post, there needed to be a way to clear the form data to start anew, without refreshing the page. Adding a clear button allows the page to be cleaned and ready for new data input.
The post editing was being done in the Write page. It seemed better to put the editing within the page itself, and not in the page where new posts are done to make it more clear where a user is.
Comments can now be edited and update the changes to the Steem blockchain.
When updating an edited comment, the child comments were lost. This was due to simply copying the updated comment fetch from Steem over the previous comment. When there were replies within the comment, they would be lose because the original comment fetching iterates to fetch child comments as long as there are some.
The fetching of individual communit data has been moved to Redux. After changing that, the infinite scroll was added to the individual community pages for pagination purposes.
When looking at another community page after already visiting one before, the previous page data was being shown. Adding a clear action to Redux to empty the groupData aobject resolved the issue.
The join communities functionality was moved to Redux as well.
On some pages that used the user name in order to get user related data, the returning user verification in Redux was being returned only after the data fetch was already sent. This made some data return as a not logged in user, when the user was. This was due to the asynchronous redux-thunk in the app. This has been corrected by checking if the redux store has the authenticated user, and if not, go get the username from the cookie instead of waiting for the asynchronous authentication.
The Home page also had the need for the user name. The previous fix is now applied to the Home page. The fix had an issue with non logged in user, as they had no cookie, thus the page would crash beacuse I wasn't testing for that, which I now do.
When editing a post and then going to write a new one, the post that was edited was staying in view, and the form was not appearing. Clicking on the Write a second time had the form appear and route change. I had to add a check for the reset flag in teh Write component to make sure the edit form fisplayed, rather than the redirect for the edited post.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What's new
To Edit a post, you just need to click on the pencil/compose icon at the bottom of a page. After clicking the Edit icon, you will be redirected to the
Write
component for the post in question. Underneath you will see the preview, just like you would be reading the post already posted. As you make changes, you will see them appear.It all starts with showing the Edit button, but only if the user logged is the author of the post.
Once the Edit icon is clicked, the Redux store received the call and parses the existing json_metadata into an array, and sets up the draft copy of the post for display. The flag
isUpdating
is set to true, which lets the other components know an edit is in process.Back in the post page you're looking at, the
isUpdating
flag lets the page know an update/edit is requested, and then redirects the user to theWrite
component via thewrite
route.Once in the Write page, the post data is populated into the form fields and text area, and the
Submit
button is changed toUpdate
. OnceUpdate
is clicked, Redux comes back into play by processing the form data, just as is done for a regular first-time post, except it posts after thecommentOp
is set the post is sent to Steem right away, withoutcommentOptions
being set.Editing a post is a crucial feature to have when submitting writing or any content to a site. Mistakes happen, and we don't want to see them there forever. Or maybe you just want to add more to the content. Regardless, KURE now offers the editing of posts and comments.
As you can see here, before, the end of the paragraph has a
-
from a previous test. You just need to click onEdit
to get started.The
EditForm
will open up with your comment, and then you can edit it.Hit
Update
and your edits will be updated on the post. While the edit is being processed and sent to Steem, you have a loading spinner to indicate something is going on.When the spinner goes away, your comment shows up with the new edits made.
The main action happens in the Redux action creator
editComment
. The newly edited body of the comment, as well as the original comment, are received for the comment updating process.From the previous comment data, the
category, permlink, author, parent_permlink, parent_author
are extracted and used for theSteemConnect.comment
function. Since there may be new images and whatnot added to the body of the comment, a newjson_metadata
is created.Sending all of that to the Steem blockchain, if successfully added, will return some data which include the block number. Once successful, the new comment data is obtained with
getComment
and then dispatched to the Redux store for use in the app once more.I also added the infinite scroll feature to the individual community pages, just like the Home and Kurated page. Now when you scroll down to view posts in a community, you will keep getting posts loaded for your viewing pleasure.
The fetch for data was moved to Redux, where the
hasMore
determines if new posts are to be fetched again when the user scrolls to the bottom of the current page of data.These individual community pages have the Join Community functionality, which requires being logged in. As such, the user name of the person is required in order to make a request. If the Redux authentication has not completed when the community page is the first page landed on for the app, then the username is obtained form the cookie. If there is no user, then a default of 'x' is used to mean not logged in.
Data is fetched, and added to the Redux store for use in the app. If the length of the resulting data fetched is less than the limit of posts to grab, this means there is no more data to fetch, and
hasMore
is set to false in order to stop the infinite scroll from even trying to get more data.Bug Fixes
There was a slight bug on the newly added infinite scroll functionality. Prior to moving the functionality to Redux, there was an
action
variable used to determine if the Steem page was initially getting data, or getting more data. When I moved more to Redux, I had forgotten to add that part of the code.The result was fetches for new page data, such as moving from Steem to Blog or Feed, would have the old page/route data on the page, with the new page data appended to it. Now when scrolling for posts
Now when fetching data, the more action is sent and actually used. Redux will only set the query author and permlink as the last ones in the page if more data is required. Otherwise, all fetches for data that don't have more requested will be treated as initial data requests and replace the older data.
When there was no more data to get on the KURE fetching for infinite scroll, the fetch was still trying one last time, needlessly, and requesting data which return no results. Then it would stop even trying. This was an extra step that wasn't needed and would show a loading symbol for nothing.
Correcting the conditions under which data is fetched to look if the limit was larger than the data retrieve and setting the
hasMore
to false corrected the issue.When writing a new post and looking at the preview, or looking at the post afterwards, if you had a string of characters that was larger than the container to display it, it would run off the container over flowing it. I only noticed this after I made a post with github commit links. Adding some CSS to wrap the overflow solved the issue.
When the editing comments functionality was done, I noticed an issue when looking at comments that had comments of their own.
When I was adding the new comment, I was simply replacing the data in the old comment, thereby erasing all the child replies added by the recursive fetch for comments. Instead, I added the old comment, and only added three new fields that were required:
When moving between community pages, the previous community data was being shown on the other with no new data being fetched. To fix that, I added a reducer to clear the community data on component unmount.
On some pages that used the user name in order to get user related data, the returning user verification in Redux was being returned only after the data fetch was already sent. This made some data return as a not logged in user, when the user was. This was due to the asynchronous redux-thunk in the app.
This has been corrected by checking if the redux store has the authenticated user, and if not, go get the username from the cookie instead of waiting for the asynchronous authentication. Now the Home, Steem and Community pages all work as designed with no issues of the redux authentication asynchronously finishing after the data fetching starts.
When editing a post and then going to write a new one, the post that was edited was staying in view, and the form was not appearing. Clicking on the Write a second time had the form appear and route change. I had to add a check for the reset flag in the Write component to make sure the edit form displayed, rather than the redirect for the edited post.