From 50bfb5a99855728fc00f55154aeb07446f692f4a Mon Sep 17 00:00:00 2001 From: KoalaSat Date: Fri, 30 Dec 2022 19:11:35 +0100 Subject: [PATCH] Image preview and JS files restructred --- frontend/Components/NoteCard/index.tsx | 4 +- .../{TextBox => TextContent}/index.tsx | 52 +++++++++++++------ .../ConfigPage/index.tsx | 0 .../ContactsPage/index.tsx | 2 +- .../ConversationPage/index.tsx | 8 +-- .../DirectMessagesPage/index.tsx | 2 +- .../{Components => Pages}/HomePage/index.tsx | 14 +++-- .../LandingPage/Loader/index.tsx | 6 +-- .../LandingPage/Logger/index.tsx | 0 .../LandingPage/index.tsx | 2 +- .../MainLayout/index.tsx | 4 +- .../MentionsPage/index.tsx | 12 ++++- .../{Components => Pages}/NotePage/index.tsx | 9 ++-- .../ProfilePage/index.tsx | 19 ++++--- .../RelaysPage/index.tsx | 0 .../{Components => Pages}/SendPage/index.tsx | 2 +- frontend/index.tsx | 2 +- package.json | 1 + yarn.lock | 37 +++++-------- 19 files changed, 105 insertions(+), 71 deletions(-) rename frontend/Components/{TextBox => TextContent}/index.tsx (68%) rename frontend/{Components => Pages}/ConfigPage/index.tsx (100%) rename frontend/{Components => Pages}/ContactsPage/index.tsx (99%) rename frontend/{Components => Pages}/ConversationPage/index.tsx (97%) rename frontend/{Components => Pages}/DirectMessagesPage/index.tsx (99%) rename frontend/{Components => Pages}/HomePage/index.tsx (93%) rename frontend/{Components => Pages}/LandingPage/Loader/index.tsx (93%) rename frontend/{Components => Pages}/LandingPage/Logger/index.tsx (100%) rename frontend/{Components => Pages}/LandingPage/index.tsx (97%) rename frontend/{Components => Pages}/MainLayout/index.tsx (93%) rename frontend/{Components => Pages}/MentionsPage/index.tsx (92%) rename frontend/{Components => Pages}/NotePage/index.tsx (96%) rename frontend/{Components => Pages}/ProfilePage/index.tsx (95%) rename frontend/{Components => Pages}/RelaysPage/index.tsx (100%) rename frontend/{Components => Pages}/SendPage/index.tsx (99%) diff --git a/frontend/Components/NoteCard/index.tsx b/frontend/Components/NoteCard/index.tsx index deec7ce..81e55a8 100644 --- a/frontend/Components/NoteCard/index.tsx +++ b/frontend/Components/NoteCard/index.tsx @@ -18,7 +18,7 @@ import { populateRelay } from '../../Functions/RelayFunctions' import Avatar from '../Avatar' import { searchRelays } from '../../Functions/DatabaseFunctions/Relays' import { RelayFilters } from '../../lib/nostr/RelayPool/intex' -import TextBox from '../TextBox' +import TextContent from '../../Components/TextContent' import { formatPubKey } from '../../Functions/RelayFunctions/Users' interface NoteCardProps { @@ -94,7 +94,7 @@ export const NoteCard: React.FC = ({ {t('note.contentWarning')} ) : ( - + )} diff --git a/frontend/Components/TextBox/index.tsx b/frontend/Components/TextContent/index.tsx similarity index 68% rename from frontend/Components/TextBox/index.tsx rename to frontend/Components/TextContent/index.tsx index f3508e1..1201f8a 100644 --- a/frontend/Components/TextBox/index.tsx +++ b/frontend/Components/TextContent/index.tsx @@ -7,19 +7,28 @@ import { AppContext } from '../../Contexts/AppContext' import { getUser } from '../../Functions/DatabaseFunctions/Users' import { formatPubKey } from '../../Functions/RelayFunctions/Users' import moment from 'moment' +import { LinkPreview, REGEX_LINK } from '@flyerhq/react-native-link-preview' -interface TextBoxProps { - note: Event +interface TextContentProps { + event?: Event + content?: string + preview?: boolean } -export const TextBox: React.FC = ({ note }) => { +export const TextContent: React.FC = ({ event, content, preview = true }) => { const theme = useTheme() const { database, goToPage } = useContext(AppContext) const [userNames, setUserNames] = useState>({}) const [loadedUsers, setLoadedUsers] = useState(0) + const text = event?.content ?? content ?? '' useEffect(() => {}, [loadedUsers]) + const containsUrl: () => boolean = () => { + const matches = text.match(REGEX_LINK) ?? [] + return matches.length > 0 + } + const handleUrlPress: (url: string) => void = (url) => { Linking.openURL(url) } @@ -29,8 +38,10 @@ export const TextBox: React.FC = ({ note }) => { } const handleMentionPress: (text: string) => void = (text) => { + if (!event) return + const mentionIndex: number = parseInt(text.substring(2, text.length - 1)) - goToPage(`profile#${note.tags[mentionIndex][1]}`) + goToPage(`profile#${event.tags[mentionIndex][1]}`) } const renderMentionText: (matchingString: string, matches: string[]) => string = ( @@ -41,8 +52,8 @@ export const TextBox: React.FC = ({ note }) => { if (userNames[mentionIndex]) { return userNames[mentionIndex] - } else { - const pudKey = note.tags[mentionIndex][1] + } else if (event) { + const pudKey = event.tags[mentionIndex][1] if (database) { getUser(pudKey, database).then((user) => { setLoadedUsers(moment().unix()) @@ -53,6 +64,8 @@ export const TextBox: React.FC = ({ note }) => { }) } return `@${formatPubKey(pudKey)}` + } else { + return matchingString } } @@ -76,26 +89,33 @@ export const TextBox: React.FC = ({ note }) => { }) return ( - note && ( + <> - {note.content} + {text} - ) + {preview && containsUrl() && ( + ''} textContainerStyle={{ height: 0 }} /> + )} + ) } -export default TextBox +export default TextContent diff --git a/frontend/Components/ConfigPage/index.tsx b/frontend/Pages/ConfigPage/index.tsx similarity index 100% rename from frontend/Components/ConfigPage/index.tsx rename to frontend/Pages/ConfigPage/index.tsx diff --git a/frontend/Components/ContactsPage/index.tsx b/frontend/Pages/ContactsPage/index.tsx similarity index 99% rename from frontend/Components/ContactsPage/index.tsx rename to frontend/Pages/ContactsPage/index.tsx index 8454fcf..b3be223 100644 --- a/frontend/Components/ContactsPage/index.tsx +++ b/frontend/Pages/ContactsPage/index.tsx @@ -16,7 +16,7 @@ import Icon from 'react-native-vector-icons/FontAwesome5' import { EventKind } from '../../lib/nostr/Events' import { useTranslation } from 'react-i18next' import { getUsers, updateUserContact, User } from '../../Functions/DatabaseFunctions/Users' -import UserCard from '../UserCard' +import UserCard from '../../Components/UserCard' import { RelayPoolContext } from '../../Contexts/RelayPoolContext' import { populatePets } from '../../Functions/RelayFunctions/Users' diff --git a/frontend/Components/ConversationPage/index.tsx b/frontend/Pages/ConversationPage/index.tsx similarity index 97% rename from frontend/Components/ConversationPage/index.tsx rename to frontend/Pages/ConversationPage/index.tsx index bcf80d0..5592c9c 100644 --- a/frontend/Components/ConversationPage/index.tsx +++ b/frontend/Pages/ConversationPage/index.tsx @@ -10,13 +10,13 @@ import { updateConversationRead, } from '../../Functions/DatabaseFunctions/DirectMessages' import { getUser, User } from '../../Functions/DatabaseFunctions/Users' -import Avatar from '../Avatar' +import Avatar from '../../Components/Avatar' import { decrypt } from 'nostr-tools/nip04' import Icon from 'react-native-vector-icons/FontAwesome5' import { username, usersToTags } from '../../Functions/RelayFunctions/Users' import moment from 'moment' import { encrypt } from '../../lib/nostr/Crypto' -import TextBox from '../TextBox' +import TextContent from '../../Components/TextContent' export const ConversationPage: React.FC = () => { const theme = useTheme() @@ -123,7 +123,7 @@ export const ConversationPage: React.FC = () => { {moment.unix(message.created_at).format('HH:mm DD-MM-YY')} - + @@ -143,7 +143,7 @@ export const ConversationPage: React.FC = () => { )} - + ) diff --git a/frontend/Components/DirectMessagesPage/index.tsx b/frontend/Pages/DirectMessagesPage/index.tsx similarity index 99% rename from frontend/Components/DirectMessagesPage/index.tsx rename to frontend/Pages/DirectMessagesPage/index.tsx index aad9fb2..81c8e03 100644 --- a/frontend/Components/DirectMessagesPage/index.tsx +++ b/frontend/Pages/DirectMessagesPage/index.tsx @@ -23,7 +23,7 @@ import { generateConversationId, getOtherPubKey, } from '../../Functions/RelayFunctions/DirectMessages' -import Avatar from '../Avatar' +import Avatar from '../../Components/Avatar' import Icon from 'react-native-vector-icons/FontAwesome5' import { useTranslation } from 'react-i18next' import { username } from '../../Functions/RelayFunctions/Users' diff --git a/frontend/Components/HomePage/index.tsx b/frontend/Pages/HomePage/index.tsx similarity index 93% rename from frontend/Components/HomePage/index.tsx rename to frontend/Pages/HomePage/index.tsx index a674061..97acda1 100644 --- a/frontend/Components/HomePage/index.tsx +++ b/frontend/Pages/HomePage/index.tsx @@ -1,4 +1,4 @@ -import { Button, Card, Layout, Text, useTheme } from '@ui-kitten/components' +import { Button, Card, Layout, Spinner, Text, useTheme } from '@ui-kitten/components' import React, { useCallback, useContext, useEffect, useState } from 'react' import { t } from 'i18next' import { @@ -11,7 +11,7 @@ import { } from 'react-native' import { AppContext } from '../../Contexts/AppContext' import { getMainNotes, Note } from '../../Functions/DatabaseFunctions/Notes' -import NoteCard from '../NoteCard' +import NoteCard from '../../Components/NoteCard' import Icon from 'react-native-vector-icons/FontAwesome5' import { RelayPoolContext } from '../../Contexts/RelayPoolContext' import { EventKind } from '../../lib/nostr/Events' @@ -141,6 +141,11 @@ export const HomePage: React.FC = () => { justifyContent: 'center', alignItems: 'center', }, + spinner: { + justifyContent: 'center', + alignItems: 'center', + height: 64, + }, }) return ( @@ -153,6 +158,9 @@ export const HomePage: React.FC = () => { refreshControl={} > {notes.map((note) => itemCard(note))} + + + ) : ( @@ -160,7 +168,7 @@ export const HomePage: React.FC = () => { {t('homePage.noContacts')}