Skip to content

Commit

Permalink
Polish pt. 1 - going to submit a pr
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-brennan2005 committed Apr 17, 2024
1 parent 18932ce commit b2a7d6d
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 126 deletions.
47 changes: 27 additions & 20 deletions frontend/sac-mobile/app/(app)/search/_components/club-card.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
import { useClubTags } from "@/hooks/use-club-tags";

Check failure on line 1 in frontend/sac-mobile/app/(app)/search/_components/club-card.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `ClubTags·}·from·"@/hooks/use-club-tags";⏎import·{·Club·}·from·"@/types/club";⏎import·{·useState,·useEffect·}·from·"react"` with `Effect,·useState·}·from·'react'`
import { Club } from "@/types/club";
import { useState, useEffect } from "react";

Check failure on line 3 in frontend/sac-mobile/app/(app)/search/_components/club-card.tsx

View workflow job for this annotation

GitHub Actions / Lint

'useState' is defined but never used

Check failure on line 3 in frontend/sac-mobile/app/(app)/search/_components/club-card.tsx

View workflow job for this annotation

GitHub Actions / Lint

'useEffect' is defined but never used
import { ScrollView, Text, View, ViewProps } from "react-native";
import { Pressable, ScrollView, Text, View, ViewProps } from "react-native";

Check failure on line 4 in frontend/sac-mobile/app/(app)/search/_components/club-card.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `"react-native"` with `'react-native';⏎⏎import·{·useClubTags·}·from·'@/hooks/use-club-tags';⏎import·{·Club·}·from·'@/types/club'`

export interface ClubCardProps extends ViewProps {}
export interface ClubCardProps extends ViewProps {
club?: Club

Check failure on line 7 in frontend/sac-mobile/app/(app)/search/_components/club-card.tsx

View workflow job for this annotation

GitHub Actions / Lint

Insert `;`
showTags?: boolean,

Check failure on line 8 in frontend/sac-mobile/app/(app)/search/_components/club-card.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `,` with `;`
}

Check failure on line 9 in frontend/sac-mobile/app/(app)/search/_components/club-card.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `⏎`


// @refresh reset
export const ClubCard = (p: ClubCardProps) => {
const tags = [
"Club Sport",
"Competitive",
"Yearly",
"Coed",
"Beginners Welcomed",
].map((val, ind, arr) => {
const { data: tags, isLoading, error } = useClubTags(p.club ? p.club.id : "tester");

Check failure on line 14 in frontend/sac-mobile/app/(app)/search/_components/club-card.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `·data:·tags,·isLoading,·error·}·=·useClubTags(p.club·?·p.club.id·:·"tester"` with `⏎········data:·tags,⏎········isLoading,⏎········error⏎····}·=·useClubTags(p.club·?·p.club.id·:·'tester'`

const tagComponents = !isLoading && error == null ? tags!.map((val, ind, arr) => {

Check failure on line 16 in frontend/sac-mobile/app/(app)/search/_components/club-card.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `·!isLoading·&&·error·==·null` with `⏎········!isLoading·&&·error·==·null⏎···········`

Check failure on line 16 in frontend/sac-mobile/app/(app)/search/_components/club-card.tsx

View workflow job for this annotation

GitHub Actions / Lint

'ind' is defined but never used. Allowed unused args must match /^_/u
return (
<View key={val} className="border-zinc-200 border py-1 px-2 rounded-full mr-1">
<Text className="text-base font-light">{val}</Text>
<View key={val.name} className="border-zinc-200 border py-1 px-2 rounded-full mr-1">
<Text className="text-base font-light">{val.name}</Text>
</View>
);
});
}) : [];

return (
<View {...p} className="elevation bg-white rounded-xl flex flex-col p-3">
<View className="w-full h-1/2 flex flex-row items-center">
<View className="w-12 h-12 rounded-full bg-zinc-200"></View>
<Text className="ml-4 text-base">Club Name</Text>
<Pressable
onPress={() => {
console.log("TODO: Club page")
}}>
<View {...p} className="elevation bg-white rounded-xl flex flex-col p-3">
<View className="w-full h-1/2 flex flex-row items-center">
<View className="w-12 h-12 rounded-full bg-zinc-200"></View>

Check warning on line 31 in frontend/sac-mobile/app/(app)/search/_components/club-card.tsx

View workflow job for this annotation

GitHub Actions / Lint

Empty components are self-closing
<Text className="ml-4 text-base">{p.club ? p.club.name : "Club"}</Text>
</View>
{p.showTags ? <ScrollView horizontal className="w-full h-1/2 flex flex-row mt-2" showsHorizontalScrollIndicator={false}>
{tagComponents}
</ScrollView> : <></>}
</View>
<ScrollView horizontal className="w-full h-1/2 flex flex-row mt-2" showsHorizontalScrollIndicator={false}>
{tags}
</ScrollView>
</View>
</Pressable>

);
}

