11<script setup lang="ts">
22import { useNotionBlock , defineNotionProps } from " @/lib/blockable"
3- import { computed , nextTick , onBeforeMount , onMounted , ref , watch } from " vue"
3+ import { computed , onBeforeMount , getCurrentInstance , ref , onMounted } from " vue"
4+ import { useTwttr } from " ./helpers/tweet"
45
56const props = defineProps ({ ... defineNotionProps })
67// @ts-ignore
7- const { properties, pass } = useNotionBlock (props )
8+ const { properties } = useNotionBlock (props )
9+
810const tweetId = computed (() => properties .value ?.source ?.[0 ]?.[0 ].split (" status/" )?.[1 ])
911const el = ref <HTMLElement >()
12+ const error = ref ()
1013
1114const renderTweet = () => {
1215 // @ts-ignore
1316 const twttr = window [" twttr" ]
1417 // @ts-ignore
1518 twttr ?.ready ().then (({ widgets }) => {
16- if (el .value ) {
17- el .value .innerHTML = " "
18- }
19- widgets .createTweetEmbed (tweetId .value , el .value , {})
19+ widgets
20+ .createTweetEmbed (tweetId .value , el .value , {})
21+ .then ((element : any ) => {
22+ error .value = element ? undefined : " error"
23+ })
24+ .catch ((err : any ) => {
25+ error .value = err
26+ })
2027 })
2128}
22-
23- onBeforeMount (() => {
24- let twttrScript = document .getElementById (" twitter-widgets-js" )
25- if (! twttrScript ) {
26- var s = document .createElement (" script" )
27- s .id = " twitter-widgets-js"
28- s .src = " https://platform.twitter.com/widgets.js"
29- document .body .appendChild (s )
30- }
29+ useTwttr (renderTweet )
30+ onMounted (() => {
31+ renderTweet ()
3132})
3233 </script >
3334
@@ -38,5 +39,6 @@ export default {
3839 </script >
3940
4041<template >
41- <div ref =" el" ></div >
42+ <div v-if =" !error" class =" notion-tweet" ref =" el" ></div >
43+ <div v-else class =" notion-tweet-error" >Error loading Tweet</div >
4244</template >
0 commit comments