Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
feat(tabs): filter search open tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
LeslieOA committed Jul 16, 2021
1 parent 225f348 commit 83715ce
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ To build and run on a connected device:

### Building for Apple Silicon

When building on an M1 processor, some
When building with an M1 processor, use the following:

Install CocoaPods with:
```sudo arch -x86_64 gem install cocoapods```
Expand Down
49 changes: 44 additions & 5 deletions src/views/TabsView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useRecoilState } from 'recoil';
import { useNavigation } from '@react-navigation/native';
Expand All @@ -14,11 +14,18 @@ import { newTab, switchTab, removeTab } from 'src/utils/tabs';

import IconClose from 'src/assets/icons/icon-close-filled.svg';

interface TabListItemProps {
noTabs?: boolean;
}

export default function Tabs() {
const screenNavigation = useNavigation();

const [browserTabs, setBrowserTabs] = useRecoilState(browserTabsState);
const [searchTabs, setSearchTabs] = useState('');
const [filteredBrowserTabs, setFilteredBrowserTabs] = useState<
BrowserTabState[]
>(browserTabs.tabs);
const [searchTabs, setSearchTabs] = useState<string>('');

const goBack = () => screenNavigation.goBack();

Expand Down Expand Up @@ -47,6 +54,29 @@ export default function Tabs() {
);
};

const searchTabsFilter = (query: string) => {
if (query) {
const newData = browserTabs.tabs.filter((item) => {
const itemData = item.tabTitle
? item.tabTitle.toLocaleLowerCase()
: ''.toLocaleLowerCase();
const textData = query.toLocaleLowerCase();
console.log('\n\n\n', itemData.indexOf(textData) > -1);
return itemData.indexOf(textData) > -1;
});
console.log('\n\n\n\nSearch Filter - item:', newData, query, '\n\n\n\n');
setFilteredBrowserTabs(newData);
setSearchTabs(query);
} else {
setFilteredBrowserTabs(browserTabs.tabs);
setSearchTabs(query);
}
};

useEffect(() => {
setFilteredBrowserTabs(browserTabs.tabs);
}, [browserTabs.tabs]);

return (
<>
<BlurViewContainer blurType={IsDarkMode() ? 'dark' : 'light'} />
Expand All @@ -62,7 +92,8 @@ export default function Tabs() {
placeholder="Search by tab title or address"
value={searchTabs}
onChangeText={(query: string) => {
setSearchTabs(query);
// setSearchTabs(query);
searchTabsFilter(query);
}}
onSubmitEditing={() => {
console.log('TODO - Search for wallet information');
Expand All @@ -86,12 +117,13 @@ export default function Tabs() {

{browserTabs.tabs.length ? (
<TabList
data={browserTabs.tabs}
// data={browserTabs.tabs}
data={filteredBrowserTabs}
renderItem={_renderItem}
keyExtractor={(item, index) => index.toString()}
/>
) : (
<TabListItem>
<TabListItem noTabs>
<TabListItemTitle>No tabs</TabListItemTitle>
</TabListItem>
)}
Expand Down Expand Up @@ -165,6 +197,13 @@ const TabListItem = styled.Pressable`
border-bottom-color: ${(props) => props.theme.addressBar.background};
font-weight: 600;
padding: 20px 20px 20px 20px;
${({ noTabs }: TabListItemProps) =>
noTabs === true &&
`
border-bottom-width: 0;
padding-bottom: 10px;
opacity: .5;
`}
`;
const TabListItemTitle = styled.Text`
color: ${(props) => props.theme.colors.title};
Expand Down

0 comments on commit 83715ce

Please sign in to comment.