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

updated branch with hooks of pack screens #399

Open
wants to merge 21 commits into
base: andrew_testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4d615fd
experimenting with trpc query for fetching
andrew-bierman Sep 26, 2023
e4865f1
restoring trails store due to strange bug
andrew-bierman Sep 26, 2023
88f8335
updated branch with hooks of pack screens
owaisanwar Sep 28, 2023
f216951
updated the branch
owaisanwar Sep 28, 2023
010cbb3
Exploring using trpc react query for trails and parks fetching
andrew-bierman Sep 28, 2023
67d54b7
adding hooks and context
andrew-bierman Sep 28, 2023
5f14147
Merge branch 'andrew_testing' into feat/experimenting-with-trpc-query
andrew-bierman Oct 1, 2023
1f6c553
Merge branch 'andrew_testing' into trpc-react-query
andrew-bierman Oct 1, 2023
895b19e
Merge branch 'feat/experimenting-with-trpc-query' into trpc-react-query
andrew-bierman Oct 1, 2023
ea132e9
Merge pull request #409 from andrew-bierman/trpc-react-query
andrew-bierman Oct 1, 2023
f51e944
updating feed hook
andrew-bierman Oct 1, 2023
35679a9
restructuring files
andrew-bierman Oct 1, 2023
256a471
updated the search into packs and get single trip and fetch global items
owaisanwar Oct 1, 2023
d17692c
Merge branch 'feat/experimenting-with-trpc-query' into trpc-react-query
andrew-bierman Oct 1, 2023
cf72c0b
Merge pull request #411 from andrew-bierman/trpc-react-query
andrew-bierman Oct 1, 2023
9088461
Merge branch 'andrew_testing' into feat/experimenting-with-trpc-query
andrew-bierman Oct 1, 2023
70a847e
Merge branch 'andrew_testing' into trpc-react-query
andrew-bierman Oct 1, 2023
d9456ea
adding hook call to feed preview
andrew-bierman Oct 1, 2023
a019df2
Merge branch 'feat/experimenting-with-trpc-query' into trpc-react-query
andrew-bierman Oct 1, 2023
7d9829d
use park and trail updated with create page working
owaisanwar Oct 2, 2023
201562e
Merge branch 'trpc-react-query' of https://github.com/andrew-bierman/…
owaisanwar Oct 2, 2023
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
375 changes: 184 additions & 191 deletions client/.tamagui/tamagui.config.json

Large diffs are not rendered by default.

29 changes: 17 additions & 12 deletions client/app/(app)/items/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { getItemsGlobal } from '../../../store/globalItemsStore';
import { Stack } from 'expo-router';
import Head from 'expo-router/head';
import { useFetchGlobalItems } from '~/hooks/globalItems';

