Add user search at #2119

Closed
wyatt777 wants to merge 8 commits from gitlab-mr-iid-852 into develop
Member

For issue #562

For issue #562
Member

probably should throttle/debounce the dispatch so that it doesn't get sent too frequently

probably should throttle/debounce the dispatch so that it doesn't get sent too frequently
Author
Member

I added debounce for this.

It might be good to add debounce or throttle as an option in the api. services/new_api/utils.js might be one place.

I added debounce for this. It might be good to add debounce or throttle as an option in the api. `services/new_api/utils.js` might be one place.
Member

why

why
Author
Member

?? More details ??

Following the design pattern that already exists in the same file.

suggestor.js has no reference to this.$store. Need it for userSearch dispatch.

statusPoster in the same file, has the same design pattern. Store is passed to dispatch addNewStatuses.

?? More details ?? Following the design pattern that already exists in the same file. `suggestor.js` has no reference to `this.$store`. Need it for userSearch dispatch. `statusPoster` in the same file, has the same design pattern. Store is passed to dispatch addNewStatuses.
Member

you're passing entire vuex store into suggestor, de-facto making it dependent on it. This is just bad architectural design. Better solution would be to make users property take usersList and usersFindFunction

you're passing **entire** vuex store into suggestor, de-facto making it dependent on it. This is just bad architectural design. Better solution would be to make `users` property take `usersList` and `usersFindFunction`
Member

also this only affects post form, should also affect bio input

also this only affects post form, should also affect bio input
Author
Member

Image_2019-07-12_at_11.04.18_AM

In the same file the exact same thing is already occurring elsewhere. That should be changed too?

![Image_2019-07-12_at_11.04.18_AM](/attachments/254471bb-22b9-4365-9a6e-712b350c431e) In the same file the exact same thing is already occurring elsewhere. That should be changed too?
Author
Member

Here is a comparative flow:

statusPoster passes the entire vuex store. It (dispatches) -> addNewStatuses which depends on the store.

emojiUserSuggestor passes the entire vuex store.. It (dispatches) -> searchUsers which depends on the store.

modules/users.js already defines searchUsers which does exactly what we want.

Here is a comparative flow: statusPoster passes the **entire** vuex store. It (dispatches) -> addNewStatuses which depends on the store. emojiUserSuggestor passes the **entire** vuex store.. It (dispatches) -> searchUsers which depends on the store. `modules/users.js` already defines `searchUsers` which does exactly what we want.
Author
Member

added!

added!
Member

oh boy, time for git blame!

oh boy, time for git blame!
Member

yeah, it's the oldest code, and it's certainly not the way to go IMO. For post_status_form it should've been something like

onMakePost: (data) => store.dispatch('addNewStatuses', {
  statuses: [data],
  timeline: 'friends',
  showImmediately: true,
  noIdUpdate: true // To prevent missing notices on next pull.
})
yeah, it's the oldest code, and it's certainly not the way to go IMO. For post_status_form it should've been something like ```js onMakePost: (data) => store.dispatch('addNewStatuses', { statuses: [data], timeline: 'friends', showImmediately: true, noIdUpdate: true // To prevent missing notices on next pull. }) ```
Member

for emoji suggestor is should be something like

{
  emoji: [
    ...this.$store.state.instance.emoji,
    ...this.$store.state.instance.customEmoji
  ],
  users: {
    list: this.$store.state.users.users,
    updateList: (input) => data.store.dispatch('searchUsers', input)
  }
}

although ideally i'd make emoji suggestor asynchronous and make it use results from request directly, but it could be next step.

for emoji suggestor is should be something like ```js { emoji: [ ...this.$store.state.instance.emoji, ...this.$store.state.instance.customEmoji ], users: { list: this.$store.state.users.users, updateList: (input) => data.store.dispatch('searchUsers', input) } } ``` although ideally i'd make emoji suggestor asynchronous and make it use results from request directly, but it could be next step.
Author
Member

