Skip to content

Commit

Permalink
feat: drag only pinned
Browse files Browse the repository at this point in the history
  • Loading branch information
olgakup committed Nov 22, 2024
1 parent 96e4b12 commit d20d196
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import TestNetworkIcon from '@action/icons/common/test-network-icon.vue';
import NewIcon from '@action/icons/asset/new-icon.vue';
import PinIcon from '@action/icons/actions/pin.vue';
import { newNetworks } from '@/providers/common/libs/new-features';
import { BaseNetwork } from '@/types/base-network';
const props = defineProps({
network: {
Expand All @@ -55,9 +54,9 @@ const props = defineProps({
return false;
},
},
pinnedNetworks: {
type: Array as PropType<BaseNetwork[]>,
default: () => [],
isPinned: {
type: Boolean,
required: true,
},
});
const imageTag = ref<HTMLImageElement | null>(null);
Expand Down Expand Up @@ -130,9 +129,7 @@ const isHovered = ref(false);
* @returns {boolean} - `true` if the "Pin" button should be shown, `false` otherwise.
*/
const isPinned = computed(() => {
return props.pinnedNetworks.some(
pinnedNetwork => pinnedNetwork.name === props.network.name,
);
return props.isPinned;
});
/**
Expand Down Expand Up @@ -177,7 +174,8 @@ const setPinned = async () => {
align-items: center;
flex-direction: row;
width: 96%;
height: 40px;
min-height: 40px !important;
max-height: 40px;
margin-bottom: 3px;
margin-top: 3px;
cursor: pointer;
Expand Down
32 changes: 28 additions & 4 deletions packages/extension/src/ui/action/components/app-menu/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,31 @@
@scroll="setIsScrolling"
>
<!-- NOTE: WHATS seletced props is for, it is not in the component-->
<draggable v-model="searchNetworks" item-key="name" :animation="300">

<draggable v-model="draggableNetworks" item-key="name" :animation="500">
<template #item="{ element }">
<app-menu-item
v-bind="$attrs"
:network="element"
:is-active="!!selected && element.name === selected"
:selected="selected"
:pinnedNetworks="pinnedNetworks"
:is-pinned="getIsPinned(element.name)"
@click="emit('update:network', element)"
@update:pin-network="updatePinNetwork"
/>
</template>
</draggable>
<app-menu-item
v-for="element in otherNetworks"
:key="element.name"
v-bind="$attrs"
:network="element"
:is-active="!!selected && element.name === selected"
:selected="selected"
:is-pinned="getIsPinned(element.name)"
@click="emit('update:network', element)"
@update:pin-network="updatePinNetwork"
/>
</div>
</div>
</template>
Expand All @@ -29,7 +41,7 @@ import AppMenuItem from './components/app-menu-item.vue';
import draggable from 'vuedraggable';
import NetworksState from '@/libs/networks-state';
import { BaseNetwork } from '@/types/base-network';
import { NetworkNames } from '@enkryptcom/types';
const networksState = new NetworksState();
const props = defineProps({
networks: {
Expand Down Expand Up @@ -59,6 +71,9 @@ const emit = defineEmits<{
(e: 'update:pinNetwork', network: string, isPinned: boolean): void;
}>();
const getIsPinned = (network: NetworkNames) => {
return props.pinnedNetworks.map(pinned => pinned.name).includes(network);
};
const searchNetworks = computed({
get: () => {
return props.networks.filter(
Expand All @@ -79,6 +94,16 @@ const searchNetworks = computed({
},
});
const draggableNetworks = computed(() => {
return searchNetworks.value.filter(network => {
return getIsPinned(network.name);
});
});
const otherNetworks = computed(() => {
return searchNetworks.value.filter(network => !getIsPinned(network.name));
});
const updatePinNetwork = (network: string, isPinned: boolean) => {
emit('update:pinNetwork', network, isPinned);
};
Expand Down Expand Up @@ -125,7 +150,6 @@ onBeforeUnmount(() => {
max-height: 452px;
display: flex;
flex-direction: column;
gap: 4px;
overflow-y: scroll;
scroll-behavior: smooth;
margin-right: -4px;
Expand Down

0 comments on commit d20d196

Please sign in to comment.