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

Resources are shuffled on page load and a random button #106

Closed

Conversation

@makitsune
Copy link
Contributor

makitsune commented Oct 10, 2019

No description provided.

@makitsune makitsune changed the title Resources are shuffled on page load and a randomize button Resources are shuffled on page load and a random button Oct 10, 2019
Copy link
Owner

timdeschryver left a comment

I like the idea of a shuffle, but I would want to change the implementation.
We want to have the "add new resource" tile always to be as last.

What do you think about the following?

shuffle = new Subject();
  resources$ = this.routeQuery.pipe(
    map(query => {
      if (!query) {
        return resources;
      }

      const queryLower = query.toLowerCase();
      return resources.filter(resource =>
        resource.title.toLowerCase().includes(queryLower) ||
        resource.description.toLowerCase().includes(queryLower) ||
        resource.author.name.toLowerCase().includes(queryLower) ||
        resource.contributor.name.toLowerCase().includes(queryLower) ||
        resource.category.toLowerCase().includes(queryLower) ||
        resource.url.toLowerCase().includes(queryLower)
      )
    })
  );

  randomized$ = this.resources$.pipe(
    switchMap(resources => {
      return this.shuffle.pipe(
        startWith({}),
        map(() => resources.slice().sort(() => Math.random() - 0.5).concat(this.placeholder as any))
      )
    })
  )
@makitsune

This comment has been minimized.

Copy link
Contributor Author

makitsune commented Oct 12, 2019

Sure. I wasn't very sure how to best implement it since I dont use the async pipe

@timdeschryver

This comment has been minimized.

Copy link
Owner

timdeschryver commented Oct 13, 2019

Would you want to change the implementation to the proposed version?

@makitsune

This comment has been minimized.

Copy link
Contributor Author

makitsune commented Oct 14, 2019

Okay. When I have time today or tomorrow, ill update it

@timdeschryver

This comment has been minimized.

Copy link
Owner

timdeschryver commented Oct 26, 2019

I have added a change to randomize the resources when the page is opened, see the commit f34a868.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.