diff --git a/src/app/browser/components/friend-code.tsx b/src/app/browser/components/friend-code.tsx new file mode 100644 index 0000000..a60fe88 --- /dev/null +++ b/src/app/browser/components/friend-code.tsx @@ -0,0 +1,33 @@ +import React, { useCallback, useMemo } from 'react'; +import { StyleSheet, Text } from 'react-native'; +import { CurrentUser } from '../../../api/coral-types.js'; +import ipc from '../ipc.js'; + +export default function FriendCode(props: { + friendcode: CurrentUser['links']['friendCode']; +} | { + id: string; +}) { + const friendcode = useMemo(() => 'friendcode' in props ? props.friendcode : { + id: props.id, + regenerable: false, + regenerableAt: 0, + }, ['friendcode' in props ? props.friendcode : null, 'id' in props ? props.id : null]); + + const onFriendCodeContextMenu = useCallback(() => { + ipc.showFriendCodeMenu(friendcode); + }, [ipc, friendcode]); + + return SW-{friendcode.id}; +} + +const styles = StyleSheet.create({ + friendCodeValue: { + // @ts-expect-error + userSelect: 'all', + }, +}); diff --git a/src/app/browser/components/icons/add-outline.tsx b/src/app/browser/components/icons/add-outline.tsx index 4f57c9a..ac8d027 100644 --- a/src/app/browser/components/icons/add-outline.tsx +++ b/src/app/browser/components/icons/add-outline.tsx @@ -3,7 +3,7 @@ import { Platform, Text } from 'react-native'; import { svg_styles } from './util.js'; const IconWeb = React.memo(() => - Add + ); export default Platform.OS === 'web' ? IconWeb : React.memo(() => null); diff --git a/src/app/browser/components/icons/warning.tsx b/src/app/browser/components/icons/warning.tsx index d1a2e15..39bf301 100644 --- a/src/app/browser/components/icons/warning.tsx +++ b/src/app/browser/components/icons/warning.tsx @@ -3,7 +3,7 @@ import { Platform, Text } from 'react-native'; import { svg_styles } from './util.js'; const IconWeb = React.memo(() => - ionicons-v5-r + ); export default Platform.OS === 'web' ? IconWeb : React.memo(() => null); diff --git a/src/app/browser/components/index.ts b/src/app/browser/components/index.ts index 5ac39b4..05c5e36 100644 --- a/src/app/browser/components/index.ts +++ b/src/app/browser/components/index.ts @@ -1,3 +1,4 @@ export { default as Button } from './button.js'; export { default as NintendoSwitchUser } from './nintendo-switch-user.js'; export { NintendoSwitchUsers } from './nintendo-switch-user.js'; +export { default as FriendCode } from './friend-code.js'; diff --git a/src/app/browser/main/friends.tsx b/src/app/browser/main/friends.tsx index 5d5b258..8f0511b 100644 --- a/src/app/browser/main/friends.tsx +++ b/src/app/browser/main/friends.tsx @@ -1,12 +1,13 @@ import React, { useCallback } from 'react'; import { Image, ImageStyle, Platform, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native'; -import { useTranslation } from 'react-i18next'; +import { Trans, useTranslation } from 'react-i18next'; import ipc from '../ipc.js'; import { useAccentColour, useColourScheme, User, useTimeSince } from '../util.js'; import { Friend, Presence, PresenceState } from '../../../api/coral-types.js'; import { TEXT_COLOUR_ACTIVE, TEXT_COLOUR_DARK, TEXT_COLOUR_LIGHT } from '../constants.js'; import Section, { HEADER_SIZE } from './section.js'; import AddOutline from '../components/icons/add-outline.js'; +import { FriendCode } from '../components/index.js'; export default function Friends(props: { user: User; @@ -23,7 +24,10 @@ export default function Friends(props: { }, [props.user.user.id]); const header_buttons = - + ; const onFriendCodeContextMenu = useCallback(() => { @@ -43,11 +47,19 @@ export default function Friends(props: { : {t('no_friends')} - {t('friend_code')}: {fc} + + + + + } {props.friends.length ? - {t('friend_code')}: {fc} + + + + + : null} ; } @@ -124,10 +136,6 @@ const styles = StyleSheet.create({ fontSize: 12, opacity: 0.7, }, - friendCodeValue: { - // @ts-expect-error - userSelect: 'all', - }, content: { paddingBottom: 16, paddingLeft: ipc.platform === 'win32' ? 24 : 20, diff --git a/src/app/i18n/locale/en-gb.ts b/src/app/i18n/locale/en-gb.ts index eddf568..c57cdbb 100644 --- a/src/app/i18n/locale/en-gb.ts +++ b/src/app/i18n/locale/en-gb.ts @@ -145,9 +145,10 @@ export const main_window = { friends_section: { title: 'Friends', + add: 'Add', no_friends: 'Add friends using a Nintendo Switch console.', - friend_code: 'Your friend code', + friend_code: 'Your friend code: <0>', presence_playing: 'Playing', presence_offline: 'Offline',