2023-02-28 07:26:27 -08:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
2023-02-27 05:25:59 -08:00
|
|
|
|
2023-02-28 07:26:27 -08:00
|
|
|
import { HStack, Icon, IconButton, Input, Stack } from 'soapbox/components/ui';
|
2023-02-27 05:25:59 -08:00
|
|
|
|
|
|
|
import PopularGroups from './components/discover/popular-groups';
|
2023-03-29 10:21:28 -07:00
|
|
|
import PopularTags from './components/discover/popular-tags';
|
2023-02-28 12:03:03 -08:00
|
|
|
import Search from './components/discover/search/search';
|
2023-02-27 05:25:59 -08:00
|
|
|
import SuggestedGroups from './components/discover/suggested-groups';
|
|
|
|
import TabBar, { TabItems } from './components/tab-bar';
|
|
|
|
|
2023-02-28 07:26:27 -08:00
|
|
|
const messages = defineMessages({
|
|
|
|
placeholder: { id: 'groups.discover.search.placeholder', defaultMessage: 'Search' },
|
|
|
|
});
|
|
|
|
|
2023-02-27 05:25:59 -08:00
|
|
|
const Discover: React.FC = () => {
|
2023-02-28 07:26:27 -08:00
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
const [isSearching, setIsSearching] = useState<boolean>(false);
|
|
|
|
const [value, setValue] = useState<string>('');
|
|
|
|
|
|
|
|
const hasSearchValue = value && value.length > 0;
|
|
|
|
|
|
|
|
const cancelSearch = () => {
|
|
|
|
clearValue();
|
|
|
|
setIsSearching(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
const clearValue = () => setValue('');
|
|
|
|
|
2023-02-27 05:25:59 -08:00
|
|
|
return (
|
|
|
|
<Stack space={4}>
|
|
|
|
<TabBar activeTab={TabItems.FIND_GROUPS} />
|
|
|
|
|
|
|
|
<Stack space={6}>
|
2023-02-28 07:26:27 -08:00
|
|
|
<HStack alignItems='center'>
|
|
|
|
{isSearching ? (
|
|
|
|
<IconButton
|
|
|
|
src={require('@tabler/icons/arrow-left.svg')}
|
|
|
|
iconClassName='mr-2 h-5 w-5 fill-current text-gray-600'
|
|
|
|
onClick={cancelSearch}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
<Input
|
|
|
|
data-testid='search'
|
|
|
|
type='text'
|
|
|
|
placeholder={intl.formatMessage(messages.placeholder)}
|
|
|
|
value={value}
|
|
|
|
onChange={(event) => setValue(event.target.value)}
|
|
|
|
onFocus={() => setIsSearching(true)}
|
|
|
|
outerClassName='mt-0 w-full'
|
|
|
|
theme='search'
|
|
|
|
append={
|
|
|
|
<button onClick={clearValue}>
|
|
|
|
<Icon
|
|
|
|
src={hasSearchValue ? require('@tabler/icons/x.svg') : require('@tabler/icons/search.svg')}
|
|
|
|
className='h-4 w-4 text-gray-700 dark:text-gray-600'
|
|
|
|
aria-hidden='true'
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</HStack>
|
|
|
|
|
|
|
|
{isSearching ? (
|
|
|
|
<Search
|
|
|
|
searchValue={value}
|
|
|
|
onSelect={(newValue) => setValue(newValue)}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<PopularGroups />
|
|
|
|
<SuggestedGroups />
|
2023-03-29 10:21:28 -07:00
|
|
|
<PopularTags />
|
2023-02-28 07:26:27 -08:00
|
|
|
</>
|
|
|
|
)}
|
2023-02-27 05:25:59 -08:00
|
|
|
</Stack>
|
|
|
|
</Stack>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Discover;
|