2022-12-17 01:30:02 +01:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { FavoriteFilled } from '@vicons/material';
|
2023-06-10 17:14:50 +02:00
|
|
|
|
2022-12-17 01:30:02 +01:00
|
|
|
import { useToolStore } from '@/tools/tools.store';
|
|
|
|
import type { Tool } from '@/tools/tools.types';
|
2023-05-28 23:13:24 +02:00
|
|
|
|
|
|
|
const props = defineProps<{ tool: Tool }>();
|
2022-12-17 01:30:02 +01:00
|
|
|
|
|
|
|
const toolStore = useToolStore();
|
|
|
|
|
|
|
|
const { tool } = toRefs(props);
|
|
|
|
|
|
|
|
const isFavorite = computed(() => toolStore.isToolFavorite({ tool }));
|
|
|
|
const buttonType = computed(() => (isFavorite.value ? 'primary' : 'default'));
|
|
|
|
|
|
|
|
function toggleFavorite(event: MouseEvent) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if (toolStore.isToolFavorite({ tool })) {
|
|
|
|
toolStore.removeToolFromFavorites({ tool });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
toolStore.addToolToFavorites({ tool });
|
|
|
|
}
|
|
|
|
</script>
|
2023-05-28 23:13:24 +02:00
|
|
|
|
|
|
|
<template>
|
|
|
|
<n-tooltip trigger="hover">
|
|
|
|
<template #trigger>
|
|
|
|
<c-button
|
|
|
|
variant="text"
|
|
|
|
circle
|
|
|
|
:type="buttonType"
|
|
|
|
:style="{ opacity: isFavorite ? 1 : 0.2 }"
|
|
|
|
@click="toggleFavorite"
|
|
|
|
>
|
|
|
|
<n-icon :component="FavoriteFilled" />
|
|
|
|
</c-button>
|
|
|
|
</template>
|
|
|
|
{{ isFavorite ? 'Remove from favorites' : 'Add to favorites' }}
|
|
|
|
</n-tooltip>
|
|
|
|
</template>
|