diff --git a/src/app/components/RenderMessageContent.tsx b/src/app/components/RenderMessageContent.tsx index 40647144..510785c8 100644 --- a/src/app/components/RenderMessageContent.tsx +++ b/src/app/components/RenderMessageContent.tsx @@ -30,8 +30,6 @@ import { UrlPreviewHolder, YouTubeEmbed, isYouTubeUrl, - TikTokEmbed, - isTikTokUrl, GiphyEmbed, isGiphyUrl, } from './url-preview'; @@ -88,11 +86,8 @@ export function RenderMessageContent({ // Separate special URLs from generic ones const youtubeUrls = filteredUrls.filter(isYouTubeUrl); - const tiktokUrls = filteredUrls.filter(isTikTokUrl); const giphyUrls = filteredUrls.filter(isGiphyUrl); - const otherUrls = filteredUrls.filter( - (url) => !isYouTubeUrl(url) && !isTikTokUrl(url) && !isGiphyUrl(url), - ); + const otherUrls = filteredUrls.filter((url) => !isYouTubeUrl(url) && !isGiphyUrl(url)); return ( <> @@ -100,10 +95,6 @@ export function RenderMessageContent({ {youtubeUrls.map((url) => ( ))} - {/* Render TikTok embeds */} - {tiktokUrls.map((url) => ( - - ))} {/* Render Giphy embeds */} {giphyUrls.map((url) => ( diff --git a/src/app/components/url-preview/TikTokEmbed.css.tsx b/src/app/components/url-preview/TikTokEmbed.css.tsx deleted file mode 100644 index a639394b..00000000 --- a/src/app/components/url-preview/TikTokEmbed.css.tsx +++ /dev/null @@ -1,117 +0,0 @@ -import { style } from '@vanilla-extract/css'; -import { DefaultReset, color, config, toRem } from 'folds'; - -export const TikTokEmbed = style([ - DefaultReset, - { - width: toRem(360), - maxWidth: '100%', - backgroundColor: color.SurfaceVariant.Container, - border: `${config.borderWidth.B300} solid ${color.SurfaceVariant.ContainerLine}`, - borderRadius: config.radii.R300, - overflow: 'hidden', - }, -]); - -export const TikTokEmbedHeader = style([ - DefaultReset, - { - padding: `${config.space.S200} ${config.space.S300}`, - backgroundColor: color.SurfaceVariant.ContainerActive, - display: 'flex', - alignItems: 'center', - justifyContent: 'space-between', - gap: config.space.S200, - }, -]); - -export const TikTokEmbedInfo = style([ - DefaultReset, - { - display: 'flex', - flexDirection: 'column', - gap: config.space.S100, - flex: 1, - minWidth: 0, - }, -]); - -export const TikTokEmbedTitle = style({ - color: color.Primary.Main, - textDecoration: 'none', - fontWeight: config.fontWeight.W500, - ':hover': { - textDecoration: 'underline', - }, -}); - -export const TikTokEmbedAuthor = style({ - color: color.SurfaceVariant.OnContainer, - textDecoration: 'none', - opacity: 0.8, - ':hover': { - textDecoration: 'underline', - opacity: 1, - }, -}); - -export const TikTokEmbedLink = style({ - color: color.Success.Main, - textDecoration: 'none', - overflow: 'hidden', - textOverflow: 'ellipsis', - whiteSpace: 'nowrap', - ':hover': { - textDecoration: 'underline', - }, -}); - -export const TikTokThumbnailContainer = style([ - DefaultReset, - { - position: 'relative', - width: '100%', - height: toRem(550), - backgroundColor: '#000', - display: 'block', - }, -]); - -export const TikTokThumbnailButton = style([ - DefaultReset, - { - position: 'relative', - width: '100%', - height: toRem(550), - border: 'none', - padding: 0, - cursor: 'pointer', - backgroundColor: '#000', - display: 'block', - overflow: 'hidden', - }, -]); - -export const TikTokThumbnail = style([ - DefaultReset, - { - width: '100%', - height: '100%', - display: 'block', - objectFit: 'cover', - objectPosition: 'center', - }, -]); - -export const TikTokEmbedContainer = style([ - DefaultReset, - { - width: '100%', - height: toRem(550), - alignItems: 'center', - justifyContent: 'center', - backgroundColor: '#000', - border: 'none', - display: 'block', - }, -]); diff --git a/src/app/components/url-preview/TikTokEmbed.tsx b/src/app/components/url-preview/TikTokEmbed.tsx deleted file mode 100644 index d102d507..00000000 --- a/src/app/components/url-preview/TikTokEmbed.tsx +++ /dev/null @@ -1,277 +0,0 @@ -import React, { MouseEvent, useEffect, useState } from 'react'; -import { Box, Spinner, Text, as } from 'folds'; -import * as css from './TikTokEmbed.css'; -import { openExternalUrl } from '../../utils/tauri'; - -/** - * Regex patterns to match TikTok URLs - */ -const TIKTOK_URL_PATTERNS = [ - // Standard tiktok.com/@username/video/VIDEO_ID - /(?:https?:\/\/)?(?:www\.)?tiktok\.com\/@[\w.-]+\/video\/(\d+)/i, - // Short vm.tiktok.com/VIDEO_CODE - /(?:https?:\/\/)?(?:www\.)?vm\.tiktok\.com\/([\w]+)/i, - // Short vt.tiktok.com/VIDEO_CODE - /(?:https?:\/\/)?(?:www\.)?vt\.tiktok\.com\/([\w]+)/i, - // Mobile m.tiktok.com - /(?:https?:\/\/)?(?:www\.)?m\.tiktok\.com\/v\/(\d+)/i, -]; - -/** - * TikTok oEmbed API base - */ -const TIKTOK_OEMBED_API = 'https://www.tiktok.com/oembed'; - -/** - * Click handler for external links - uses Tauri shell on desktop/mobile - */ -const handleExternalLinkClick = (e: MouseEvent) => { - const { href } = e.currentTarget; - if (href && (href.startsWith('http://') || href.startsWith('https://'))) { - e.preventDefault(); - openExternalUrl(href); - } -}; - -/** - * Checks if a URL is a TikTok URL - * @param url The URL to check - * @returns True if the URL is a TikTok URL - */ -export function isTikTokUrl(url: string): boolean { - return TIKTOK_URL_PATTERNS.some((pattern) => pattern.test(url)); -} - -function extractTikTokVideoId(url: string, embedHtml = ''): string | null { - const urlMatch = url.match(/\/video\/(\d+)/i) ?? url.match(/\/v\/(\d+)/i); - const embedMatch = embedHtml.match(/data-video-id=["'](\d+)["']/i); - return urlMatch?.[1] ?? embedMatch?.[1] ?? null; -} - -/** - * Fetches TikTok video metadata using oEmbed API - * @param url The TikTok video URL - * @returns Video metadata including title, author, and thumbnail - */ -async function fetchTikTokOEmbed(url: string): Promise<{ - title: string; - authorName: string; - authorUrl: string; - thumbnailUrl: string; - embedHtml: string; - videoId: string | null; -} | null> { - try { - const { electron } = window as any; - let data; - if (electron?.tiktok?.getOEmbed) { - data = await electron.tiktok.getOEmbed(url); - } else { - const oembedUrl = `${TIKTOK_OEMBED_API}?url=${encodeURIComponent(url)}`; - const response = await fetch(oembedUrl); - if (!response.ok) return null; - data = await response.json(); - } - if (!data) return null; - - return { - title: data.title || 'TikTok Video', - authorName: data.author_name || 'Unknown', - authorUrl: data.author_url || url, - thumbnailUrl: data.thumbnail_url || '', - embedHtml: data.html || '', - videoId: extractTikTokVideoId(url, data.html || ''), - }; - } catch { - return null; - } -} - -type TikTokEmbedState = - | { status: 'loading' } - | { - status: 'loaded'; - title: string; - authorName: string; - authorUrl: string; - thumbnailUrl: string; - embedHtml: string; - videoId: string | null; - } - | { status: 'error' }; - -type TikTokEmbedProps = { - /** The original TikTok URL */ - url: string; -}; - -/** - * TikTok embed component that shows video preview with metadata - */ -export const TikTokEmbed = as<'div', TikTokEmbedProps>(({ url, ...props }, ref) => { - const [state, setState] = useState({ status: 'loading' }); - const [showPlayer, setShowPlayer] = useState(false); - - // Fetch video info on mount - useEffect(() => { - let cancelled = false; - - fetchTikTokOEmbed(url).then((info) => { - if (cancelled) return; - - if (info) { - setState({ - status: 'loaded', - title: info.title, - authorName: info.authorName, - authorUrl: info.authorUrl, - thumbnailUrl: info.thumbnailUrl, - embedHtml: info.embedHtml, - videoId: info.videoId, - }); - } else { - setState({ status: 'error' }); - } - }); - - return () => { - cancelled = true; - }; - }, [url]); - - // Loading state - if (state.status === 'loading') { - return ( - -
- - TikTok - Loading... - -
- - - -
- ); - } - - // Error state - show basic link - if (state.status === 'error') { - return ( - -
- - TikTok Video - -
-
- ); - } - - // Loaded state - show thumbnail or embed - if (!showPlayer) { - return ( - -
-
- - {state.title} - - - {state.authorName} - -
-
- -
- ); - } - - const playerUrl = state.videoId - ? `https://www.tiktok.com/player/v1/${state.videoId}?autoplay=1` - : null; - - // Use TikTok's documented player instead of injecting the oEmbed script. - return ( - -
- - {state.title} - -
- {playerUrl ? ( -