Skip to content

Commit

Permalink
Merge pull request #1 from Delemangi/feat/notification-ui
Browse files Browse the repository at this point in the history
Feat/notification UI
  • Loading branch information
Delemangi authored Feb 11, 2024
2 parents 2aab23d + 948775e commit 68a99bd
Show file tree
Hide file tree
Showing 25 changed files with 1,221 additions and 1,106 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ yarn-error.*
# The following patterns were generated by expo-cli

expo-env.d.ts
# @end expo-cli
# @end expo-cli
2 changes: 1 addition & 1 deletion .hintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"hints": {
"typescript-config/consistent-casing": "off"
}
}
}
1,842 changes: 845 additions & 997 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,32 @@
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"lint": "eslint ."
"lint": "eslint .",
"format": "eslint --fix ."
},
"dependencies": {
"@expo/vector-icons": "^14.0.0",
"@react-native-async-storage/async-storage": "1.21.0",
"@react-navigation/native": "^6.0.2",
"@react-navigation/native": "^6.1.10",
"@rneui/base": "^0.0.0-edge.2",
"@rneui/themed": "^0.0.0-edge.2",
"@tanstack/react-query": "^5.17.0",
"expo": "~50.0.5",
"@tanstack/react-query": "^5.20.1",
"expo": "~50.0.6",
"expo-constants": "~15.4.5",
"expo-font": "~11.10.2",
"expo-linking": "~6.2.2",
"expo-router": "~3.4.6",
"expo-router": "~3.4.7",
"expo-splash-screen": "~0.26.4",
"expo-status-bar": "~1.11.1",
"expo-system-ui": "~2.9.3",
"expo-web-browser": "~12.8.2",
"firebase": "^10.7.1",
"i18next": "^23.7.14",
"lodash": "^4.17.21",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-i18next": "^14.0.0",
"react-native": "0.73.2",
"react-i18next": "^14.0.5",
"react-native": "0.73.4",
"react-native-gesture-handler": "~2.14.0",
"react-native-reanimated": "~3.6.2",
"react-native-safe-area-context": "4.8.2",
Expand All @@ -41,8 +43,9 @@
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@tanstack/eslint-plugin-query": "^5.14.6",
"@types/react": "^18.2.52",
"@tanstack/eslint-plugin-query": "^5.20.1",
"@types/lodash": "^4.14.202",
"@types/react": "^18.2.55",
"eslint": "^8.56.0",
"eslint-config-universe": "^12.0.0",
"prettier": "^3.1.1",
Expand Down
27 changes: 27 additions & 0 deletions src/api/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useQuery } from "@tanstack/react-query";

import { getUrl, listUrl } from "./urls";
import { Post } from "../types/Post";

export const useGetPosts = (type: string | null) => {
return useQuery<Post[], Error>({
queryKey: ["posts", type],
enabled: Boolean(type),
queryFn: () =>
fetch(getUrl(type!))
.then((res) => res.json())
.then((data) => data.posts),
staleTime: 1000 * 60 * 5,
});
};

export const useGetPostTypes = () => {
return useQuery<string[], Error>({
queryKey: ["types"],
queryFn: () =>
fetch(listUrl())
.then((res) => res.json())
.then((data) => data.scrapers),
staleTime: Infinity,
});
};
File renamed without changes.
6 changes: 6 additions & 0 deletions src/api/urls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { config } from "@config/config";

export const getUrl = (scraperType: string) =>
`${config.BASE_URL}/get/${scraperType}`;

export const listUrl = () => `${config.BASE_URL}/list`;
39 changes: 38 additions & 1 deletion src/app/(app)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
import AppHeader from "@components/AppHeader";
import { makeStyles } from "@rneui/themed";
import { usePostStore } from "@stores/postStore";
import { Slot } from "expo-router";
import { useEffect } from "react";
import { View } from "react-native";

import { useGetPostTypes } from "../../api/hooks";

const useStyles = makeStyles((theme) => ({
container: {
display: "flex",
alignItems: "center",
justifyContent: "center",
flex: 1,
backgroundColor: theme.colors.background,
},
title: {
margin: "auto",
},
}));

const HomeLayout = () => {
return <Slot />;
const styles = useStyles();
const { data: typesData } = useGetPostTypes();
const setTypes = usePostStore((state) => state.setTypes);

useEffect(() => {
if (typesData) {
setTypes(typesData);
}
}, [typesData]);

return (
<>
<AppHeader />
<View style={styles.container}>
<Slot />
</View>
</>
);
};