Cool! Yes git blame. Want to keep it in the order that is already established, possibly multiple places in the code that are using the same logic and changing that deserves a discussion.

Cool! Yes git blame. Want to keep it in the order that is already established, possibly multiple places in the code that are using the same logic and changing that deserves a discussion.
Member

I can see the concerns here.
hj wants to nicely abstract that logic (data.store.dispatch('searchUsers', input)) away from suggestor.js and make the updating logic available and customizable on-demand to any component that needs it that makes sense to me. 👍

@wyatt777 It'd be great if you can follow the pattern so suggestor.js doesn't need to know the whole vuex store logic. Otherwise, we can just pass this.$store only and destructure everything in suggestor.js. 😉

As you mentioned, we have duplicated logics of emojiUserSuggestor and emojiSuggestor in two places. We definitely want abstraction that allows us to define emojiUserSuggestor and emojiSuggestor in a single place and share it across many components, but we can try it in another MR later.

I can see the concerns here. hj wants to nicely abstract that logic (`data.store.dispatch('searchUsers', input)`) away from `suggestor.js` and make the updating logic available and customizable on-demand to any component that needs it that makes sense to me. :thumbsup: @wyatt777 It'd be great if you can follow the pattern so `suggestor.js` doesn't need to know the whole vuex store logic. Otherwise, we can just pass `this.$store` only and destructure everything in `suggestor.js`. :wink: As you mentioned, we have duplicated logics of `emojiUserSuggestor` and `emojiSuggestor` in two places. We definitely want abstraction that allows us to define `emojiUserSuggestor` and `emojiSuggestor` in a single place and share it across many components, but we can try it in another MR later.
Author
Member

Hi @tae ! Yes I agree with the changes and will do a push with them for my function.

For future proofing:
I think doing it right once across the whole code base is better than choosing one place randomly. If there are multiple objects passing the $store there should be an issue that looks into that specifically and makes the code have consistent treatment of them.

Hi @tae ! Yes I agree with the changes and will do a push with them for my function. For future proofing: I think doing it right once across the whole code base is better than choosing one place randomly. If there are multiple objects passing the `$store` there should be an issue that looks into that specifically and makes the code have consistent treatment of them.
Member

lgtm

lgtm
Member
  1. update the comment above so that it also explains it
  2. naming - it's not obvious from the name that updateList updates list of users. should either be a property of data.users or something like updateUsersList
  3. make it optional so that it doesn't explode when it's not defined?
1. update the comment above so that it also explains it 2. naming - it's not obvious from the name that `updateList` updates list of users. should either be a property of `data.users` or something like `updateUsersList` 3. make it optional so that it doesn't explode when it's not defined?
Member

other than that - lgtm

other than that - lgtm
Author
Member

1,2 & 3. Pushed.

1,2 & 3. Pushed.
Member

data.users.indexOf(input) === -1

will not work. input is string, data.users is array of objects, it will always be true and always iterate over entire array.

`data.users.indexOf(input) === -1` will not work. `input` is string, `data.users` is array of objects, it will always be true and always iterate over entire array.
Author
Member

@hj Thank you. Will fix it and re-push.

@hj Thank you. Will fix it and re-push.
Author
Member

@hj I pushed again with the changes. Not sure how much this is needed. It only blocks if there is an exact match within data.users. Maybe there should be an array with all inputs that were already searched and block them all?

@hj I pushed again with the changes. Not sure how much this is needed. It only blocks if there is an exact match within data.users. Maybe there should be an array with all inputs that were already searched and block them all?
Member

maybe it should be moved into suggestUsers which does all the necessary filtering already?

maybe it should be moved into `suggestUsers` which does all the necessary filtering already?
Author
Member

Thanks. It will only search if there are no matches from suggestUsers now.

Thanks. It will only search if there are no matches from `suggestUsers` now.
Member

works for me

works for me

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pleroma/pleroma-fe!2119
No description provided.