Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/css/card.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/card.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 36 additions & 1 deletion resources/js/components/ResourceNavigationLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,49 @@
</template>

<script>
import { ref, onMounted, onUnmounted } from 'vue';

export default {
props: [ 'card' ],
setup() {
const currentSearch = ref(window.location.search);

const checkSearchChange = () => {
const search = window.location.search;
if (currentSearch.value !== search) {
currentSearch.value = search;
}
};

const decodeFilters = (link) => {
const params = new URLSearchParams(currentSearch.value);
const encoded = params.get(`${link.uriKey}_filter`);
return encoded ? JSON.parse(atob(encoded)) : null;
};

const isLinkActive = (link) => {
const filters = decodeFilters(link);
if (!filters || !link.activeFilter || !link.activeValue) return window.location.pathname.endsWith(link.url);
return filters.some(filter => {
const key = Object.keys(filter)[0];
const value = filter[key];
return key === link.activeFilter && value == link.activeValue;
});
};

onMounted(() => {
Nova.$on('filter-changed', checkSearchChange)
Nova.$on('filter-reset', checkSearchChange)
});

onUnmounted(() => {
Nova.$off('filter-changed', checkSearchChange)
Nova.$off('filter-reset', checkSearchChange)
});

return {
component: link => link.external ? 'a' : 'Link',
active: link => window.location.pathname.endsWith(link.url),
active: link => isLinkActive(link),
target: link => link.openInNewTab ? '_blank' : '_self'
}

Expand Down
Loading