Skip to content

feat: add card pinning and keep pinned results at top#682

Open
akash-belide wants to merge 1 commit into
masterfrom
card-pinning
Open

feat: add card pinning and keep pinned results at top#682
akash-belide wants to merge 1 commit into
masterfrom
card-pinning

Conversation

@akash-belide

Copy link
Copy Markdown
Contributor

Fixes #659

Summary: Adds card pinning from the card list and ensures pinned entities stay visible at the top of filtered results.

Changes

  • User experience

    • Added a floating pin button to cards
    • The pin button appears when the card is hovered or when the card is already pinned.
    • Added hover text for Pin to the page and Unpin from the page.
    • Pinned cards keep the pin button visible.
    • Hovering over the pin button on a pinned card switches the icon from PinIcon to PinOffIcon.
  • Logical changes

    • Pinned entities bypass active filters.
    • Pinned entities remain visible even when the current search or filters would normally hide them.
    • Pinned entities are sorted to the front
    • Pinned entities preserve the order stored in the pinned page param.
    • Non-pinned entities continue to follow the normal sort order.

Screenshots

  • Pinned
image
  • Pinned entities bypass active filters
image
  • Hover text for Pin to the page and Unpin from the page
image image

@akash-belide akash-belide requested a review from a team as a code owner June 19, 2026 01:30
@github-actions

Copy link
Copy Markdown
Contributor

Cloudflare Pages preview

@conradarcturus conradarcturus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It functions well!

I left some comments but they aren't blocking -- I'll leave it to your judgment.

const bPinned = bIndex !== -1;
// Pinned entities always come first, in the order they were pinned, so they
// reliably stay at the top (and on the first page) across refreshes.
if (aPinned && bPinned) return aIndex - bIndex;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nice, I didn't expect this but it makes sense to use the pin array to decide the order of the pins. Originally I had thought it would stay in sorted order amongst the pins, but this makes sense too.

tabIndex={0}
>
{showPinButton && (
<HoverableButton

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot of markup, it would probably be best to move this to its own class CardPinButton

<span
aria-label={isPinned ? 'Unpin from the page' : 'Pin to the page'}
onMouseEnter={() => setIsHoveringPin(true)}
onMouseLeave={() => setIsHoveringPin(false)}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably all these as parameters to HoverableButton, but..

For this button it may be better to be completely different and actually not use HoverableButton. One advantage of the other hoverable buttons is that uses CSS hover to color the button. but since you hardcoded the background we cannot switch the background color to the usual hover state (blue bg white foreground). The background is nice because it gives a wider click area. I do agree that given its role when its not in a hover state it is better transparent.

So 1 options 1) change the background color & foreground color when isHovering or 2) move most of the styling to CSS. You already gave it a class name, you can also append a class when its pinned (eg. className={'CardPinButton' + (isPinned ? ' pinned' : '')}.


const isPinned = pinned.includes(object.ID);
const togglePin = useCallback(() => {
updatePageParams({

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the card moves it stays in the hover state which is odd (however if the card did not move then this is wrong).

Hmmm, I think we may want to control colors with CSS -- I mentioned later that you can either use isHoveringPin to make more fine-grained controls but I notice that this doesn't fix all the rendering bugs (cards stay hovered even when it moves away from the cursor because the mouseLeave event did not trigger).

I think the css :hover attribute is more accurate than what we are doing now.

Suggested change
updatePageParams({
setIsHoveringPin(false);
updatePageParams({

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pins: Add to CardList UI

2 participants