Expand Down
15 changes: 11 additions & 4 deletions frontend/sac-mobile/app/(app)/search/_components/search-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { useContext, useEffect, useRef, useState } from "react";
import { Text, GestureResponderEvent, TextInput, TouchableOpacity, TouchableWithoutFeedback, View, ViewProps, Pressable } from "react-native";

import SearchIcon from '@/assets/images/svg/search.svg';
import { SearchContext } from "../_layout";

export interface SearchBarProps extends ViewProps {
searchBoxEditable: boolean,
/** Will only be shown if searchBox is not editable. */
searchBoxText?: string,
focusOnLayout?: boolean,
onSearchBoxPressed?: () => ("Focus" | undefined),
onSearchSubmitted?: (query: string) => void,
cancelOrBackButton?: "Cancel" | "Back",
Expand All @@ -18,8 +20,7 @@ export const SearchBar = (p: SearchBarProps) => {
const [text, setText] = useState("");
const textInputRef: React.Ref<TextInput> = useRef(null);


const searchBoxMargin = p.cancelOrBackButton == "Cancel" ? "ml-2" : "mr-2";
// FIXME: needs to filter, users cannot search with '/' in the query
const backButton = (
<Button
onPress={() => {
Expand Down Expand Up @@ -65,12 +66,18 @@ export const SearchBar = (p: SearchBarProps) => {
editable={p.searchBoxEditable}
placeholder={"Search"}
ref={textInputRef}
value={text}
value={!p.searchBoxEditable && p.searchBoxText ? p.searchBoxText : text}
onChangeText={setText}
onSubmitEditing={(evt) => {
if (p.onSearchSubmitted) {
p.onSearchSubmitted(text)
}
}}
onLayout={(evt) => {
// FIXME: works when going from discover, but not when coming back from results or results/expanded
if (p.focusOnLayout !== undefined && p.focusOnLayout) {
textInputRef.current?.focus()
}
}}/>
</View>
</Pressable>
Expand Down
21 changes: 15 additions & 6 deletions frontend/sac-mobile/app/(app)/search/_components/top-search.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { Club } from "@/types/club";
import { useState, useEffect } from "react";
import { ScrollView, Text, View, ViewProps } from "react-native";
import { ScrollView, Text, TouchableOpacity, View, ViewProps } from "react-native";

import SearchIcon from "@/assets/images/svg/search.svg";
import { router } from "expo-router";

export interface TopSearchProps extends ViewProps {}
export interface TopSearchProps extends ViewProps {
search: string
}

export const TopSearch = (p: TopSearchProps) => {
return (
<View {...p} className="elevation bg-white rounded-xl flex flex-row p-3 items-center">
<SearchIcon className="w-5 h-5"></SearchIcon>
<Text className="ml-2 text-xs">Top Search</Text>
</View>
<TouchableOpacity
onPress={() => {
router.push(`/search/results/${p.search}`)
}}>
<View {...p} className="elevation bg-white rounded-xl flex flex-row p-3 items-center">
<SearchIcon className="w-5 h-5"></SearchIcon>

Check warning on line 19 in frontend/sac-mobile/app/(app)/search/_components/top-search.tsx

View workflow job for this annotation

GitHub Actions / Lint

Empty components are self-closing
<Text className="ml-2 text-xs">{p.search}</Text>
</View>
</TouchableOpacity>

);
}
54 changes: 5 additions & 49 deletions frontend/sac-mobile/app/(app)/search/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,14 @@ import { Club } from '@/types/club';
import { queryClubs } from '@/services/club';
import DiscoverPage from './discover';

export type QueryState = "NoQuery" | "Loading" | "Done";
export type SearchContextState = {
query: string,
queryState: QueryState,
clubs: Club[],
}

// @refresh reset

export const SearchContext = createContext<SearchContextState>({
query: "",
queryState: "NoQuery",
clubs: []
});

const SearchLayout = () => {
const [query, setQuery] = useState("");
const [queryState, setQueryState] = useState<QueryState>("NoQuery");
const [clubs, setClubs] = useState<Club[]>([]);



useEffect(() => {
if (query == "") {
setQueryState("NoQuery");
return;
} else {
setQueryState("Loading");
queryClubs(query).then((clubs) => {
// FIXME: major race condition - try making a search, then deleting/clearing it
// before its loaded.
setClubs(clubs)
setQueryState("Done");
}).catch((x) => {
console.log(":(")
})
}
}, [query])


const SearchLayout = () => {
return (
<SearchContext.Provider value={{
query: query,
queryState: queryState,
clubs: clubs
}}>
<Stack screenOptions={{ headerShown: false }}>
<Stack.Screen
name="discover"/>
</Stack>
</SearchContext.Provider>

<Stack screenOptions={{ headerShown: false }}>
<Stack.Screen
name="discover"/>
</Stack>
);
};

Expand Down
12 changes: 6 additions & 6 deletions frontend/sac-mobile/app/(app)/search/discover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const Discover = () => {
flexDirection: "column"
}}>
<View className="flex flex-row">
<TopSearch className="mr-2 w-40"/>
<TopSearch className="mr-2 w-40"/>
<TopSearch className="mr-2 w-40"/>
<TopSearch search={"COExist"} className="mr-2 w-40"/>
<TopSearch search={"Volleyball"} className="mr-2 w-40"/>
<TopSearch search={"iGEM"} className="mr-2 w-40"/>
</View>
<View className="mt-2 flex flex-row">
<TopSearch className="mr-2 w-40"/>
<TopSearch className="mr-2 w-40"/>
<TopSearch className="mr-2 w-40"/>
<TopSearch search={"Jiu Jitsu"} className="mr-2 w-40"/>
<TopSearch search={"Music"} className="mr-2 w-40"/>
<TopSearch search={"Kappa Sigma"} className="mr-2 w-40"/>
</View>
</ScrollView>

Expand Down
36 changes: 23 additions & 13 deletions frontend/sac-mobile/app/(app)/search/recents.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { } from 'react';
import { SafeAreaView, ScrollView, Text, TouchableOpacity, View } from 'react-native';
import { Pressable, SafeAreaView, ScrollView, Text, TouchableOpacity, View } from 'react-native';
import { ClubCardNoTags } from './_components/club-card';
import { SearchBar } from './_components/search-bar';
import { HorizontalEventCard } from './_components/event-card';
Expand All @@ -17,15 +17,24 @@ const Recents = () => {
"Generate"
].map((val, ind, arr) => {
return (
<View className="w-full flex flex-row mb-4 items-center">
<SearchIcon className="w-5 h-5 mr-2"></SearchIcon>
<Text className="text-base flex-grow">{val}</Text>
<TouchableOpacity>
<MaterialCommunityIcons
name="close" size={20} className="w-5 h-5">
</MaterialCommunityIcons>
</TouchableOpacity>
</View>
<Pressable
onPress={(evt) => {
router.push(`/search/results/${val}`)
}}>
<View className="w-full flex flex-row mb-4 items-center">
<SearchIcon className="w-5 h-5 mr-2"></SearchIcon>
<Text className="text-base flex-grow">{val}</Text>
<TouchableOpacity
onPress={(evt) => {
console.log("Recents removed.")
}}>
{/* <MaterialCommunityIcons
name="close" size={20} className="w-5 h-5">
</MaterialCommunityIcons> */}
</TouchableOpacity>
</View>
</Pressable>

)
})
return (
Expand All @@ -36,9 +45,10 @@ const Recents = () => {
onSearchBoxPressed={() => {
return "Focus"
}}
onSearchSubmitted={() => {
router.push('/search/results')
}}/>
onSearchSubmitted={(text) => {
router.push(`/search/results/${text}`)
}}
focusOnLayout={true}/>
<View className="flex flex-col mt-6">
<Text className="font-bold text-base mb-2">Recents</Text>
{searchRecents}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
import React, { } from 'react';
import { SafeAreaView, ScrollView, Text, TouchableOpacity, View } from 'react-native';
import { ClubCard, ClubCardNoTags } from './_components/club-card';
import { SearchBar } from './_components/search-bar';
import { EventCard, HorizontalEventCard } from './_components/event-card';
import { TopSearch } from './_components/top-search';
import { router } from 'expo-router';
import { ClubCard, ClubCardNoTags } from '../_components/club-card';
import { SearchBar } from '../_components/search-bar';
import { EventCard, HorizontalEventCard } from '../_components/event-card';
import { TopSearch } from '../_components/top-search';
import { router, useLocalSearchParams } from 'expo-router';
import { queryClubs } from '@/services/club';
import { useClubSearch } from '@/hooks/use-club-search';

const Results = () => {
// TODO: Add grayboxing.
const search: string = (useLocalSearchParams().query as any) as string
const { data, error, isLoading } = useClubSearch(search)

const clubCards = !isLoading && error == null ? data!.slice(0,2).map((club, ind, arr) => {
return (<ClubCard club={club} className="h-28 mb-2"/>);
}) : [];

const Results = () => {
return (
<SafeAreaView className="w-full h-full bg-[#fafafa] pt-[50px] flex flex-col px-[5%]">
<SearchBar
searchBoxEditable={false}
searchBoxText={search}
cancelOrBackButton='Back'/>
<ScrollView className="flex flex-col mt-6">
<View className="w-full flex flex-row justify-between items-center">
<Text className="font-bold text-base mb-2">Recommended Clubs</Text>
<TouchableOpacity
onPress={() => {
router.push("/search/results-expanded")
router.push(`/search/results/expanded/${search}`)
}}>
<Text className="text-xs text-zinc-600">
View All
</Text>
</TouchableOpacity>
</View>

<ClubCard className="h-28 mb-2"/>
<ClubCard className="h-28 mb-2"/>
{clubCards}

<View className="w-full flex flex-row justify-between items-center">
<Text className="font-bold text-base mb-2">Recommended Events</Text>
Expand All @@ -36,10 +46,16 @@ const Results = () => {
</Text>
</TouchableOpacity>
</View>

<View className="w-full h-56 flex flex-row mb-2 justify-between">
<EventCard className="w-1/2"/>
<EventCard className="w-1/2"/>
</View>

<EventCard className="w-full mb-2"/>
<EventCard className="w-full mb-2"/>
<EventCard className="w-full mb-2"/>
<View className="w-full h-56 flex flex-row mb-2 justify-between">
<EventCard className="w-1/2"/>
<EventCard className="w-1/2"/>
</View>
</ScrollView>
</SafeAreaView>
);
Expand Down
Loading

0 comments on commit b2a7d6d

Please sign in to comment.