Skip to content

Commit

Permalink
Merge pull request #766 from MuckRock/762-project-pin
Browse files Browse the repository at this point in the history
Disable project pin if project.edit_access is false
  • Loading branch information
eyeseast authored Oct 8, 2024
2 parents 456c264 + ff62907 commit 25f70d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/common/Pin.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
</script>

<button
{disabled}
class="pin"
class:active
class:disabled
on:click|stopPropagation|preventDefault
style={cssVarStyles}
on:click|stopPropagation|preventDefault
>
<Pin {title} {size} />
</button>
Expand Down
23 changes: 14 additions & 9 deletions src/lib/components/projects/ProjectPin.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,31 @@
e.preventDefault();
const csrf_token = getCsrfToken();
const newPinnedState = !project.pinned;
let error: unknown;
({ data: project, error } = await pinProject(
const { data, error } = await pinProject(
project.id,
newPinnedState,
csrf_token,
));
);
if (error) {
project.pinned = !project.pinned;
console.error(error);
} else {
project = data;
await invalidate(canonicalUrl(project));
}
// now that we've updated, set $pinned
$pinned = project.pinned
? sortPins([...$pinned, project])
: $pinned.filter((a) => a.id !== project.id);
// now that we've updated, set $pinned
$pinned = project.pinned
? sortPins([...$pinned, project])
: $pinned.filter((a) => a.id !== project.id);
}
}
</script>

<Pin active={project.pinned} on:click={toggle} {size} />
<Pin
active={project.pinned}
{size}
disabled={!project.edit_access}
on:click={toggle}
/>

0 comments on commit 25f70d8

Please sign in to comment.