export default function Items() {
const [isAddItemModalOpen, setIsAddItemModalOpen] = useState(false);
Expand All @@ -21,19 +22,23 @@ export default function Items() {
// page number for pagination
const [page, setPage] = useState(1);
// it will be used as a dependency for reloading the data in case of some modifications
const [refetch, setRefetch] = useState(false);
// const [refetch, setRefetch] = useState(false);

const { enableDarkMode, enableLightMode, isDark, isLight, currentTheme } =
UseTheme();
const data = useSelector((state) => state.globalItems);

const isLoading = useSelector((state) => state.globalItems.isLoading);
const isError = useSelector((state) => state.globalItems.isError);

const { data, isLoading, isError, refetch } = useFetchGlobalItems(limit, page);
console.log("🚀 ~ file: index.js:32 ~ Items ~ data:", data)
// const data = useSelector((state) => state.globalItems);

// const isLoading = useSelector((state) => state.globalItems.isLoading);
// const isError = useSelector((state) => state.globalItems.isError);

const dispatch = useDispatch();
useEffect(() => {
dispatch(getItemsGlobal({ limit, page }));
}, [limit, page, refetch]);
// useEffect(() => {
// dispatch(getItemsGlobal({ limit, page }));
// }, [limit, page]);

return (
<ScrollView>
Expand Down Expand Up @@ -95,23 +100,23 @@ export default function Items() {
onCancel={setIsAddItemModalOpen}
>
<AddItemGlobal
setRefetch={setRefetch}
refetch={refetch}
setRefetch={() => refetch()}
// refetch={refetch}
setIsAddItemModalOpen={setIsAddItemModalOpen}
/>
</CustomModal>
</>
{!isError && Array.isArray(data.globalItems.items) ? (
{!isError ? (
<ItemsTable
limit={limit}
setLimit={setLimit}
page={page}
setPage={setPage}
data={data}
isLoading={isLoading}
totalPages={data?.globalItems?.totalPages}
totalPages={data?.totalPages}
refetch={refetch}
setRefetch={setRefetch}
setRefetch={() => refetch()}
/>
) : null}
</Box>
Expand Down
51 changes: 40 additions & 11 deletions client/app/_layout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Slot } from 'expo-router';

import { useState } from 'react';
import { Platform, View } from 'react-native';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

import Navigation from '../screens/Navigation';

Expand All @@ -14,19 +15,47 @@ import { ThemeProvider } from '../context/theme';
import FlashMessage from 'react-native-flash-message';
import Footer from '../components/footer/Footer';

import { queryTrpc, getToken } from '../trpc';
import { httpBatchLink } from '@trpc/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { api } from '~/constants/api';

import { TrpcQueryProvider } from '../context/tRPC';

export default function HomeLayout() {
const queryClient = new QueryClient();

const trpcClient = queryTrpc.createClient({
links: [
httpBatchLink({
url: `${api}/trpc`,
async headers() {
const token = await getToken('session');
return {
authorization: token ? `Bearer ${token}` : '',
};
},
}),
],
});

return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<SessionProvider>
<ThemeProvider>
<FlashMessage position="top" />
<Navigation />
<Slot />
{/* {Platform.OS === 'web' ? <Footer /> : null} */}
</ThemeProvider>
</SessionProvider>
</PersistGate>
<queryTrpc.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>
<PersistGate loading={null} persistor={persistor}>
<SessionProvider>
<ThemeProvider>
<FlashMessage position="top" />
<Navigation />
<Slot />
{/* {Platform.OS === 'web' ? <Footer /> : null} */}
</ThemeProvider>
</SessionProvider>
</PersistGate>
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</queryTrpc.Provider>
</Provider>
);
}
78 changes: 54 additions & 24 deletions client/components/SearchInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,46 @@ import { useState, useEffect } from 'react';
import { fetchTrails } from '../store/trailsStore';
import { fetchParks } from '../store/parksStore';
import {
setSelectedSearchResult,
// setSelectedSearchResult,
clearSearchResults,
fetchPhotonSearchResults,
} from '../store/searchStore';
import { fetchWeather, fetchWeatherWeek } from '../store/weatherStore';
import { fetchWeather, fetchWeatherWeek, setLatLng, setSearchResult } from '../store/weatherStore';
import useCustomStyles from '~/hooks/useCustomStyles';
import { setFilteredTrails, setTrails } from '~/store/trailsStore_copy'; // REMOVE
import useTrails from '~/hooks/trails';
import useParks from '~/hooks/parks';
import { usePhotonDetail } from '~/hooks/photonDetail';
import { useFetchWeather,useFetchWeatherWeak } from '~/hooks/weather';

export const SearchInput = ({ onSelect, placeholder }) => {
const [searchString, setSearchString] = useState('');
const [isLoadingMobile, setIsLoadingMobile] = useState(false);
const [selectedSearch, setSelectedSearch] = useState('');

const { selectedSearch } = useSelector(state => state.weather)
// const [selectedSearch, setSelectedSearch] = useState('');
const [showSearchResults, setShowSearchResults] = useState(false);

const { refetch, data, isError, isLoading } = usePhotonDetail(searchString,showSearchResults);

const { currentTheme } = useTheme();
const styles = useCustomStyles(loadStyles());
const [selectedSearchResult, setSelectedSearchResult] = useState({});
const searchResults =
useSelector((state) => state.search.searchResults) || [];
// const [latLng,setLatLng] = useState({});

// const selectedSearchResult =
// useSelector((state) => state.search.selectedSearchResult) || {};

const selectedSearchResult =
useSelector((state) => state.search.selectedSearchResult) || {};

const [showSearchResults, setShowSearchResults] = useState(false);

const dispatch = useDispatch();

useEffect(() => {
setShowSearchResults(searchString.length > 0);

const timeout = setTimeout(() => {
if (!searchString) return;
dispatch(fetchPhotonSearchResults(searchString));
refetch();
// dispatch(fetchPhotonSearchResults(searchString));
}, 2000);

return () => {
Expand All @@ -56,6 +66,7 @@ export const SearchInput = ({ onSelect, placeholder }) => {
}, [searchString, dispatch]);

const getTrailsParksAndWeatherDetails = async () => {
console.log(selectedSearchResult, 'selected search result')
if (
!selectedSearchResult ||
Object.keys(selectedSearchResult).length === 0
Expand All @@ -73,15 +84,31 @@ export const SearchInput = ({ onSelect, placeholder }) => {
if (!lat || !lon) {
setIsLoadingMobile(false);
return;
} else {
dispatch(setLatLng({ lat, lon }))
}


try {
await Promise.all([
dispatch(fetchTrails({ lat, lon, selectedSearch })),
dispatch(fetchParks({ lat, lon, selectedSearch })),
dispatch(fetchWeather({ lat, lon })),
dispatch(fetchWeatherWeek({ lat, lon })),
]);


// console.log('before parksData:', parksData);

// console.log('after parksData:', parksData);

// console.log('parksData:', parksData);

// console.log('data:', data);
// console.log('error:', error);
// console.log('isLoading:', isLoading);


// await Promise.all([
// // dispatch(fetchTrails({ lat, lon, selectedSearch })),
// // dispatch(fetchParks({ lat, lon, selectedSearch })),
// dispatch(fetchWeather({ lat, lon })),
// dispatch(fetchWeatherWeek({ lat, lon })),
// ]);
} catch (error) {
console.error(error);
}
Expand All @@ -90,6 +117,7 @@ export const SearchInput = ({ onSelect, placeholder }) => {
};

useEffect(() => {
console.log('why not here?')
const timeout = setTimeout(getTrailsParksAndWeatherDetails, 1000);

return () => {
Expand All @@ -101,11 +129,13 @@ export const SearchInput = ({ onSelect, placeholder }) => {
const {
properties: { name, osm_id },
} = result;

setSelectedSearch(name);
// console.log(result, 'line 136');
dispatch(setSearchResult(name));
setSearchString(name);
setShowSearchResults(false);
dispatch(setSelectedSearchResult(result));
setSelectedSearchResult(result);

// dispatch(setSelectedSearchResult(result));

if (onSelect) {
onSelect(result);
Expand Down Expand Up @@ -167,7 +197,7 @@ export const SearchInput = ({ onSelect, placeholder }) => {
</RStack>

<RStack style={{ position: 'relative' }}>
{showSearchResults && searchResults?.length > 0 && (
{data && data?.length > 0 && (
<RScrollView
position="absolute"
top="100%"
Expand All @@ -181,7 +211,7 @@ export const SearchInput = ({ onSelect, placeholder }) => {
zIndex={20000}
>
<RStack space={2} w="100%">
{searchResults.map((result, i) => (
{data.map((result, i) => (
<RStack
key={`result + ${i}`}
onPress={() => {
Expand Down Expand Up @@ -240,7 +270,7 @@ export const SearchInput = ({ onSelect, placeholder }) => {
}
/>

{showSearchResults && searchResults?.length > 0 && (
{showSearchResults && data?.length > 0 && (
<ScrollView
position="absolute"
top="100%"
Expand All @@ -255,7 +285,7 @@ export const SearchInput = ({ onSelect, placeholder }) => {
zIndex={10}
>
<List space={2} w="100%">
{searchResults.map((result, i) => (
{data.map((result, i) => (
<Pressable
key={`result + ${i}`}
onPress={() => {
Expand Down
23 changes: 16 additions & 7 deletions client/components/dashboard/FeedPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,33 @@ import { getPublicPacks, getPublicTrips } from '../../store/feedStore';
import useTheme from '../../hooks/useTheme';
import Carousel from '../carousel';
import useCustomStyles from '~/hooks/useCustomStyles';
import { useFeed } from '~/hooks/feed';

const { height, width } = Dimensions.get('window');

const FeedPreviewScroll = () => {
const dispatch = useDispatch();
const styles = useCustomStyles(loadStyles);

useEffect(() => {
dispatch(getPublicPacks());
dispatch(getPublicTrips());
}, []);
// useEffect(() => {
// dispatch(getPublicPacks());
// dispatch(getPublicTrips());
// }, []);

const feedData = useSelector((state) => state.feed);
const filteredFeedData = feedData.publicTrips.concat(feedData.publicPacks);
const {
data: feedData,
error,
isLoading,
} = useFeed(
// queryString = 'Most Recent',
// ownerId,
(feedType = 'public'),
(selectedTypes = { pack: true, trip: true }),
);

return (
<Carousel itemWidth={250}>
{filteredFeedData.map((item, index) => {
{feedData?.map((item, index) => {
const linkStr = `/${item.type}/${item._id}`;
return linkStr ? (
<Link href={linkStr} key={`${linkStr}`}>
Expand Down
2 changes: 1 addition & 1 deletion client/components/dashboard/HeroBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const HeroSection = ({ onSelect }) => {
console.log('selectedResult ------->', selectedResult);

// Set the selected search result in the Redux store
dispatch(setSelectedSearchResult(selectedResult));
// dispatch(setSelectedSearchResult(selectedResult));

const { osm_id, osm_type } = selectedResult.properties;

Expand Down
Loading