Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Groups Page #106

Merged
merged 19 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/groups/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const platformIcons: Record<
},
facebook: {
svg: facebook,
width: 24,
width: 25,
heigth: 24,
},
}
25 changes: 9 additions & 16 deletions src/components/Groups/AnimatedPoliSearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
import { Group } from "api/groups"
import { PoliSearchBar } from "components/Home"
import React, { FC } from "react"
import React, { FC, useState } from "react"
import { View, ViewStyle } from "react-native"
import { AnimatedLine } from "./AnimatedLine"


export interface AnimatedPoliSearchBarProps {
setSearch: (val: string) => void
isSearching: boolean
setIsSearching: (val: boolean) => void
groups?: Group[]
onSearch: (val: string) => void
style?: ViewStyle
}

export const AnimatedPoliSearchBar: FC<
AnimatedPoliSearchBarProps
> = props => {

export const AnimatedPoliSearchBar: FC<AnimatedPoliSearchBarProps> = props => {
const [isSearching, setIsSearching] = useState(false)
return (
<View style={props.style}>
<PoliSearchBar
onChange={val => {
props.setSearch(val)
props.onSearch(val)
if (val !== "") {
props.setIsSearching(true)
} else if (props.isSearching === true) {
props.setIsSearching(false)
setIsSearching(true)
} else if (isSearching === true) {
setIsSearching(false)
}
}}
style={{ marginTop: 0, marginBottom: 0 }}
/>
<AnimatedLine mounted={props.isSearching} />
<AnimatedLine mounted={isSearching} />
</View>
)
}
127 changes: 67 additions & 60 deletions src/components/Groups/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { ModalSelection, SelectTile } from "components/Settings"
import { getNameFromMode, ValidModalType } from "utils/groups"

export interface FiltersProps {
year: string
setYear: (value: string) => void
course: string
setCourse: (value: string) => void
type: string
setType: (value: string) => void
platform: string
setPlatform: (value: string) => void
forceSearch: () => void
filters: Filters
onFilterChange: (filters: Filters) => void
}

export interface Filters {
year?: string
course?: string
platform?: string
type?: string
}

interface ModalItemList {
Expand All @@ -23,8 +23,20 @@ interface ModalItemList {
}

const yearsList: ModalItemList = {
itemsToShow: [ "2022/2023","2021/2022", "2020/2021", "2019/2020", "2018/2019"],
itemsToSave: [ "2022/2023","2021/2022", "2020/2021", "2019/2020", "2018/2019"],
itemsToShow: [
"2022/2023",
"2021/2022",
"2020/2021",
"2019/2020",
"2018/2019",
],
itemsToSave: [
"2022/2023",
"2021/2022",
"2020/2021",
"2019/2020",
"2018/2019",
],
}
const coursesList: ModalItemList = {
itemsToShow: ["Triennale", "Magistrale", "Ciclo unico"],
Expand All @@ -41,8 +53,6 @@ const platformsList: ModalItemList = {
itemsToSave: ["WA", "FB", "TG"],
}

//to avoid writing mistakes
const all = "Tutti"

export const Filters: FC<FiltersProps> = props => {
//show or hide modal
Expand All @@ -52,27 +62,13 @@ export const Filters: FC<FiltersProps> = props => {
//items to show inside modal
const [modalItems, setModalItems] = useState<ModalItemList>(yearsList)
//currently selected item inside modal
const [selectedItem, setSelectedItem] = useState<string>(all)
const [selectedItem, setSelectedItem] = useState<string | undefined>(
undefined
)

//update state when user taps "OK" in modal
const updateSelectedFilter = () => {
if (modalMode === "year") {
props.setYear(selectedItem)
} else if (modalMode === "course") {
props.setCourse(selectedItem)
} else if (modalMode === "platform") {
props.setPlatform(selectedItem)
} else {
props.setType(selectedItem)
}
}
//reset state on "reset"
const reset = () => {
props.setYear(all)
props.setCourse(all)
props.setType(all)
props.setPlatform(all)
props.forceSearch()
props.onFilterChange({})
}

return (
Expand All @@ -81,63 +77,56 @@ export const Filters: FC<FiltersProps> = props => {
style={{
flexDirection: "row",
flexWrap: "wrap",
paddingHorizontal: 10,
}}
>
<OutlinedButton
text="Anno"
buttonStyle={[
styles.buttonRightMargin,
styles.buttonBottomMargin,
]}
isSelected={props.year !== all ? true : false}
buttonStyle={styles.buttonCustomMargin}
isSelected={props.filters.year ? true : false}
onPress={() => {
setModalMode("year")
setModalItems(yearsList)
setSelectedItem(props.year)
setSelectedItem(props.filters.year)
setIsModalShowing(true)
}}
/>
<OutlinedButton
text="Corso"
buttonStyle={[
styles.buttonRightMargin,
styles.buttonBottomMargin,
]}
isSelected={props.course !== all ? true : false}
buttonStyle={styles.buttonCustomMargin}
isSelected={props.filters.course ? true : false}
onPress={() => {
setModalMode("course")
setModalItems(coursesList)
setSelectedItem(props.course)
setSelectedItem(props.filters.course)
setIsModalShowing(true)
}}
/>
<OutlinedButton
text="Tipo"
buttonStyle={styles.buttonBottomMargin}
isSelected={props.type !== all ? true : false}
buttonStyle={styles.buttonCustomMargin}
isSelected={props.filters.type ? true : false}
onPress={() => {
setModalMode("type")
setModalItems(typesList)
setSelectedItem(props.type)
setSelectedItem(props.filters.type)
setIsModalShowing(true)
}}
/>
<OutlinedButton
text="Piattaforma"
buttonStyle={styles.buttonRightMargin}
isSelected={props.platform !== all ? true : false}
buttonStyle={styles.buttonCustomMargin}
isSelected={props.filters.platform ? true : false}
onPress={() => {
setModalMode("platform")
setModalItems(platformsList)
setSelectedItem(props.platform)
setSelectedItem(props.filters.platform)
setIsModalShowing(true)
}}
/>
<OutlinedButton
text="Reset"
isSpecial={true}
buttonStyle={{ minWidth: 48 }}
buttonStyle={[{ minWidth: 48 }, styles.buttonCustomMargin]}
onPress={reset}
/>
</View>
Expand All @@ -147,17 +136,36 @@ export const Filters: FC<FiltersProps> = props => {
onClose={() => {
setIsModalShowing(false)
}}
selectedValue={selectedItem}
onOK={() => {
updateSelectedFilter()
if (modalMode === "course") {
props.onFilterChange({
...props.filters,
course: selectedItem,
})
} else if (modalMode === "platform") {
props.onFilterChange({
...props.filters,
platform: selectedItem,
})
} else if (modalMode === "year") {
props.onFilterChange({
...props.filters,
year: selectedItem,
})
} else if (modalMode === "type") {
props.onFilterChange({
...props.filters,
type: selectedItem,
})
}
setIsModalShowing(false)
}}
>
<SelectTile
value={all}
selected={selectedItem === all}
value={"Tutti"}
selected={selectedItem === undefined}
onPress={() => {
setSelectedItem(all)
setSelectedItem(undefined)
}}
/>
{modalItems?.itemsToShow.map((itemName, index) => {
Expand All @@ -180,10 +188,9 @@ export const Filters: FC<FiltersProps> = props => {
}

const styles = StyleSheet.create({
buttonRightMargin: {
marginRight: 8,
},
buttonBottomMargin: {
buttonCustomMargin: {
marginRight: 4,
marginLeft: 4,
marginBottom: 8,
},
})
1 change: 0 additions & 1 deletion src/components/Groups/GroupTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const GroupTile: FC<GroupTileProps> = props => {

const iconSvg = useSVG(props.icon?.svg)


return (
<View style={{ flex: 1 }}>
<Pressable
Expand Down
10 changes: 6 additions & 4 deletions src/components/Groups/ModalGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface ModalGroupProps {
*
*/
export const ModalGroup: FC<ModalGroupProps> = props => {
const { backgroundSecondary, modalBarrier } = usePalette()
const { backgroundSecondary, modalBarrier, isLight } = usePalette()

const deleteSvg = useSVG(icon.svg)
return (
Expand All @@ -65,7 +65,6 @@ export const ModalGroup: FC<ModalGroupProps> = props => {
height: 30,
backgroundColor: "#ffffff",
borderRadius: 15,
marginTop: 96,
marginBottom: 8,
justifyContent: "center",
alignItems: "center",
Expand Down Expand Up @@ -108,8 +107,11 @@ export const ModalGroup: FC<ModalGroupProps> = props => {
}}
>
<ButtonCustom
overrideLight="#424967"
overrideDark="#8791BD"
style={{
backgroundColor: isLight
? "#424967"
: "#8791BD",
}}
text={"JOIN GROUP"}
onPress={() => props.onJoin(props.group)}
/>
Expand Down
10 changes: 4 additions & 6 deletions src/components/Settings/ButtonCustom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export interface ButtonCustomProps {
*/
light?: boolean
onPress?: () => void
buttonStyle?: ViewStyle
overrideLight?: string
overrideDark?: string
style?: ViewStyle
}
/**
* Custom button component. Specify param `light` to select button type
Expand All @@ -28,14 +26,14 @@ export const ButtonCustom: FC<ButtonCustomProps> = props => {
{
backgroundColor: props.light
? isLight
? (props.overrideLight ?? palette.lighter)
: (props.overrideDark ?? palette.darker)
? (palette.lighter)
: ( palette.darker)
: isLight
? palette.darker
: palette.lighter,
minWidth: 130,
},
props.buttonStyle,
props.style,
]}
onPress={props.onPress}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Settings/CareerTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const CareerTile: FC<CareerTileProps> = props => {
<ButtonCustom
onPress={props.onPress}
text={"Cambia matricola"}
buttonStyle={{ paddingHorizontal: 8 }}
style={{ paddingHorizontal: 8 }}
/>
<CareerColumn career={props.career}></CareerColumn>
</View>
Expand Down
6 changes: 0 additions & 6 deletions src/components/Settings/ModalSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ export interface ModalSelectionProps {
*/
onOK: () => void

/**
* input value of `onOk` function.
* Usually the current state value of a {@link RadioButtonGroup}
*/
selectedValue: string

/**
* modal wrapper height, specify if height is fixed
*/
Expand Down
Loading