From 43ce0200f5d628a157b3fc8ea30593bfce180a4a Mon Sep 17 00:00:00 2001 From: Gowtham G Date: Sat, 9 Sep 2023 12:18:38 +0530 Subject: [PATCH 1/2] fix: add app name to home --- src/components/Appbar/HomeAppbar.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Appbar/HomeAppbar.tsx b/src/components/Appbar/HomeAppbar.tsx index edd53838..427613c9 100644 --- a/src/components/Appbar/HomeAppbar.tsx +++ b/src/components/Appbar/HomeAppbar.tsx @@ -1,6 +1,6 @@ import { NavigationProp, useNavigation } from "@react-navigation/native"; import { Fragment, FunctionComponent, memo, useState } from "react"; -import { Appbar, Avatar, Menu, Tooltip, useTheme } from "react-native-paper"; +import { Appbar, Avatar, Menu, Tooltip } from "react-native-paper"; import { StackParamList } from "../../router/types"; type props = { @@ -45,7 +45,7 @@ const HomeAppbar: FunctionComponent = ({ /> )} /> - + {!isVideoListScreen ? ( From 7ea6aca810cb599fda8e8fec469d3c92bce27e11 Mon Sep 17 00:00:00 2001 From: Gowtham G Date: Sat, 9 Sep 2023 12:37:06 +0530 Subject: [PATCH 2/2] fix: add support for tweet embeds --- src/components/Markdown/tokenizer.ts | 21 ++++++++++++++++++++- src/utils/const.ts | 1 + src/utils/url.ts | 10 +++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/components/Markdown/tokenizer.ts b/src/components/Markdown/tokenizer.ts index 94df1007..74f5881e 100644 --- a/src/components/Markdown/tokenizer.ts +++ b/src/components/Markdown/tokenizer.ts @@ -1,5 +1,9 @@ import { type CustomToken, MarkedTokenizer } from "react-native-marked"; -import { getStackoverflowEmbedURL, getYoutubeEmbedURL } from "../../utils/url"; +import { + getStackoverflowEmbedURL, + getTweetEmbedURL, + getYoutubeEmbedURL, +} from "../../utils/url"; class MDTokenizer extends MarkedTokenizer { paragraph(this: MarkedTokenizer, src: string) { @@ -110,6 +114,21 @@ class MDTokenizer extends MarkedTokenizer { return token; } + const twitterMatch = src.match(/^[*]?{% (tweet)[*]? (.*?)[*]?%}[*]?/); + if (twitterMatch && twitterMatch.length > 2) { + const url = getTweetEmbedURL(twitterMatch[2]); + const token: CustomToken = { + identifier: "embed", + type: "custom", + raw: twitterMatch[0], + tokens: [], + args: { + text: url, + }, + }; + return token; + } + return super.paragraph(src); } } diff --git a/src/utils/const.ts b/src/utils/const.ts index e835d6ad..6fceecae 100644 --- a/src/utils/const.ts +++ b/src/utils/const.ts @@ -31,3 +31,4 @@ export const VIDEO_UI_HIDE_TIMEOUT = 5000; // 5 seconds export const NETWORK_TIMEOUT_MS = 10000; export const YOUTUBE_HOST = "https://www.youtube.com"; export const STACKOVERFLOW_HOST = "https://stackoverflow.com"; +export const TWITTER_URL = "https://www.twitter.com"; diff --git a/src/utils/url.ts b/src/utils/url.ts index fcc18c2d..cff118d7 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -1,5 +1,5 @@ import Url from "url-parse"; -import { STACKOVERFLOW_HOST, YOUTUBE_HOST } from "./const"; +import { STACKOVERFLOW_HOST, TWITTER_URL, YOUTUBE_HOST } from "./const"; export const buildURLParams = ( params: Record, @@ -32,3 +32,11 @@ export const getStackoverflowEmbedURL = (str: string) => { } return `${STACKOVERFLOW_HOST}/questions/${str}`; }; + +export const getTweetEmbedURL = (id: string) => { + const parsed = new Url(id, {}); + if (parsed.host) { + return parsed.toString(); + } + return `${TWITTER_URL}/i/web/status/${id}`; +};