refactor(client): use setup syntax
This commit is contained in:
		
							parent
							
								
									2c2c7d4966
								
							
						
					
					
						commit
						d9ff2dd471
					
				
					 5 changed files with 110 additions and 191 deletions
				
			
		|  | @ -14,26 +14,15 @@ | ||||||
| </MkA> | </MkA> | ||||||
| </template> | </template> | ||||||
| 
 | 
 | ||||||
| <script lang="ts"> | <script lang="ts" setup> | ||||||
| import { defineComponent } from 'vue'; | import { } from 'vue'; | ||||||
| import { userName } from '@/filters/user'; | import { userName } from '@/filters/user'; | ||||||
| import ImgWithBlurhash from '@/components/MkImgWithBlurhash.vue'; | import ImgWithBlurhash from '@/components/MkImgWithBlurhash.vue'; | ||||||
| import * as os from '@/os'; | import * as os from '@/os'; | ||||||
| 
 | 
 | ||||||
| export default defineComponent({ | const props = defineProps<{ | ||||||
| 	components: { | 	post: any; | ||||||
| 		ImgWithBlurhash, | }>(); | ||||||
| 	}, |  | ||||||
| 	props: { |  | ||||||
| 		post: { |  | ||||||
| 			type: Object, |  | ||||||
| 			required: true, |  | ||||||
| 		}, |  | ||||||
| 	}, |  | ||||||
| 	methods: { |  | ||||||
| 		userName, |  | ||||||
| 	}, |  | ||||||
| }); |  | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <style lang="scss" scoped> | <style lang="scss" scoped> | ||||||
|  |  | ||||||
|  | @ -1,8 +1,8 @@ | ||||||
| <template> | <template> | ||||||
| <div v-if="ad" class="qiivuoyo"> | <div v-if="chosen" class="qiivuoyo"> | ||||||
| 	<div v-if="!showMenu" class="main" :class="ad.place"> | 	<div v-if="!showMenu" class="main" :class="chosen.place"> | ||||||
| 		<a :href="ad.url" target="_blank"> | 		<a :href="chosen.url" target="_blank"> | ||||||
| 			<img :src="ad.imageUrl"> | 			<img :src="chosen.imageUrl"> | ||||||
| 			<button class="_button menu" @click.prevent.stop="toggleMenu"><span class="fas fa-info-circle info-circle"></span></button> | 			<button class="_button menu" @click.prevent.stop="toggleMenu"><span class="fas fa-info-circle info-circle"></span></button> | ||||||
| 		</a> | 		</a> | ||||||
| 	</div> | 	</div> | ||||||
|  | @ -10,7 +10,7 @@ | ||||||
| 		<div class="body"> | 		<div class="body"> | ||||||
| 			<div>Ads by {{ host }}</div> | 			<div>Ads by {{ host }}</div> | ||||||
| 			<!--<MkButton class="button" primary>{{ $ts._ad.like }}</MkButton>--> | 			<!--<MkButton class="button" primary>{{ $ts._ad.like }}</MkButton>--> | ||||||
| 			<MkButton v-if="ad.ratio !== 0" class="button" @click="reduceFrequency">{{ $ts._ad.reduceFrequencyOfThisAd }}</MkButton> | 			<MkButton v-if="chosen.ratio !== 0" class="button" @click="reduceFrequency">{{ $ts._ad.reduceFrequencyOfThisAd }}</MkButton> | ||||||
| 			<button class="_textButton" @click="toggleMenu">{{ $ts._ad.back }}</button> | 			<button class="_textButton" @click="toggleMenu">{{ $ts._ad.back }}</button> | ||||||
| 		</div> | 		</div> | ||||||
| 	</div> | 	</div> | ||||||
|  | @ -18,98 +18,78 @@ | ||||||
| <div v-else></div> | <div v-else></div> | ||||||
| </template> | </template> | ||||||
| 
 | 
 | ||||||
| <script lang="ts"> | <script lang="ts" setup> | ||||||
| import { defineComponent, ref } from 'vue'; | import { ref } from 'vue'; | ||||||
| import { instance } from '@/instance'; | import { instance } from '@/instance'; | ||||||
| import { host } from '@/config'; | import { host } from '@/config'; | ||||||
| import MkButton from '@/components/ui/button.vue'; | import MkButton from '@/components/ui/button.vue'; | ||||||
| import { defaultStore } from '@/store'; | import { defaultStore } from '@/store'; | ||||||
| import * as os from '@/os'; | import * as os from '@/os'; | ||||||
| 
 | 
 | ||||||
