mirror of
https://github.com/austinried/subtracks.git
synced 2026-02-10 23:02:43 +01:00
don't use i18n namespaces
there's no need to keep reloading different parts of the object we already cached
This commit is contained in:
@@ -50,11 +50,11 @@ const TopSongs = withSuspenseMemo<{
|
||||
}>(
|
||||
({ songs, name }) => {
|
||||
const { setQueue, isReady, contextId } = useSetQueue('artist', songs)
|
||||
const { t } = useTranslation('resources.song.lists')
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header>{t('artistTopSongs')}</Header>
|
||||
<Header>{t('resources.song.lists.artistTopSongs')}</Header>
|
||||
{songs.slice(0, 5).map((s, i) => (
|
||||
<ListItem
|
||||
key={i}
|
||||
@@ -79,7 +79,7 @@ const ArtistAlbums = withSuspenseMemo<{
|
||||
}>(
|
||||
({ albums }) => {
|
||||
const albumsLayout = useLayout()
|
||||
const { t } = useTranslation('resources.album')
|
||||
const { t } = useTranslation()
|
||||
|
||||
const sortedAlbums = [...albums]
|
||||
.sort((a, b) => a.name.localeCompare(b.name))
|
||||
@@ -89,7 +89,7 @@ const ArtistAlbums = withSuspenseMemo<{
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header>{t('name', { count: 2 })}</Header>
|
||||
<Header>{t('resources.album.name', { count: 2 })}</Header>
|
||||
<View style={styles.albums} onLayout={albumsLayout.onLayout}>
|
||||
{sortedAlbums.map(a => (
|
||||
<AlbumItem key={a.id} album={a} height={albumSize} width={albumSize} />
|
||||
|
||||
@@ -45,9 +45,9 @@ const AlbumItem = React.memo<{
|
||||
}, equal)
|
||||
|
||||
const CategoryHeader = withSuspenseMemo<{ type: string }>(({ type }) => {
|
||||
const { t } = useTranslation('resources.album.lists')
|
||||
console.log('type', type, t(type))
|
||||
return <Header style={styles.header}>{t(type)}</Header>
|
||||
const { t } = useTranslation()
|
||||
console.log('type', type, t(`resources.album.lists.${type}`))
|
||||
return <Header style={styles.header}>{t(`resources.album.lists.${type}`)}</Header>
|
||||
})
|
||||
|
||||
const Category = React.memo<{
|
||||
|
||||
@@ -66,18 +66,18 @@ const filterValues: GetAlbumList2TypeBase[] = [
|
||||
]
|
||||
|
||||
const AlbumFilterButton = withSuspenseMemo(() => {
|
||||
const { t } = useTranslation('resources.album.lists')
|
||||
const { t } = useTranslation()
|
||||
const filterType = useStoreDeep(store => store.settings.screens.library.albumsFilter.type)
|
||||
const setFilterType = useStore(store => store.setLibraryAlbumFilterType)
|
||||
|
||||
return (
|
||||
<FilterButton
|
||||
data={filterValues.map(value => ({ value, text: t(value) }))}
|
||||
data={filterValues.map(value => ({ value, text: t(`resources.album.lists.${value}`) }))}
|
||||
value={filterType}
|
||||
onSelect={selection => {
|
||||
setFilterType(selection as GetAlbumList2TypeBase)
|
||||
}}
|
||||
title={t('sort')}
|
||||
title={t('resources.album.lists.sort')}
|
||||
/>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -21,16 +21,16 @@ const filterValues: ArtistFilterType[] = [
|
||||
]
|
||||
|
||||
const ArtistFilterButton = withSuspenseMemo(() => {
|
||||
const { t } = useTranslation('resources.artist.lists')
|
||||
const { t } = useTranslation()
|
||||
const filterType = useStoreDeep(store => store.settings.screens.library.artistsFilter.type)
|
||||
const setFilterType = useStore(store => store.setLibraryArtistFilterType)
|
||||
|
||||
return (
|
||||
<FilterButton
|
||||
data={filterValues.map(value => ({ value, text: t(value) }))}
|
||||
data={filterValues.map(value => ({ value, text: t(`resources.artist.lists.${value}`) }))}
|
||||
value={filterType}
|
||||
onSelect={selection => setFilterType(selection as ArtistFilterType)}
|
||||
title={t('sort')}
|
||||
title={t('resources.artist.lists.sort')}
|
||||
/>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -49,7 +49,7 @@ const ResultsCategory = withSuspenseMemo<{
|
||||
}>(
|
||||
({ name, query, type, items }) => {
|
||||
const navigation = useNavigation()
|
||||
const { t } = useTranslation('search')
|
||||
const { t } = useTranslation()
|
||||
|
||||
if (items.length === 0) {
|
||||
return <></>
|
||||
@@ -67,7 +67,7 @@ const ResultsCategory = withSuspenseMemo<{
|
||||
)}
|
||||
{items.length === 5 && (
|
||||
<Button
|
||||
title={t('moreResults')}
|
||||
title={t('search.moreResults')}
|
||||
buttonStyle="hollow"
|
||||
style={styles.more}
|
||||
onPress={() => navigation.navigate('results', { query, type: items[0].itemType })}
|
||||
@@ -85,13 +85,28 @@ const Results = withSuspenseMemo<{
|
||||
query: string
|
||||
}>(
|
||||
({ results, query }) => {
|
||||
const { t } = useTranslation('resources')
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<>
|
||||
<ResultsCategory name={t('artist.name', { count: 2 })} query={query} type={'artist'} items={results.artists} />
|
||||
<ResultsCategory name={t('album.name', { count: 2 })} query={query} type={'album'} items={results.albums} />
|
||||
<ResultsCategory name={t('song.name', { count: 2 })} query={query} type={'song'} items={results.songs} />
|
||||
<ResultsCategory
|
||||
name={t('resources.artist.name', { count: 2 })}
|
||||
query={query}
|
||||
type={'artist'}
|
||||
items={results.artists}
|
||||
/>
|
||||
<ResultsCategory
|
||||
name={t('resources.album.name', { count: 2 })}
|
||||
query={query}
|
||||
type={'album'}
|
||||
items={results.albums}
|
||||
/>
|
||||
<ResultsCategory
|
||||
name={t('resources.song.name', { count: 2 })}
|
||||
query={query}
|
||||
type={'song'}
|
||||
items={results.songs}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
},
|
||||
@@ -102,7 +117,7 @@ const Results = withSuspenseMemo<{
|
||||
const Search = withSuspense(() => {
|
||||
const [query, setQuery] = useState('')
|
||||
const { data, isLoading } = useQuerySearchResults({ query, albumCount: 5, artistCount: 5, songCount: 5 })
|
||||
const { t } = useTranslation('search')
|
||||
const { t } = useTranslation()
|
||||
|
||||
const [text, setText] = useState('')
|
||||
const searchBarRef = useRef<ReactTextInput>(null)
|
||||
@@ -154,7 +169,7 @@ const Search = withSuspense(() => {
|
||||
<TextInput
|
||||
ref={searchBarRef}
|
||||
style={styles.textInput}
|
||||
placeholder={t('inputPlaceholder')}
|
||||
placeholder={t('search.inputPlaceholder')}
|
||||
value={text}
|
||||
onChangeText={onChangeText}
|
||||
/>
|
||||
|
||||
@@ -59,7 +59,7 @@ const SearchResultsView = withSuspense<{
|
||||
type: 'album' | 'artist' | 'song'
|
||||
}>(({ query, type }) => {
|
||||
const navigation = useNavigation()
|
||||
const { t } = useTranslation('search')
|
||||
const { t } = useTranslation()
|
||||
|
||||
const size = 100
|
||||
const params: Search3Params = { query }
|
||||
@@ -85,7 +85,7 @@ const SearchResultsView = withSuspense<{
|
||||
|
||||
useEffect(() => {
|
||||
navigation.setOptions({
|
||||
title: t('headerTitle', { query }),
|
||||
title: t('search.headerTitle', { query }),
|
||||
})
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [])
|
||||
|
||||
@@ -20,7 +20,7 @@ const ServerView = withSuspense<{
|
||||
id?: string
|
||||
title?: string
|
||||
}>(({ id, title }) => {
|
||||
const { t } = useTranslation('settings.servers')
|
||||
const { t } = useTranslation()
|
||||
const navigation = useNavigation()
|
||||
const activeServerId = useStore(store => store.settings.activeServerId)
|
||||
const servers = useStoreDeep(store => store.settings.servers)
|
||||
@@ -143,7 +143,7 @@ const ServerView = withSuspense<{
|
||||
const ping = async () => {
|
||||
const res = await pingServer(potential)
|
||||
toast(
|
||||
t(`messages.${res ? 'connectionOk' : 'connectionFailed'}`, {
|
||||
t(`settings.servers.messages.${res ? 'connectionOk' : 'connectionFailed'}`, {
|
||||
address: potential.address,
|
||||
interpolation: { escapeValue: false },
|
||||
}),
|
||||
@@ -178,7 +178,7 @@ const ServerView = withSuspense<{
|
||||
return (
|
||||
<GradientScrollView style={styles.scroll}>
|
||||
<View style={styles.content}>
|
||||
<Text style={styles.inputTitle}>{t('fields.address')}</Text>
|
||||
<Text style={styles.inputTitle}>{t('settings.servers.fields.address')}</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
placeholderTextColor="grey"
|
||||
@@ -191,7 +191,7 @@ const ServerView = withSuspense<{
|
||||
onChangeText={setAddress}
|
||||
onBlur={formatAddress}
|
||||
/>
|
||||
<Text style={styles.inputTitle}>{t('fields.username')}</Text>
|
||||
<Text style={styles.inputTitle}>{t('settings.servers.fields.username')}</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
placeholderTextColor="grey"
|
||||
@@ -204,7 +204,7 @@ const ServerView = withSuspense<{
|
||||
value={username}
|
||||
onChangeText={setUsername}
|
||||
/>
|
||||
<Text style={styles.inputTitle}>{t('fields.password')}</Text>
|
||||
<Text style={styles.inputTitle}>{t('settings.servers.fields.password')}</Text>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
placeholderTextColor="grey"
|
||||
@@ -219,11 +219,11 @@ const ServerView = withSuspense<{
|
||||
onChangeText={setPassword}
|
||||
/>
|
||||
<SettingsSwitch
|
||||
title={t('options.forcePlaintextPassword.title')}
|
||||
title={t('settings.servers.options.forcePlaintextPassword.title')}
|
||||
subtitle={
|
||||
usePlainPassword
|
||||
? t('options.forcePlaintextPassword.descriptionOn')
|
||||
: t('options.forcePlaintextPassword.descriptionOff')
|
||||
? t('settings.servers.options.forcePlaintextPassword.descriptionOn')
|
||||
: t('settings.servers.options.forcePlaintextPassword.descriptionOff')
|
||||
}
|
||||
value={usePlainPassword}
|
||||
setValue={togglePlainPassword}
|
||||
@@ -231,17 +231,22 @@ const ServerView = withSuspense<{
|
||||
<Button
|
||||
disabled={disableControls()}
|
||||
style={styles.button}
|
||||
title={t('actions.testConnection')}
|
||||
title={t('settings.servers.actions.testConnection')}
|
||||
buttonStyle="hollow"
|
||||
onPress={test}
|
||||
/>
|
||||
<Button
|
||||
disabled={disableControls()}
|
||||
style={[styles.button, styles.delete, deleteStyle]}
|
||||
title={t('actions.delete')}
|
||||
title={t('settings.servers.actions.delete')}
|
||||
onPress={remove}
|
||||
/>
|
||||
<Button disabled={disableControls()} style={styles.button} title={t('actions.save')} onPress={save} />
|
||||
<Button
|
||||
disabled={disableControls()}
|
||||
style={styles.button}
|
||||
title={t('settings.servers.actions.save')}
|
||||
onPress={save}
|
||||
/>
|
||||
</View>
|
||||
</GradientScrollView>
|
||||
)
|
||||
|
||||
@@ -26,7 +26,7 @@ const ServerItem = withSuspenseMemo<{
|
||||
const activeServerId = useStore(store => store.settings.activeServerId)
|
||||
const switchActiveServer = useSwitchActiveServer()
|
||||
const navigation = useNavigation()
|
||||
const { t } = useTranslation('settings.servers.actions')
|
||||
const { t } = useTranslation()
|
||||
|
||||
const setActive = useCallback(() => {
|
||||
switchActiveServer(server.id)
|
||||
@@ -36,7 +36,7 @@ const ServerItem = withSuspenseMemo<{
|
||||
<SettingsItem
|
||||
title={server.address}
|
||||
subtitle={server.username}
|
||||
onPress={() => navigation.navigate('server', { id: server.id, title: t('edit') })}>
|
||||
onPress={() => navigation.navigate('server', { id: server.id, title: t('settings.servers.actions.edit') })}>
|
||||
<PressableOpacity style={styles.serverActive} onPress={setActive}>
|
||||
{activeServerId === server.id ? (
|
||||
<Icon name="checkbox-marked-circle" size={30} color={colors.accent} />
|
||||
@@ -81,12 +81,16 @@ const BitrateModal = withSuspenseMemo<{
|
||||
bitrate: number
|
||||
setBitrate: (bitrate: number) => void
|
||||
}>(({ title, bitrate, setBitrate }) => {
|
||||
const { t } = useTranslation('settings.network.values')
|
||||
const { t } = useTranslation()
|
||||
const [visible, setVisible] = useState(false)
|
||||
|
||||
const toggleModal = useCallback(() => setVisible(!visible), [visible])
|
||||
|
||||
const bitrateText = useCallback((value: number) => (value === 0 ? t('unlimitedKbps') : t('kbps', { value })), [t])
|
||||
const bitrateText = useCallback(
|
||||
(value: number) =>
|
||||
value === 0 ? t('settings.network.values.unlimitedKbps') : t('settings.network.values.kbps', { value }),
|
||||
[t],
|
||||
)
|
||||
|
||||
const BitrateChoice: React.FC<{ value: number }> = useCallback(
|
||||
({ value }) => {
|
||||
@@ -178,7 +182,7 @@ const SettingsTextModal = React.memo<{
|
||||
})
|
||||
|
||||
const SettingsContent = withSuspenseMemo(() => {
|
||||
const { t } = useTranslation('settings')
|
||||
const { t } = useTranslation()
|
||||
|
||||
const servers = useStoreDeep(store => store.settings.servers)
|
||||
const scrobble = useStore(store => store.settings.scrobble)
|
||||
@@ -209,77 +213,84 @@ const SettingsContent = withSuspenseMemo(() => {
|
||||
const setMinBufferText = useCallback((text: string) => setMinBuffer(parseFloat(text)), [setMinBuffer])
|
||||
const setMaxBufferText = useCallback((text: string) => setMaxBuffer(parseFloat(text)), [setMaxBuffer])
|
||||
|
||||
const secondsText = useCallback((value: string) => t('network.values.seconds', { value }), [t])
|
||||
const secondsText = useCallback((value: string) => t('settings.network.values.seconds', { value }), [t])
|
||||
|
||||
return (
|
||||
<View style={styles.content}>
|
||||
<Header>{t('servers.name')}</Header>
|
||||
<Header>{t('settings.servers.name')}</Header>
|
||||
{Object.values(servers).map(s => (
|
||||
<ServerItem key={s.id} server={s} />
|
||||
))}
|
||||
<Button
|
||||
style={styles.button}
|
||||
title={t('servers.actions.add')}
|
||||
onPress={() => navigation.navigate('server', { title: t('servers.actions.add') })}
|
||||
title={t('settings.servers.actions.add')}
|
||||
onPress={() => navigation.navigate('server', { title: t('settings.servers.actions.add') })}
|
||||
buttonStyle="hollow"
|
||||
/>
|
||||
<Header style={styles.header}>{t('network.name')}</Header>
|
||||
<Header style={styles.header}>{t('settings.network.name')}</Header>
|
||||
<BitrateModal
|
||||
title={t('network.options.maxBitrateWifi.title')}
|
||||
title={t('settings.network.options.maxBitrateWifi.title')}
|
||||
bitrate={maxBitrateWifi}
|
||||
setBitrate={setMaxBitrateWifi}
|
||||
/>
|
||||
<BitrateModal
|
||||
title={t('network.options.maxBitrateMobile.title')}
|
||||
title={t('settings.network.options.maxBitrateMobile.title')}
|
||||
bitrate={maxBitrateMobile}
|
||||
setBitrate={setMaxBitrateMobile}
|
||||
/>
|
||||
<SettingsTextModal
|
||||
title={t('network.options.minBuffer.title')}
|
||||
title={t('settings.network.options.minBuffer.title')}
|
||||
value={minBuffer.toString()}
|
||||
setValue={setMinBufferText}
|
||||
subtitle={secondsText}
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
<SettingsTextModal
|
||||
title={t('network.options.maxBuffer.title')}
|
||||
title={t('settings.network.options.maxBuffer.title')}
|
||||
value={maxBuffer.toString()}
|
||||
setValue={setMaxBufferText}
|
||||
subtitle={secondsText}
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
<Header style={styles.header}>{t('music.name')}</Header>
|
||||
<Header style={styles.header}>{t('settings.music.name')}</Header>
|
||||
<SettingsSwitch
|
||||
title={t('music.options.scrobble.title')}
|
||||
subtitle={scrobble ? t('music.options.scrobble.descriptionOn') : t('music.options.scrobble.descriptionOff')}
|
||||
title={t('settings.music.options.scrobble.title')}
|
||||
subtitle={
|
||||
scrobble
|
||||
? t('settings.music.options.scrobble.descriptionOn')
|
||||
: t('settings.music.options.scrobble.descriptionOff')
|
||||
}
|
||||
value={scrobble}
|
||||
setValue={setScrobble}
|
||||
/>
|
||||
<Header style={styles.header}>{t('reset.name')}</Header>
|
||||
<Header style={styles.header}>{t('settings.reset.name')}</Header>
|
||||
<Button
|
||||
disabled={clearing}
|
||||
style={styles.button}
|
||||
title={t('reset.actions.clearImageCache')}
|
||||
title={t('settings.reset.actions.clearImageCache')}
|
||||
onPress={clear}
|
||||
buttonStyle="hollow"
|
||||
/>
|
||||
<Header style={styles.header}>{t('about.name')}</Header>
|
||||
<Header style={styles.header}>{t('settings.about.name')}</Header>
|
||||
<Text style={styles.text}>
|
||||
<Text style={styles.bold}>Subtracks</Text> {t('about.version', { version })}
|
||||
<Text style={styles.bold}>Subtracks</Text> {t('settings.about.version', { version })}
|
||||
</Text>
|
||||
<Button
|
||||
disabled={clearing}
|
||||
style={styles.button}
|
||||
title={t('about.actions.projectHomepage')}
|
||||
title={t('settings.about.actions.projectHomepage')}
|
||||
onPress={() => Linking.openURL('https://github.com/austinried/subtracks')}
|
||||
buttonStyle="hollow"
|
||||
/>
|
||||
<Button
|
||||
disabled={clearing}
|
||||
style={styles.button}
|
||||
title={t('about.actions.licenses')}
|
||||
title={t('settings.about.actions.licenses')}
|
||||
onPress={() =>
|
||||
navigation.navigate('web', { uri: 'file:///android_asset/licenses.html', title: t('about.actions.licenses') })
|
||||
navigation.navigate('web', {
|
||||
uri: 'file:///android_asset/licenses.html',
|
||||
title: t('settings.about.actions.licenses'),
|
||||
})
|
||||
}
|
||||
buttonStyle="hollow"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user