feat: allow disabling click to view
This commit is contained in:
1 parent
eeca5a826a
commit
0a3c5c8d97
5 files changed
+53
-9
No files matched your search
@@ -38,7 +38,7 @@ export const isYoutubeLink = (url?: string): boolean => {
|
|||||||
export const postLink = (post: Post) => `/post/${getInstance()}/${post.id}`
|
export const postLink = (post: Post) => `/post/${getInstance()}/${post.id}`
|
||||||
|
|
||||||
export type MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
|
export type MediaType = 'video' | 'image' | 'iframe' | 'embed' | 'none'
|
||||||
export type IframeType = 'youtube'
|
export type IframeType = 'youtube' | 'none'
|
||||||
|
|
||||||
export const mediaType = (post: Post, view: View = 'cozy'): MediaType => {
|
export const mediaType = (post: Post, view: View = 'cozy'): MediaType => {
|
||||||
if (post.url) {
|
if (post.url) {
|
||||||
|
|||||||
@@ -15,13 +15,19 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Icon, PuzzlePiece } from 'svelte-hero-icons'
|
import {
|
||||||
|
Icon,
|
||||||
|
PuzzlePiece,
|
||||||
|
VideoCamera,
|
||||||
|
type IconSource,
|
||||||
|
} from 'svelte-hero-icons'
|
||||||
import type { IframeType, MediaType } from '../helpers'
|
import type { IframeType, MediaType } from '../helpers'
|
||||||
import { userSettings } from '$lib/settings'
|
import { userSettings } from '$lib/settings'
|
||||||
|
|
||||||
export let type: IframeType = 'none'
|
export let type: IframeType = 'none'
|
||||||
|
export let thumbnail: string | undefined = undefined
|
||||||
export let url: string
|
export let url: string
|
||||||
let opened = false
|
let opened = !$userSettings.embeds.clickToView
|
||||||
|
|
||||||
const urlToEmbed = (inputUrl: string) => {
|
const urlToEmbed = (inputUrl: string) => {
|
||||||
if (type == 'youtube') {
|
if (type == 'youtube') {
|
||||||
@@ -37,6 +43,29 @@
|
|||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const typeData = (
|
||||||
|
type: IframeType
|
||||||
|
): {
|
||||||
|
icon: IconSource
|
||||||
|
text: string
|
||||||
|
} => {
|
||||||
|
switch (type) {
|
||||||
|
case 'youtube': {
|
||||||
|
return {
|
||||||
|
icon: VideoCamera,
|
||||||
|
text: 'YouTube Video',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return {
|
||||||
|
icon: PuzzlePiece,
|
||||||
|
text: 'Embed',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: data = typeData(type)
|
||||||
$: embedUrl = urlToEmbed(url)
|
$: embedUrl = urlToEmbed(url)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -54,11 +83,19 @@
|
|||||||
on:click={() => (opened = true)}
|
on:click={() => (opened = true)}
|
||||||
class="aspect-video w-full h-full z-0 overflow-hidden relative rounded-xl flex flex-col gap-2 items-center justify-center"
|
class="aspect-video w-full h-full z-0 overflow-hidden relative rounded-xl flex flex-col gap-2 items-center justify-center"
|
||||||
>
|
>
|
||||||
<div
|
{#if thumbnail}
|
||||||
class="absolute blur-3xl -z-10 top-0 left-0 w-full h-full bg-gradient-to-br from-green-800 via-blue-900 via-20% to-red-700"
|
<img
|
||||||
/>
|
src={thumbnail}
|
||||||
<Icon src={PuzzlePiece} solid size="48" />
|
class="absolute top-0 left-0 -z-10 brightness-[25%]"
|
||||||
<h1 class="font-bold text-xl">Embed</h1>
|
alt=""
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
|
<div
|
||||||
|
class="absolute blur-3xl -z-10 top-0 left-0 w-full h-full bg-gradient-to-br from-green-800 via-blue-900 via-20% to-red-700"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
<Icon src={data.icon} solid size="48" />
|
||||||
|
<h1 class="font-bold text-xl">{data.text}</h1>
|
||||||
<p>Click to view this content.</p>
|
<p>Click to view this content.</p>
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -92,7 +92,7 @@
|
|||||||
<p class="text-base">Go to the post to view this video.</p>
|
<p class="text-base">Go to the post to view this video.</p>
|
||||||
</a>
|
</a>
|
||||||
{:else if type == 'iframe' && (view == 'cozy' || view == 'card') && post.url}
|
{:else if type == 'iframe' && (view == 'cozy' || view == 'card') && post.url}
|
||||||
<PostIframe type="youtube" url={post.url} />
|
<PostIframe thumbnail={post.thumbnail_url} type="youtube" url={post.url} />
|
||||||
{:else if type == 'embed' && post.url}
|
{:else if type == 'embed' && post.url}
|
||||||
<PostLink
|
<PostLink
|
||||||
url={post.url}
|
url={post.url}
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ interface Settings {
|
|||||||
crosspostOriginalLink: boolean
|
crosspostOriginalLink: boolean
|
||||||
|
|
||||||
embeds: {
|
embeds: {
|
||||||
|
clickToView: boolean
|
||||||
youtube: 'youtube' | 'invidious' | 'piped'
|
youtube: 'youtube' | 'invidious' | 'piped'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,6 +131,7 @@ export const defaultSettings: Settings = {
|
|||||||
openLinksInNewTab: false,
|
openLinksInNewTab: false,
|
||||||
crosspostOriginalLink: true,
|
crosspostOriginalLink: true,
|
||||||
embeds: {
|
embeds: {
|
||||||
|
clickToView: true,
|
||||||
youtube: 'youtube',
|
youtube: 'youtube',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,6 +156,11 @@
|
|||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
<Section title="Embeds">
|
<Section title="Embeds">
|
||||||
|
<ToggleSetting
|
||||||
|
title="Click to view"
|
||||||
|
description="Before loading embeds, click. (It is recommended to leave this on, to not load a video you don't want to load.)"
|
||||||
|
bind:checked={$userSettings.embeds.clickToView}
|
||||||
|
/>
|
||||||
<Setting>
|
<Setting>
|
||||||
<span slot="title">YouTube</span>
|
<span slot="title">YouTube</span>
|
||||||
<span slot="description">
|
<span slot="description">
|
||||||
|
|||||||
Reference in new issue
Block a user