| export default defineComponent({ | type Ad = (typeof instance)['ads'][number]; | ||||||
| 	components: { |  | ||||||
| 		MkButton |  | ||||||
| 	}, |  | ||||||
| 
 | 
 | ||||||
| 	props: { | const props = defineProps<{ | ||||||
| 		prefer: { | 	prefer: string[]; | ||||||
| 			type: Array, | 	specify?: Ad; | ||||||
| 			required: true | }>(); | ||||||
| 		}, |  | ||||||
| 		specify: { |  | ||||||
| 			type: Object, |  | ||||||
| 			required: false |  | ||||||
| 		}, |  | ||||||
| 	}, |  | ||||||
| 
 | 
 | ||||||
| 	setup(props) { | const showMenu = ref(false); | ||||||
| 		const showMenu = ref(false); | const toggleMenu = (): void => { | ||||||
| 		const toggleMenu = () => { | 	showMenu.value = !showMenu.value; | ||||||
| 			showMenu.value = !showMenu.value; | }; | ||||||
| 		}; |  | ||||||
| 
 | 
 | ||||||
| 		const choseAd = (): (typeof instance)['ads'][number] | null => { | const choseAd = (): Ad | null => { | ||||||
| 			if (props.specify) { | 	if (props.specify) { | ||||||
| 				return props.specify as (typeof instance)['ads'][number]; | 		return props.specify; | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			const allAds = instance.ads.map(ad => defaultStore.state.mutedAds.includes(ad.id) ? { |  | ||||||
| 				...ad, |  | ||||||
| 				ratio: 0 |  | ||||||
| 			} : ad); |  | ||||||
| 
 |  | ||||||
| 			let ads = allAds.filter(ad => props.prefer.includes(ad.place)); |  | ||||||
| 
 |  | ||||||
| 			if (ads.length === 0) { |  | ||||||
| 				ads = allAds.filter(ad => ad.place === 'square'); |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			const lowPriorityAds = ads.filter(ad => ad.ratio === 0); |  | ||||||
| 			ads = ads.filter(ad => ad.ratio !== 0); |  | ||||||
| 
 |  | ||||||
| 			if (ads.length === 0) { |  | ||||||
| 				if (lowPriorityAds.length !== 0) { |  | ||||||
| 					return lowPriorityAds[Math.floor(Math.random() * lowPriorityAds.length)]; |  | ||||||
| 				} else { |  | ||||||
| 					return null; |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			const totalFactor = ads.reduce((a, b) => a + b.ratio, 0); |  | ||||||
| 			const r = Math.random() * totalFactor; |  | ||||||
| 
 |  | ||||||
| 			let stackedFactor = 0; |  | ||||||
| 			for (const ad of ads) { |  | ||||||
| 				if (r >= stackedFactor && r <= stackedFactor + ad.ratio) { |  | ||||||
| 					return ad; |  | ||||||
| 				} else { |  | ||||||
| 					stackedFactor += ad.ratio; |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			return null; |  | ||||||
| 		}; |  | ||||||
| 
 |  | ||||||
| 		const chosen = ref(choseAd()); |  | ||||||
| 
 |  | ||||||
| 		const reduceFrequency = () => { |  | ||||||
| 			if (chosen.value == null) return; |  | ||||||
| 			if (defaultStore.state.mutedAds.includes(chosen.value.id)) return; |  | ||||||
| 			defaultStore.push('mutedAds', chosen.value.id); |  | ||||||
| 			os.success(); |  | ||||||
| 			chosen.value = choseAd(); |  | ||||||
| 			showMenu.value = false; |  | ||||||
| 		}; |  | ||||||
| 
 |  | ||||||
| 		return { |  | ||||||
| 			ad: chosen, |  | ||||||
| 			showMenu, |  | ||||||
| 			toggleMenu, |  | ||||||
| 			host, |  | ||||||
| 			reduceFrequency, |  | ||||||
| 		}; |  | ||||||
| 	} | 	} | ||||||
| }); | 
 | ||||||
|  | 	const allAds = instance.ads.map(ad => defaultStore.state.mutedAds.includes(ad.id) ? { | ||||||
|  | 		...ad, | ||||||
|  | 		ratio: 0, | ||||||
|  | 	} : ad); | ||||||
|  | 
 | ||||||
|  | 	let ads = allAds.filter(ad => props.prefer.includes(ad.place)); | ||||||
|  | 
 | ||||||
|  | 	if (ads.length === 0) { | ||||||
|  | 		ads = allAds.filter(ad => ad.place === 'square'); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	const lowPriorityAds = ads.filter(ad => ad.ratio === 0); | ||||||
|  | 	ads = ads.filter(ad => ad.ratio !== 0); | ||||||
|  | 
 | ||||||
|  | 	if (ads.length === 0) { | ||||||
|  | 		if (lowPriorityAds.length !== 0) { | ||||||
|  | 			return lowPriorityAds[Math.floor(Math.random() * lowPriorityAds.length)]; | ||||||
|  | 		} else { | ||||||
|  | 			return null; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	const totalFactor = ads.reduce((a, b) => a + b.ratio, 0); | ||||||
|  | 	const r = Math.random() * totalFactor; | ||||||
|  | 
 | ||||||
|  | 	let stackedFactor = 0; | ||||||
|  | 	for (const ad of ads) { | ||||||
|  | 		if (r >= stackedFactor && r <= stackedFactor + ad.ratio) { | ||||||
|  | 			return ad; | ||||||
|  | 		} else { | ||||||
|  | 			stackedFactor += ad.ratio; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return null; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | const chosen = ref(choseAd()); | ||||||
|  | 
 | ||||||
|  | function reduceFrequency(): void { | ||||||
|  | 	if (chosen.value == null) return; | ||||||
|  | 	if (defaultStore.state.mutedAds.includes(chosen.value.id)) return; | ||||||
|  | 	defaultStore.push('mutedAds', chosen.value.id); | ||||||
|  | 	os.success(); | ||||||
|  | 	chosen.value = choseAd(); | ||||||
|  | 	showMenu.value = false; | ||||||
|  | } | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <style lang="scss" scoped> | <style lang="scss" scoped> | ||||||
|  |  | ||||||
|  | @ -18,54 +18,39 @@ | ||||||
| </component> | </component> | ||||||
| </template> | </template> | ||||||
| 
 | 
 | ||||||
| <script lang="ts"> | <script lang="ts" setup> | ||||||
| import { defineAsyncComponent, defineComponent, ref } from 'vue'; | import { defineAsyncComponent, ref } from 'vue'; | ||||||
| import { toUnicode as decodePunycode } from 'punycode/'; | import { toUnicode as decodePunycode } from 'punycode/'; | ||||||
| import { url as local } from '@/config'; | import { url as local } from '@/config'; | ||||||
| import * as os from '@/os'; | import * as os from '@/os'; | ||||||
| import { useTooltip } from '@/scripts/use-tooltip'; | import { useTooltip } from '@/scripts/use-tooltip'; | ||||||
| import { safeURIDecode } from '@/scripts/safe-uri-decode'; | import { safeURIDecode } from '@/scripts/safe-uri-decode'; | ||||||
| 
 | 
 | ||||||
| export default defineComponent({ | const props = defineProps<{ | ||||||
| 	props: { | 	url: string; | ||||||
| 		url: { | 	rel?: string; | ||||||
| 			type: String, | }>(); | ||||||
| 			required: true, |  | ||||||
| 		}, |  | ||||||
| 		rel: { |  | ||||||
| 			type: String, |  | ||||||
| 			required: false, |  | ||||||
| 			default: null, |  | ||||||
| 		}, |  | ||||||
| 	}, |  | ||||||
| 	setup(props) { |  | ||||||
| 		const self = props.url.startsWith(local); |  | ||||||
| 		const url = new URL(props.url); |  | ||||||
| 		const el = ref(); |  | ||||||
| 
 | 
 | ||||||
| 		useTooltip(el, (showing) => { | const self = props.url.startsWith(local); | ||||||
| 			os.popup(defineAsyncComponent(() => import('@/components/MkUrlPreviewPopup.vue')), { | const url = new URL(props.url); | ||||||
| 				showing, | const el = ref(); | ||||||
| 				url: props.url, |  | ||||||
| 				source: el.value, |  | ||||||
| 			}, {}, 'closed'); |  | ||||||
| 		}); |  | ||||||
| 
 | 
 | ||||||
| 		return { | useTooltip(el, (showing) => { | ||||||
| 			local, | 	os.popup(defineAsyncComponent(() => import('@/components/MkUrlPreviewPopup.vue')), { | ||||||
| 			schema: url.protocol, | 		showing, | ||||||
| 			hostname: decodePunycode(url.hostname), | 		url: props.url, | ||||||
| 			port: url.port, | 		source: el.value, | ||||||
| 			pathname: safeURIDecode(url.pathname), | 	}, {}, 'closed'); | ||||||
| 			query: safeURIDecode(url.search), |  | ||||||
| 			hash: safeURIDecode(url.hash), |  | ||||||
| 			self: self, |  | ||||||
| 			attr: self ? 'to' : 'href', |  | ||||||
| 			target: self ? null : '_blank', |  | ||||||
| 			el, |  | ||||||
| 		}; |  | ||||||
| 	}, |  | ||||||
| }); | }); | ||||||
|  | 
 | ||||||
|  | const schema = url.protocol; | ||||||
|  | const hostname = decodePunycode(url.hostname); | ||||||
|  | const port = url.port; | ||||||
|  | const pathname = safeURIDecode(url.pathname); | ||||||
|  | const query = safeURIDecode(url.search); | ||||||
|  | const hash = safeURIDecode(url.hash); | ||||||
|  | const attr = self ? 'to' : 'href'; | ||||||
|  | const target = self ? null : '_blank'; | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <style lang="scss" scoped> | <style lang="scss" scoped> | ||||||
|  |  | ||||||
|  | @ -1,17 +0,0 @@ | ||||||
| <template> |  | ||||||
| <div class="evrzpitu"></div> |  | ||||||
| </template> |  | ||||||
| 
 |  | ||||||
| <script lang="ts"> |  | ||||||
| import { defineComponent } from 'vue'; |  | ||||||
| import * as os from '@/os'; |  | ||||||
| 
 |  | ||||||
| export default defineComponent({}); |  | ||||||
| </script> |  | ||||||
| 
 |  | ||||||
| <style lang="scss" scoped> |  | ||||||
| .evrzpitu |  | ||||||
| 	margin 16px 0 |  | ||||||
| 	border-bottom solid var(--lineWidth) var(--faceDivider) |  | ||||||
| 
 |  | ||||||
| </style> |  | ||||||
|  | @ -9,40 +9,22 @@ | ||||||
| </div> | </div> | ||||||
| </template> | </template> | ||||||
| 
 | 
 | ||||||
| <script lang="ts"> | <script lang="ts" setup> | ||||||
| import { defineComponent } from 'vue'; | import { computed } from 'vue'; | ||||||
|  | import * as misskey from 'misskey-js'; | ||||||
| import MkPagination from '@/components/ui/pagination.vue'; | import MkPagination from '@/components/ui/pagination.vue'; | ||||||
| 
 | 
 | ||||||
| export default defineComponent({ | const props = defineProps<{ | ||||||
| 	components: { | 	user: misskey.entities.User; | ||||||
| 		MkPagination, | }>(); | ||||||
| 	}, |  | ||||||
| 
 | 
 | ||||||
| 	props: { | const pagination = { | ||||||
| 		user: { | 	endpoint: 'users/clips' as const, | ||||||
| 			type: Object, | 	limit: 20, | ||||||
| 			required: true | 	params: computed(() => ({ | ||||||
| 		}, | 		userId: props.user.id, | ||||||
| 	}, | 	})), | ||||||
| 
 | }; | ||||||
| 	data() { |  | ||||||
| 		return { |  | ||||||
| 			pagination: { |  | ||||||
| 				endpoint: 'users/clips' as const, |  | ||||||
| 				limit: 20, |  | ||||||
| 				params: { |  | ||||||
| 					userId: this.user.id, |  | ||||||
| 				} |  | ||||||
| 			}, |  | ||||||
| 		}; |  | ||||||
| 	}, |  | ||||||
| 
 |  | ||||||
| 	watch: { |  | ||||||
| 		user() { |  | ||||||
| 			this.$refs.list.reload(); |  | ||||||
| 		} |  | ||||||
| 	}, |  | ||||||
| }); |  | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
| <style lang="scss" scoped> | <style lang="scss" scoped> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue