Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: network selector on explorer #4863

Merged
merged 5 commits into from
Feb 2, 2023
Merged
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
49 changes: 49 additions & 0 deletions components/explore/ExploreChain.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div>
<NeoDropdown position="bottom-right" @active-change="isActive = $event">
<NeoButton
:label="`Network: ${selected.text}`"
:icon="isActive ? 'caret-up' : 'caret-down'" />

<template #items>
<NeoDropdownItem
v-for="chain in availableChains"
:key="chain.value"
:active="route.params.prefix === chain.value"
@click.native="onSwitchChain(chain.value)">
{{ chain.text }}
</NeoDropdownItem>
</template>
</NeoDropdown>
</div>
</template>

<script setup lang="ts">
import { NeoButton, NeoDropdown, NeoDropdownItem } from '@kodadot1/brick'

const route = useRoute()
const router = useRouter()
const { $store } = useNuxtApp()

const { availableChains } = useChain()
const isActive = ref(false)
const selected = computed(() =>
availableChains.value.find((chain) => chain.value === route.params.prefix)
)

function onSwitchChain(chain) {
$store.dispatch('setUrlPrefix', chain)

router.push({
params: {
prefix: chain,
},
query: {
page: '1',
sort: route.query.sort,
Copy link
Contributor

Choose a reason for hiding this comment

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

how about adding the search keywords to query

Copy link
Member Author

Choose a reason for hiding this comment

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

will add this 👍

},
})
}
</script>

<style scoped></style>
14 changes: 13 additions & 1 deletion components/explore/ExploreIndex.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<template>
<div class="explore is-flex">
<ExploreTabItem />
<ExploreSort />
<div class="explore-menu is-flex">
<ExploreSort />
<ExploreChain />
</div>
</div>
</template>

<script setup lang="ts" scoped>
import ExploreTabItem from './ExploreTabItem.vue'
import ExploreSort from './ExploreSort.vue'
import ExploreChain from './ExploreChain.vue'
</script>

<style lang="scss" scoped>
Expand All @@ -17,9 +21,17 @@ import ExploreSort from './ExploreSort.vue'
margin-bottom: 2.5rem;
gap: 2rem;

&-menu {
gap: 2rem;
}

@include mobile {
gap: 1rem;
flex-direction: column;

&-menu {
gap: 1rem;
}
}
}
</style>
15 changes: 15 additions & 0 deletions composables/useChain.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { chainPropListOf } from '@/utils/config/chain.config'
import { ChainProperties } from '@/utils/api/Query'
import { getChainTestList } from '@/utils/constants'

export default function () {
const { $store, $config } = useNuxtApp()
const { urlPrefix } = usePrefix()

const chainProperties = computed<ChainProperties>(() => {
Expand All @@ -20,10 +22,23 @@ export default function () {
return urlPrefix.value !== 'snek' && urlPrefix.value !== 'bsx'
})

const availableChains = computed(() => {
const availableUrlPrefixes = $store.getters['availableUrlPrefixes']

if (!$config.public.dev) {
return availableUrlPrefixes.filter(
(urlPrefix) => !getChainTestList().includes(urlPrefix.value)
)
}

return availableUrlPrefixes
})

return {
decimals,
unit,
offersDisabled,
chainProperties,
availableChains,
}
}
10 changes: 9 additions & 1 deletion libs/ui/src/components/NeoDropdown/NeoDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class="neo-dropdown"
:class="{ 'o-drop-active': isActive }"
:mobile-modal="mobileModal"
@active-change="isActive = $event">
@active-change="onActiveChange($event)">
<template #trigger>
<slot />
</template>
Expand All @@ -15,6 +15,7 @@
</template>

<script lang="ts" setup>
import { defineEmits } from 'vue'
import { ODropdown } from '@oruga-ui/oruga'

const isActive = ref(false)
Expand All @@ -31,6 +32,13 @@ withDefaults(
mobileModal: false,
}
)

const emit = defineEmits(['active-change'])

function onActiveChange(event) {
isActive.value = event
emit('active-change', event)
}
</script>

<style lang="scss">
Expand Down