0

I have a users model which fetches data from github users api (https://api.github.com/users). While displaying the list there is a add button which should add the user to a shortlist section below and which has a remove button to remove user from shortlist. I don't have api to save shortlist data. What is the best approach to make this work?

Try 1: Created a shortlist model and used store.push

this.store.push({
    data: [{
        id: user.id,
        type: 'shortlist',
        attributes: {
        login: userData.login,
        avatar_url: userData.avatar_url,
        type: userData.type
        }
    }]
});

and used item.unloadRecord(); to remove from model. But did nor found a way to fetch all record and show as this.store.peakAll('shortlist') wasen't working.

Try 2: Used localstorage to add user to shortlist, display and remove but here it needs page reload to display the add/remove changes as i used setupController to get the items from localstorage.

Please suggest how to do this in best possible way.

Sajal
  • 1,198
  • 1
  • 17
  • 32
  • Are you using Ember Data? Do you want to persist the data in users browser or is this state only needed for running instance? Should it be synchronized between different tabs? There are a lot of details missing. – jelhan Dec 09 '18 at 19:01
  • Yes i want user data to persist as when switch between routes, data should show. And for this requirement i am not sure how can use ember data as i don't have backend api to save this shortlist. – Sajal Dec 10 '18 at 05:21
  • Both approaches should work, although I do recommend the second. Please post the code from your model definition as well as your route so we can see what might be going wrong. – Gaurav Dec 10 '18 at 08:26
  • plz check here - https://github.com/sajaldas/gitusers/blob/master/app/routes/users.js – Sajal Dec 10 '18 at 08:38
  • Possible duplicate of [Persist variables between page loads](https://stackoverflow.com/questions/29986657/persist-variables-between-page-loads) – Liam Dec 10 '18 at 09:21
  • You could also use https://www.ember-cli-mirage.com/ in production – Patsy Issa Dec 10 '18 at 13:10
  • there is also this: https://github.com/genkgo/ember-localforage-adapter/ – NullVoxPopuli Dec 10 '18 at 15:46

0 Answers0