Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Fix Keep message drafts #1459 #1891

Closed
wants to merge 4 commits into from

Conversation

Gerald1614
Copy link

Closes ___ (e.g. #230)

What does this PR do?

use localStorage to keep draft of messages (wall and pickups messages) even if page is refreshed. The Key refers to the ConversationId and the value to the messsage. The key-value pair is destroyed only when the draft is submited, or the user voluntary quit the page or escape the form.

(briefly describe what this PR is about)

Links to related issues

[https://github.com//issues/1459]
)## Checklist

  • added a test, or explain why one is not needed/possible...
  • no unrelated changes
  • asked someone for a code review
  • joined #karrot-dev channel at https://slackin.yunity.org
  • added an entry to CHANGELOG.md (description, pull request link, username(s))

@codecov
Copy link

codecov bot commented Nov 19, 2019

Codecov Report

Merging #1891 into master will decrease coverage by 0.1%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1891      +/-   ##
==========================================
- Coverage   60.54%   60.44%   -0.11%     
==========================================
  Files         269      269              
  Lines        5566     5577      +11     
  Branches      901      903       +2     
==========================================
+ Hits         3370     3371       +1     
- Misses       2195     2205      +10     
  Partials        1        1
Impacted Files Coverage Δ
src/messages/components/ConversationMessage.vue 100% <ø> (ø) ⬆️
src/messages/components/WallConversation.vue 100% <ø> (ø) ⬆️
src/messages/components/ChatConversation.vue 65.93% <ø> (-0.38%) ⬇️
src/messages/components/ConversationCompose.vue 31.81% <33.33%> (-18.19%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3a8a3da...c10add0. Read the comment docs.

Copy link
Member

@tiltec tiltec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that should work! I left some comments.

Another option that seems a bit more in line with the Karrot architecture would to sync message drafts to the conversations vuex datastore and use vuex-persistedstate to sync it to localStorage. We already have a 'persistedState' config that could be extended: https://github.com//yunity/karrot-frontend/blob/master/src/base/datastore/persistedState.js
Would you be interested in implementing this approach?

if (this.key) {
return this.key
}
else return 'wallConv'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be a special case, wall conversations have an ID as well. You can pass it from WallConversation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i will modify that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact, i could get conversationId from editing an existing message but for the one on the top which enables to create a new message, we need an identifier. but what I did was seting the key in the parent component so in my new version it is consistent to just return the key.

},
onFocus (event) {
this.hasFocus = true
},
onBlur () {
this.hasFocus = false
this.message = ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems unexpected to delete the message on blur!

@@ -93,6 +93,9 @@ export default {
type: String,
default: null,
},
conversation: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the prop should be named conversationId, to avoid confusion with a complete conversation object.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

hasFocus: false,
key: this.conversation,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not reactive: if conversation ID gets loaded lazily (i.e. after this component initializes) or changes, key will be invalid.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed I switched that to a computed prop

},
leaveEdit () {
this.$emit('leaveEdit')
this.message = ''
localStorage.removeItem(this.getkey())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a small bug in this: it would delete a message draft from localStorage when editing a previous message in the same conversation.

For example, I start writing a new message to you, then edit an old message in our conversation but abort editing and close my browser. I would expect the new message to still exist when I open the browser again.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the wall there is a cancel button that user can use to cancel the editing and then accept the draft to be deleted but on pickup messages the only way to cancel is to press the escape button. I think it would make sense to add a button here and in such case, I agree this deletion is not necessary. but without this button, i guess most users will just leave the draft thinking that it would cancel the draft. It is more a UX question

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you are referring to: as far as I know, the "cancel edit" button shown in both WallConversation and ChatConversation.

@Gerald1614
Copy link
Author

HI @tiltec I just pushed a new commit that addresses most of the points mentioned. I unfied the way we handle the conversationId, even for wall conversation. I kept a 'wallConv, key to keep the draft of new wall conversation( no iD as long as message is not submitted). I kept the deletion of the draft on Leave, because it is the only way to delete the draft. As explained earlier it is a UI decision, you can remove if your prefer, but that would involve the localstorage will never get cleaned. I will want on an alterbative leveraging vuex and vuex-persistant as you mentioned, but I not sure it is a good idea as the data is really used only in a single component (ConversationCompose). I wanted to finalise his PR so at leats we have something that works. as of now people can also edit existing messages. the message showing on the page is the one that is coming from backend, but if they come back to finalise an edit they started earlier, this draft will be used in the edit form. it is only if they submit that the draft will replace previous message. Please test it and let me know if it does the job.

@tiltec
Copy link
Member

tiltec commented Nov 21, 2019

I kept a 'wallConv, key to keep the draft of new wall conversation( no iD as long as message is not submitted).

There's more than one wall: each group and each place has one. You implemented it in a way that would remember one message draft for walls, no matter where the user originally typed it in.
I think that's sligthly confusing to users and rather unexpected to both developers and users - what do you think? It should be possible to use conversation ID as well, it exists already for empty walls.

@Gerald1614
Copy link
Author

Gerald1614 commented Nov 21, 2019

@tiltec Thanks for your feedback, In fact I am using conversation in all the places. as of today, I saw usage of ConversationCompose on the wall and in pickups. for both of them I am using the conversationId so it is universal and it wil store all drafts based on this conversationId. but if you look at the top of the wall page, users can enter directly in Converation compose to edit a new conversation. This conversation can not have an idea because it is not yet part of any conversation. this is only for this one that i created the wallConv. if people edit an existing conversation or add new comment on an existing conversation, the feature will save the draft based on its conversationId. because local storage is used, the draft will be saved only for this specific user (and specific device in fact) so there is no conflict with other groups or places. But if it happens that users are part of different groups or places then I would have to use the groupId and PlaceId in my key used in local storage. that would be easy to implement

@github-actions
Copy link

This pull request is marked as stale because it has not had any activity for 90 days, remove the stale label or add a comment on it, otherwise it will be automatically closed in 7 days. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants