Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildTimelineItem (seen) does not work properly #123

Open
ezzypzzy opened this issue Jul 16, 2021 · 1 comment
Open

buildTimelineItem (seen) does not work properly #123

ezzypzzy opened this issue Jul 16, 2021 · 1 comment
Labels

Comments

@ezzypzzy
Copy link

Hello Ramon, fantastic little library you've made here. Thanks :)
I think 've encountered a bug.

As documented in stories structure,
there is a key (seen: false, // set true if user has opened)

When in array of stories I put seen: true for one out of 5 stories (say for id="ramon").
I expect its ring to discolor & the story to go last.
zuck_expected

Outcome observed: Story does go to last but the ring is not discolored as class "seen" is not added.
zuck_bug

@ezzypzzy
Copy link
Author

ezzypzzy commented Jul 16, 2021

I patched together a fix in my code, sharing here.

In \src\zuck.js make changes to reflect accordingly in \dist\zuck.js (webpack)

Underneath
/* api */ zuck.data = option('stories') || {};
I created an array containing id of stories that have set key seen: true
const seenStoryIdsArr = zuck.data.filter(function(obj){ return obj.seen == true }).map(function(story){ return story.id; });

This I then pass the array variable as a second argument to function getLocalData wherever it is called, such as
zuck.internalData.seenItems = getLocalData('seenItems', seenStoryIdsArr) || {};

This function I then define as
const getLocalData = function (key, seenStoryIdsArr) { if (option('localStorage')) { const keyName = zuck-${id}-${key}`;

    return window.localStorage[keyName]
      ? JSON.parse(window.localStorage[keyName])
      : false;
  } else {
    // return false;
    const seenStoryIdsObj = {};
    for(var i=0;i<seenStoryIdsArr.length;i++){
      var keyName = seenStoryIdsArr[i];
      seenStoryIdsObj[keyName] = true;
    }
    return seenStoryIdsObj;
  }
};`

P.S. The code works just fine if key localStorage: true

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

No branches or pull requests

2 participants