Skip to content

Commit

Permalink
fix: make network prop reactive, close #62 (#65)
Browse files Browse the repository at this point in the history
* fix: make network prop reactive, close #62

* fix: miss ref value

---------

Co-authored-by: ntnyq <ntnyq13@gmail.com>
  • Loading branch information
Mister-Hope and ntnyq authored Feb 13, 2023
1 parent 31a1389 commit c01b847
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/client/components/SocialShare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,18 @@ export const SocialShare = defineComponent({

// eslint-disable-next-line max-lines-per-function
setup(props) {
const networks = [...new Set(props.networks)]
const networkList = Object.keys(props.networksData)
.map(name => ({ name, ...props.networksData[name] }))
.filter(network => networks.includes(network.name))
.sort((prev, next) => networks.indexOf(prev.name) - networks.indexOf(next.name))
const networks = computed(() => [...new Set(props.networks)])

const networkList = computed(() =>
Object.keys(props.networksData)
.map(name => ({ name, ...props.networksData[name] }))
.filter(network => networks.value.includes(network.name))
.sort(
(prev, next) =>
networks.value.indexOf(prev.name) - networks.value.indexOf(next.name),
),
)

const frontmatter = usePageFrontmatter<SocialShareFrontmatter>()
const timer = ref<MayBe<number>>(null)
const popup = reactive({
Expand Down Expand Up @@ -114,7 +121,7 @@ export const SocialShare = defineComponent({

// Computed
const visible = computed(
() => Boolean(networks.length) && !frontmatter.value.noSocialShare,
() => Boolean(networks.value.length) && !frontmatter.value.noSocialShare,
)
const url = computed(() => frontmatter.value.$shareUrl
?? frontmatter.value.shareUrl
Expand Down Expand Up @@ -279,7 +286,7 @@ export const SocialShare = defineComponent({

return () => {
return visible.value
? h('div', { class: 'social-share' }, [renderNetworkList(networkList)])
? h('div', { class: 'social-share' }, [renderNetworkList(networkList.value)])
: null
}
},
Expand Down

1 comment on commit c01b847

@vercel
Copy link

@vercel vercel bot commented on c01b847 Feb 13, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.