Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

user favourite items

Hi guys,

I have a list on the 'homepage' that is viewable by all users. I've added a button to the list that when clicked saves the listitem values to storage variables, then invokes a create service that uses those storage variables to adds the item to a new collection called 'favourite items'. These items are then mapped to a 'favourites' list on the users 'Profile' page. The 'favourites' list on the 'Profile' page uses access token so the favourites are unique to each user. Theres also a 'delete' button on the 'favourite' list that invokes a delete service that removes items from the 'favourites' list.

This is all working but I'm looking to make it a bit more user friendly.
Im wanting to have a button/toggle/checkbox on the homepage list which indicates whether the item is on the users favourite list or not. For example, having a toggle that would add the item to the 'favourite' list if toggled 'On'. if toggled 'Off' it will delete the item from favourites. This way when users return to the homepage list they can see if an item is in their 'favourites' or not.
At the moment it just shows an 'Add' button that just adds the item to the 'favourite' collection. It doesnt indicate if the items been added or not.

Homepage:
Image

Profile:
Image

Is it possible this way?
Or is there a better solution/method?

Thanks

Xavier U
Posts: 0
Joined: Tue Oct 14, 2014 3:53 pm

user favourite items

Hello, I wish I had an answer for your question, but I was wondering if you could explain how you created the favorites thus far? I'm trying to do a similar thing and am really struggling. Thank you!

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

user favourite items

Hello,

Once your favorite items are already stored in the storage variable, if they are in local storage, you can when rendering the list of all items check each item during mapping to find it in the favorites list in local storage, if yes, then you should do something with this (add the class or toggle, etc).

And when you click on the item itself you should check the condition of what you have added, for example, if you added the class, then check whether this string has the added class, if yes, then you need to remove the item from the favorites, if not, add.

Plus during the mapping you can add logic of visible for 2 buttons (add and remove) and show only one of them, depending on whether the item in the favorites list

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

user favourite items

Hi Xavier U

This video helped me a lot in understanding User registration and how users can access items in a collection that are unique to them.

https://www.youtube.com/watch?v=ikf0-...

what i did is change the way the create service is invoked. on favouritebutton click I used local storage to save the item name and id, and then invoked the create service, mapping the local storage variables to the correct fields in the collection.

Joe

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

user favourite items

Hi Evgene,

At the moment I have 2 LSV's for this. favouriteitemName, and favouriteitemId.
Once an item from the list is clicked to be added to the 'favourite' list the lsv change. Therefore i could favourite 4 items in the list, yet only the most recently added one will be saved in the LSV. So when the list renders and checks the LSV then it will only work for the most recently added. If i was to create more LSV to solve this how would I map this to multiple variables?

I'm sorry I don't understand exactly what you mean in the 2nd paragraph.

I understand what you mean in the 3rd paragraph but I'm not sure how to do it.

Thanks,
Joe

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

user favourite items

Hi Joe,

Please use models and storage to save an array of selected records:
http://devcenter.appery.io/documentat...

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

user favourite items

Thank you Kateryna

I have read the documentation and implemented the correct model and local storage.

in Evegenes first reply, he said 'when rendering the list of all items check each item during mapping to find it in the favorites list in local storage, if yes, then you should do something with this (add the class or toggle, etc). '
I understand this but don't know how to do it.
How would I do this?

Thanks,
Joe

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

user favourite items

Hi Joe,

For example: I have a local storage array:

Image

In the beginning I have an only entry in it, this is a string "Arizona".

I map data like this:

Image

Please note that I mapped state name to the Label 'text' property and Toggle 'toggled' property.

For Toggle I added the following code: prevar lsData = Appery.storage.qwe.get();
if ( _.contains( lsData, value ) ) {
return true;
}

return false;/preSo, when the mapped value is found in local storage then 'toggled' will be set to 'true'.

This is how you can display that the item is already in 'favorite' list.

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

user favourite items

Hi Kateryna,

I followed your steps but couldnt get it to work.

My storage is a little different, I have a model that has the item type 'favourite'.

Image

How would I change the code if I want to check if the 'Source_Id' already exists in the 'favourite' collection?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

user favourite items

Hi Joe,

Try this code please:prevar lsData = Appery.storage.LSVNAME.get();
if ( .findWhere( lsData, { Source_Id: value } ) ) {
return true;
}
return false;/pre

Return to “Issues”