Skip to content

Commit

Permalink
Merge pull request kodadot#6703 from roiLeo/chore/vue3/composite
Browse files Browse the repository at this point in the history
πŸ”§ vue3 composition api
  • Loading branch information
yangwao authored Aug 14, 2023
2 parents f00e5e4 + d9be03b commit 3fa9006
Show file tree
Hide file tree
Showing 5 changed files with 559 additions and 800 deletions.
15 changes: 2 additions & 13 deletions components/bsx/Offer/OfferTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ withDefaults(
const { $route } = useNuxtApp()
const { urlPrefix, tokenId } = usePrefix()
const { accountId } = useAuth()
const { replaceUrl } = useReplaceUrl()
const itemsPerPage = ref(20)
const currentPage = ref(parseInt($route.query?.page as string) || 1)
Expand All @@ -188,21 +189,9 @@ const tellFrens = (caller: string, withdraw: boolean) => {
}
watch(currentPage, (val) => {
replaceUrl(String(val))
replaceUrl({ page: String(val) })
})
const replaceUrl = (value: string, key = 'page') => {
const { $route, $router, $consola } = useNuxtApp()
if ($route.query[key] !== value) {
$router
.replace({
path: String($route.path),
query: { ...$route.query, [key]: value },
})
.catch($consola.warn /*Navigation Duplicate err fix later */)
}
}
const currentBlock = ref(async () => {
const { apiInstance } = useApi()
const api = await apiInstance.value
Expand Down
101 changes: 42 additions & 59 deletions components/rmrk/Gallery/EmotionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<NeoButton
v-for="emoji in emotes.slice(0, DISPLAYED_EMOJI)"
:key="emoji.key"
variant="is-outlined"
variant="secondary"
no-shadow
class="emoji-box mb-2"
@click.native="$emit('selected', emoji.parsed)">
Expand All @@ -28,77 +28,60 @@
</div>
</template>

<script lang="ts">
import { Component, Prop, Provide, Vue } from 'nuxt-property-decorator'
<script lang="ts" setup>
import orderBy from 'lodash/orderBy'
import { Emotion } from '../service/scheme'
import EmotionModal from './EmotionModal.vue'
import { NeoButton, NeoIcon, NeoTooltip } from '@kodadot1/brick'
import Identity from '@/components/identity/IdentityIndex.vue'
const issuerId = (emotion: Emotion) => emotion.caller
const DISPLAYED_EMOJI = 5
const { $buefy } = useNuxtApp()
const instance = getCurrentInstance()
interface GroupedEmotion {
[x: string]: Emotion[]
}
interface Emoji {
key: string
count: number
issuers: string[]
parsed: string
}
const props = defineProps<{
emotions: []
}>()
@Component({
components: {
Identity: () => import('@/components/identity/IdentityIndex.vue'),
NeoIcon,
NeoTooltip,
NeoButton,
},
})
export default class EmotionList extends Vue {
@Prop() public emotions!: GroupedEmotion
@Provide() DISPLAYED_EMOJI = 5
/**
* parse emoji from codepoint to emoji
* @param codepoint Emoji Codepoint
* @returns Emoticon πŸ‘¨πŸ»β€πŸŒΎ
*/
parseEmoji(codepoint): string {
if (codepoint) {
const toInt = codepoint.split('-').map((code) => parseInt(code, 16))
return String.fromCodePoint.apply(String, toInt)
}
return ''
/**
* parse emoji from codepoint to emoji
* @param codepoint Emoji Codepoint
* @returns Emoticon πŸ‘¨πŸ»β€πŸŒΎ
*/
const parseEmoji = (codepoint): string => {
if (codepoint) {
const toInt = codepoint.split('-').map((code) => parseInt(code, 16))
return String.fromCodePoint.apply(String, toInt)
}
openEmotionModal(): void {
this.$buefy.modal.open({
parent: this,
component: EmotionModal,
canCancel: ['escape', 'outside'],
hasModalCard: true,
props: {
emotes: this.emotes,
},
})
}
get emotes(): Emoji[] {
const mapping = Object.entries(this.emotions).map(([key, emotions]) => ({
key,
count: emotions.length,
issuers: emotions.map(issuerId),
parsed: this.parseEmoji(key),
}))
const orderByCount = orderBy(mapping, ['count'], ['desc'])
return ''
}
return orderByCount
}
const openEmotionModal = () => {
$buefy.modal.open({
parent: instance?.proxy,
component: EmotionModal,
canCancel: ['escape', 'outside'],
hasModalCard: true,
props: {
emotes: emotes.value,
},
})
}
const emotes = computed(() => {
const mapping = Object.entries(props.emotions).map(([key, emotions]) => ({
key,
count: emotions.length,
issuers: emotions.map(issuerId),
parsed: parseEmoji(key),
}))
const orderByCount = orderBy(mapping, ['count'], ['desc'])
return orderByCount
})
</script>

<style lang="scss">
Expand Down
Loading

0 comments on commit 3fa9006

Please sign in to comment.