-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DMAPP-149: Integrate channel categories (#151)
* DMAPP-149: Channel Categories - Completed UI integration - Completed API integration - Work in progress: Handling search and category filter functionality * DMAPP-149: Integrate channel categories - Implemented handling of search and category filters. - Ensured reset of the previous filter when a new one is applied. * DMAPP-149: Integrate channel categories enhancements - Disabled onPress event for the active category. - Added a new message to display when data is unavailable. * DMAPP-149: Minor fix in Pill component * DMAPP-149: Code level changes - Minor changes in Pill and channelsDisplayer component
- Loading branch information
1 parent
3e01dd4
commit 3d6d3d9
Showing
10 changed files
with
249 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, {FC} from 'react'; | ||
import {Pressable, StyleSheet, Text} from 'react-native'; | ||
import Globals from 'src/Globals'; | ||
|
||
import {PillProps} from '.'; | ||
|
||
const Pill: FC<PillProps> = ({data, value, onChange, disabled}) => { | ||
const isActive = data.value === value; | ||
return ( | ||
<Pressable | ||
disabled={disabled} | ||
onPress={() => onChange(data)} | ||
style={[ | ||
styles.mainView, | ||
isActive ? styles.activeView : styles.inactiveView, | ||
]}> | ||
<Text | ||
style={[ | ||
styles.labelText, | ||
isActive ? styles.activeText : styles.inactiveText, | ||
]}> | ||
{data.label} | ||
</Text> | ||
</Pressable> | ||
); | ||
}; | ||
|
||
export {Pill}; | ||
|
||
const styles = StyleSheet.create({ | ||
mainView: { | ||
height: 40, | ||
borderRadius: 48, | ||
paddingHorizontal: 16, | ||
paddingVertical: 8, | ||
marginRight: 8, | ||
}, | ||
activeView: { | ||
backgroundColor: Globals.COLORS.BLACK, | ||
}, | ||
inactiveView: { | ||
backgroundColor: Globals.COLORS.PILL_BG_DEFAULT, | ||
}, | ||
labelText: { | ||
fontSize: 14, | ||
fontWeight: '500', | ||
lineHeight: 20, | ||
}, | ||
activeText: { | ||
color: Globals.COLORS.WHITE, | ||
}, | ||
inactiveText: { | ||
color: Globals.COLORS.PILL_TEXT_DEFAULT, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export type PillProps = { | ||
data: PillData; | ||
value: string | number; | ||
onChange: (value: PillData) => void; | ||
disabled?: boolean; | ||
}; | ||
|
||
export type PillData = { | ||
label: string; | ||
value: string | number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './Pill'; | ||
export * from './Pill.types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, {FC, useState} from 'react'; | ||
import {ScrollView, StyleSheet, View} from 'react-native'; | ||
import Globals from 'src/Globals'; | ||
import {useChannelCategories} from 'src/hooks/channel/useChannelCategories'; | ||
|
||
import {Pill} from '../pill'; | ||
|
||
type ChannelCategoriesProps = { | ||
onChangeCategory: (category: string) => void; | ||
value: string; | ||
disabled: boolean; | ||
}; | ||
|
||
const ChannelCategories: FC<ChannelCategoriesProps> = ({ | ||
onChangeCategory, | ||
value, | ||
disabled, | ||
}) => { | ||
const {isLoading, channelCategories} = useChannelCategories(); | ||
|
||
if (!isLoading && channelCategories?.length > 0) { | ||
return ( | ||
<View style={styles.mainView}> | ||
<ScrollView showsHorizontalScrollIndicator={false} horizontal> | ||
{channelCategories.map((item, index) => ( | ||
<Pill | ||
disabled={disabled || item.value === value} | ||
key={`${index}_pill_keys`} | ||
value={value} | ||
data={item} | ||
onChange={category => { | ||
onChangeCategory(category.value as string); | ||
}} | ||
/> | ||
))} | ||
</ScrollView> | ||
</View> | ||
); | ||
} | ||
return null; | ||
}; | ||
|
||
export {ChannelCategories}; | ||
|
||
const styles = StyleSheet.create({ | ||
mainView: { | ||
height: 40, | ||
width: '100%', | ||
flexDirection: 'row', | ||
marginBottom: 16, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {useEffect, useState} from 'react'; | ||
import Globals from 'src/Globals'; | ||
import {PillData} from 'src/components/pill'; | ||
import envConfig from 'src/env.config'; | ||
|
||
type ChannelCategoriesReturnType = { | ||
isLoading: boolean; | ||
channelCategories: PillData[]; | ||
}; | ||
|
||
const useChannelCategories = (): ChannelCategoriesReturnType => { | ||
const [channelCategories, setChannelCategories] = useState<PillData[]>([]); | ||
const [isLoading, setIsLoading] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
getChannelCategories(); | ||
}, []); | ||
|
||
const getChannelCategories = async () => { | ||
setIsLoading(true); | ||
try { | ||
const requestURL = | ||
envConfig.EPNS_SERVER + envConfig.ENDPOINT_FETCH_CHANNEL_CATEGORIES; | ||
const resJson = await fetch(requestURL).then(response => response.json()); | ||
// Modify data for pill component | ||
const modifiedData = resJson?.tags?.tags.map((category: string) => ({ | ||
label: category, | ||
value: category, | ||
})); | ||
setChannelCategories([ | ||
{ | ||
label: Globals.CONSTANTS.ALL_CATEGORIES, | ||
value: Globals.CONSTANTS.ALL_CATEGORIES, | ||
}, | ||
...modifiedData, | ||
]); | ||
} catch (e) { | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}; | ||
|
||
return {isLoading, channelCategories}; | ||
}; | ||
|
||
export {useChannelCategories}; |
Oops, something went wrong.