export default HomeLayout;
16 changes: 11 additions & 5 deletions src/app/(app)/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import { useGetPosts } from "@api/hooks";
import { isRouteAuthenticated } from "@auth/routes";
import { PostCard } from "@components/PostCard";
import { usePostStore } from "@stores/postStore";
import { useUserStore } from "@stores/userStore";
import { usePathname } from "expo-router";
import { StatusBar } from "expo-status-bar";
import { View } from "react-native";
import { ScrollView } from "react-native";

import Login from "./login";

const App = () => {
const { user } = useUserStore();
const route = usePathname();
const postsType = usePostStore((state) => state.type);
const { data } = useGetPosts(postsType);

if (!user && route !== "/login" && route !== "/register") {
if (!user && isRouteAuthenticated(route)) {
return <Login />;
}

return (
<View>
<ScrollView>
<StatusBar style="auto" />
Hello {user?.email}
</View>
{data?.map((post) => <PostCard key={post.url} post={post} />)}
</ScrollView>
);
};

Expand Down
8 changes: 4 additions & 4 deletions src/app/(app)/login.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import LoginField from "@components/CredentialsForm";
import Error from "@components/Error";
import { useLoginUser } from "@auth/hooks";
import ErrorScreen from "@components/ErrorScreen";
import LoadingSpinner from "@components/LoadingSpinner";
import { useLoginUser } from "@hooks/auth";
import LoginField from "@components/LoginField";
import { Redirect } from "expo-router";
import { useState } from "react";

Expand All @@ -19,7 +19,7 @@ const Login = () => {
}

if (error) {
return <Error error={error.message} />;
return <ErrorScreen error={error.message} />;
}

return (
Expand Down
8 changes: 4 additions & 4 deletions src/app/(app)/register.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import LoginField from "@components/CredentialsForm";
import Error from "@components/Error";
import { useRegisterUser } from "@auth/hooks";
import ErrorScreen from "@components/ErrorScreen";
import LoadingSpinner from "@components/LoadingSpinner";
import { useRegisterUser } from "@hooks/auth";
import LoginField from "@components/LoginField";
import { Redirect } from "expo-router";
import { useState } from "react";

Expand All @@ -19,7 +19,7 @@ const Register = () => {
}

if (error) {
return <Error error={error.message} />;
return <ErrorScreen error={error.message} />;
}

return (
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions src/auth/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const UNAUTHENTICATED_ROUTES = ["login", "register"];

export const isRouteAuthenticated = (route: string) => {
return !UNAUTHENTICATED_ROUTES.includes(route);
};
55 changes: 55 additions & 0 deletions src/components/AppHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Header, Text, makeStyles } from "@rneui/themed";
import { usePostStore } from "@stores/postStore";
import React from "react";
import { ScrollView, TouchableOpacity } from "react-native";

const useStyles = makeStyles((theme) => ({
headerContainer: {
backgroundColor: theme.colors.primary,
justifyContent: "space-around",
height: 100,
},
scrollView: {
flexGrow: 0,
},
option: {
paddingHorizontal: 10,
},
optionText: {
color: theme.colors.white,
},
}));

const AppHeader = () => {
const styles = useStyles();
const { setType, types } = usePostStore((state) => state);

const handlePostTypeSelect = (type: string) => {
setType(type);
};

return (
<Header
centerComponent={
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
style={styles.scrollView}
>
{types.map((type, index) => (
<TouchableOpacity
key={index}
onPress={() => handlePostTypeSelect(type)}
style={styles.option}
>
<Text style={styles.optionText}>{type.toUpperCase()}</Text>
</TouchableOpacity>
))}
</ScrollView>
}
containerStyle={styles.headerContainer}
/>
);
};

export default AppHeader;
67 changes: 0 additions & 67 deletions src/components/CredentialsForm.tsx

This file was deleted.

18 changes: 9 additions & 9 deletions src/components/Error.tsx → src/components/ErrorScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { makeStyles, Text } from "@rneui/themed";
import { View } from "react-native";

type Props = {
error: string;
};

const useStyles = makeStyles((theme) => ({
container: {
display: "flex",
Expand All @@ -19,15 +15,19 @@ const useStyles = makeStyles((theme) => ({
},
}));

const Error = ({ error }: Props) => {
const classes = useStyles();
type Props = {
error: string;
};

const ErrorScreen = ({ error }: Props) => {
const styles = useStyles();

return (
<View style={classes.container}>
<View style={styles.container}>
<Text h3>The application has crashed.</Text>
<Text style={classes.errorText}>{error}</Text>
<Text style={styles.errorText}>{error}</Text>
</View>
);
};

export default Error;
export default ErrorScreen;
Loading

0 comments on commit 68a99bd

Please sign in to comment.