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

Dev/bahl aryan/profile get attendee #18

Merged
merged 6 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
114 changes: 57 additions & 57 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,74 @@ import { config } from "@gluestack-ui/config"; // Optional if you want to use de
import { NavigationContainer, useNavigation } from "@react-navigation/native";
import { SafeAreaProvider } from "react-native-safe-area-context";
import Navigation from "./navigation/Navigation";
import Home from "./screens/Home";
import * as Linking from "expo-linking";
import Login from "./screens/Login";
import { createStackNavigator } from "@react-navigation/stack";
import store from "./redux/store";
import { Provider, useDispatch } from 'react-redux';
import { setToken } from "./redux/actions";
import { setToken, clearTokens, AuthActionTypes } from './redux/actions';
import { Dispatch } from "@reduxjs/toolkit";

const prefix = Linking.createURL("/");
console.log(prefix);
const Stack = createStackNavigator();

const App = () => {
const [data, setData] = useState(null);
const dispatch = useDispatch();

const linking = {
prefixes:[prefix],
config:{
screens: {
Home: "home",
Camera: "camera",
Events: "events",
Profile: "profile",
Shop: "shop"
}
const [data, setData] = useState(null);
const dispatch = useDispatch<Dispatch<AuthActionTypes>>();
const linking = {
prefixes:[prefix],
config:{
screens: {
Main: "Main",
Home: "home",
Camera: "camera",
Events: "events",
Profile: "profile",
Shop: "shop"
}
}

useEffect(() => {
const handleDeepLink = (event: { url: string; }) => {
const { path, queryParams } = Linking.parse(event.url);
if (queryParams.token) {
dispatch(setToken(queryParams.token));
setData({ path, queryParams });
}
};

async function getInitialURL() {
const initialURL = await Linking.getInitialURL();
if (initialURL) handleDeepLink({url: initialURL});
}

const listener = Linking.addEventListener("url", handleDeepLink);

if (!data) {
getInitialURL();
}

return () => listener.remove();
}, [dispatch]);


useEffect(() => {
const handleDeepLink = (event: { url: string; }) => {
console.log("handling deep link:", event.url);
const searchParams = new URL(event.url).searchParams;
const token = searchParams.get('token');
console.log("TOKEN", token);
dispatch(setToken(token))
}

async function getInitialURL() {
const initialURL = await Linking.getInitialURL();
console.log("getting initial URL:", initialURL);
if (initialURL) handleDeepLink({url: initialURL});
}

getInitialURL();
const listener = Linking.addEventListener("url", handleDeepLink);

return () => listener.remove();
}, [dispatch]);

return (
<GluestackUIProvider config={config}>
<SafeAreaProvider>
<NavigationContainer linking={linking}>
<Stack.Navigator screenOptions={{ headerShown: false}} initialRouteName="Login">
<Stack.Screen name="Login" component={Login}/>
<Stack.Screen name="Main" component={Navigation}/>
</Stack.Navigator>
</NavigationContainer>
</SafeAreaProvider>
</GluestackUIProvider>
);
}

export default function AppWrapper() {
return (
<GluestackUIProvider config={config}>
<SafeAreaProvider>
<NavigationContainer linking={linking}>
<Stack.Navigator screenOptions={{ headerShown: false}}>
<Stack.Screen name="Login" component={Login}/>
<Stack.Screen name="Main" component={Navigation}/>
</Stack.Navigator>
</NavigationContainer>
</SafeAreaProvider>
</GluestackUIProvider>
<Provider store={store}>
<App />
</Provider>
);
}

export default function AppWrapper() {
return (
<Provider store={store}>
<App />
</Provider>
);
}
}
6 changes: 6 additions & 0 deletions Components/Images.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const Images = styled(Image,
{
variants: {
variant: {
qrCode: {
height: 300,
width: 300,
borderRadius: "$xl",
marginTop: "$5",
},
loginLogo: {
height: 300,
width: 300,
Expand Down
35 changes: 35 additions & 0 deletions api/getAttendee.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { setAttendee } from "../redux/actions";

export const getAttendee = (token: string) => {
return async (dispatch: any) => {
let clone;
try {
const response = await fetch('https://api.reflectionsprojections.org/attendee/', {
headers: {
'Authorization': `Bearer ${token}`,
},
});

clone = response.clone();

if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}

const data = await response.json();
console.log("attendee:", data);
dispatch(setAttendee(data));
} catch (error) {
console.error('Error fetching attendee:', error);
if (clone) {
clone.text().then((bodyText) => {
console.log('Received the following instead of valid JSON:', bodyText);
}).catch(err => {
console.error('Error reading the response body:', err);
})
}
}
};
};

//potentially optimizec
29 changes: 29 additions & 0 deletions api/getQRCode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { setQRCode } from "../redux/actions";

export const getQRCode = (token: string) => {
return async (dispatch: any) => {
try {
const response = await fetch('https://api.reflectionsprojections.org/attendee/qr/', {
headers: {
'Authorization': `${token}`,
'Content-Type': 'application/json'
},
});
const data = await response.json();
dispatch(setQRCode(data));

// Refresh the QR Code every 20 seconds
setInterval(async () => {
const refreshResponse = await fetch('https://api.reflectionsprojections.org/attendee/qr/', {
headers: {
'Authorization': `${token}`,
},
});
const refreshData = await refreshResponse.json();
dispatch(setQRCode(refreshData));
}, 20000)
} catch (error) {
console.error('Error fetching qrcode:', error);
}
};
};
10 changes: 3 additions & 7 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"expo": {
"scheme": "myapp",
"scheme": "reflectionsprojections",
"name": "rp-mobile-2024",
"slug": "rp-mobile-2024",
"version": "1.0.0",
Expand Down Expand Up @@ -34,16 +34,12 @@
},
"permissions": [
"android.permission.CAMERA"
]
],
"package": "com.rpdev2024.rpmobile2024"
},
"web": {
"favicon": "./assets/favicon.png"
},
"extra": {
"eas": {
"projectId": "d54e6f30-0fdc-427a-bab4-a1bad3a57fcf"
}
},
"runtimeVersion": {
"policy": "appVersion"
},
Expand Down
Loading
Loading