Skip to content
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
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "tethr",
"slug": "expo-starter",
"scheme": "tethr",
"version": "1.0.0",
"version": "1.0.3",
"orientation": "portrait",
"icon": "./src/assets/splash-icon.png",
"userInterfaceStyle": "dark",
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"expo-linear-gradient": "~15.0.7",
"expo-linking": "~8.0.9",
"expo-router": "~6.0.15",
"expo-splash-screen": "~31.0.11",
"expo-status-bar": "~3.0.8",
"nativewind": "^4.1.23",
"prettier-plugin-tailwindcss": "^0.7.1",
Expand Down
39 changes: 38 additions & 1 deletion src/app/main/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,55 @@
import { Tabs, useSegments } from 'expo-router';
import '../../../global.css';
import React from 'react';
import { TouchableOpacity, View } from 'react-native';
import { StatusBar } from 'expo-status-bar';
import React, { useState, useEffect, useCallback } from 'react';
import { getFriendsList } from '@/controllers/getFriends';
import { completedTasksController } from '@/controllers/completeTask';
import { groupController } from '@/controllers/group';
import { friendRequestObserver } from '@/controllers/observers/friendRequestObserver';

import AntDesign from '@expo/vector-icons/AntDesign';
import Feather from '@expo/vector-icons/Feather';
import Ionicons from '@expo/vector-icons/Ionicons';

export default function RootLayout() {
const [incomingRequests, setIncoming] = useState<number>(0);
const segments = useSegments();

const hideTabBar =
segments.includes('camera') || segments.includes('groups') || segments.includes('tasks');

const loadFriends = useCallback(async () => {
const incomingRes = await getFriendsList.getIncomingFriendRequestsCount();
setIncoming(incomingRes);
}, [setIncoming]);

const initializeTaskObservers = () => {
console.log('Initializing task observers');
completedTasksController.initialize();
groupController.initialize();
};

useEffect(() => {
loadFriends();
}, [loadFriends]);

useEffect(() => {
initializeTaskObservers();

const unsubscribe = friendRequestObserver.subscribe((data) => {
console.log('Layout observer: reduce friends badge', data);

if (data.action === 'accept') {
setIncoming((prev) => Math.max(0, prev - 1));
} else if (data.action === 'reject') {
setIncoming((prev) => Math.max(0, prev - 1));
}
});

return () => unsubscribe();
}, []);

return (
<React.Fragment>
<StatusBar style="light" />
Expand Down Expand Up @@ -68,6 +104,7 @@ export default function RootLayout() {
options={{
tabBarIcon: ({ color, size }) => <Ionicons name="people" size={size} color={color} />,
tabBarButton: (props) => <TouchableOpacity {...(props as any)} />,
tabBarBadge: incomingRequests && incomingRequests > 0 ? incomingRequests : undefined,
}}
/>
<Tabs.Screen
Expand Down
2 changes: 1 addition & 1 deletion src/app/main/camera/chooseGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const ChooseGroup = () => {

const fetchGroupData = async () => {
try {
const allGroups = await getAllGroups.fetchUserData();
const allGroups = await getAllGroups.fetchUserData('Choose group');
setGroups(allGroups);
setFiltered(allGroups);
} catch (err) {
Expand Down
21 changes: 10 additions & 11 deletions src/app/main/camera/chooseTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ const ChooseTask = () => {
</View>

<View className="items-center">
<Text className="mb-4 text-2xl font-bold text-white">Select Task for {group_name}</Text>

<View className="flex flex-row gap-2">
<Text className="mb-4 text-2xl font-bold text-white">Select Task for</Text>
<Text className="mb-4 text-2xl font-bold text-tethr-purple">{group_name}</Text>
</View>
<View className="mb-4 w-full items-center">
<SearchBar placeholder="Search tasks..." value={query} onSearch={handleSearch} />
</View>
Expand All @@ -94,7 +96,7 @@ const ChooseTask = () => {

return (
<TouchableOpacity
className="w-full items-center rounded-xl px-4"
className={`flex w-10/12 self-center bg-tethr-gray/50 px-5 py-4 text-2xl text-white ${roundedMap[getCardType(idx, filteredTasks.length)]}`}
key={idx}
disabled={taskCompleted}
onPress={() =>
Expand All @@ -108,14 +110,11 @@ const ChooseTask = () => {
},
})
}>
<View
className={`flex w-10/12 self-center bg-tethr-gray/50 px-5 py-4 text-2xl text-white ${roundedMap[getCardType(idx, filteredTasks.length)]}`}>
<Text
className={`${taskCompleted ? 'text-tethr-light-gray/20' : 'text-white'} font-semibold`}>
{task.task_name} {task.recurring ? '(Recurring)' : ''}{' '}
{task.weekly ? '(Weekly)' : ''} {taskCompleted ? '(Completed)' : ''}
</Text>
</View>
<Text
className={`${taskCompleted ? 'text-tethr-light-gray/20' : 'text-white'} font-semibold`}>
{task.task_name} {task.recurring ? '(Recurring)' : ''}{' '}
{task.weekly ? '(Weekly)' : ''} {taskCompleted ? '(Completed)' : ''}
</Text>
</TouchableOpacity>
);
})}
Expand Down
2 changes: 2 additions & 0 deletions src/app/main/camera/takePhoto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default function Camera() {
quality: 1,
base64: true,
exif: true,
skipProcessing: false,
});

setPhoto(takenPhoto);
Expand Down Expand Up @@ -164,6 +165,7 @@ export default function Camera() {
zoom={zoom}
ref={cameraRef}
mirror={facing === 'front'}
responsiveOrientationWhenOrientationLocked
/>
<Text className="absolute left-8 top-2 w-auto items-center justify-center rounded-lg bg-tethr-gray/80 px-3 py-2 text-white">
{taskName}
Expand Down
14 changes: 13 additions & 1 deletion src/app/main/friends.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import SearchBar from '@/components/searchbar';
import { useRouter } from 'expo-router';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { getCardType } from '@/utils/cardType';
import { friendRequestObserver } from '@/controllers/observers/friendRequestObserver';

export default function FriendsScreen() {
const [friends, setFriends] = useState<FriendProps[]>([]);
Expand Down Expand Up @@ -117,10 +118,21 @@ export default function FriendsScreen() {
};
const handleAcceptRequest = async (friendId: string) => {
try {
setFriends((prev) => prev.filter((f) => f.userId !== friendId));
const acceptedFriend = incomingRequests.find((f) => f.userId === friendId);

setIncoming((prev) => prev.filter((f) => f.userId !== friendId));
setOutgoing((prev) => prev.filter((f) => f.userId !== friendId));

if (acceptedFriend) {
setFriends((prev) => [...prev, { ...acceptedFriend, buttonText: 'Remove' }]);
}

friendRequestObserver.notify({
action: 'accept',
friendId,
username: acceptedFriend?.username,
});

await getFriendsList.acceptRequest(friendId);
} catch (error) {
console.error(error);
Expand Down
10 changes: 8 additions & 2 deletions src/app/main/groups/[groupId]/createTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const CreateTask = () => {
setLoading(false);
};

const handleTaskNameChange = (text: string) => {
const filtered = text.replace(/[^a-zA-Z0-9 ]/g, '');
setTask(filtered);
};

if (loading) {
return (
<View className="flex-1 items-center justify-center">
Expand All @@ -52,7 +57,8 @@ const CreateTask = () => {
}

const handleCreateTask = async () => {
const result = await taskController.createTask(groupId, task, recurring, weekly);
const sanitizedTask = task.replace(/[^a-zA-Z0-9 ]/g, '').trim();
const result = await taskController.createTask(groupId, sanitizedTask, recurring, weekly);
setUploading(true);

if (result.success) {
Expand Down Expand Up @@ -108,7 +114,7 @@ const CreateTask = () => {
<TextInput
className="border-1 m-2 mx-auto w-full rounded-lg bg-white p-2"
value={task}
onChangeText={setTask}
onChangeText={handleTaskNameChange}
placeholder="Enter task name"
placeholderTextColor="#DEDEDE"
returnKeyType="done"
Expand Down
3 changes: 1 addition & 2 deletions src/app/main/groups/[groupId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const GroupPage = () => {
/>
</TouchableOpacity>
</View>
<View className="flex-row items-center justify-between px-[5vw] pt-4">
<View className="flex-row items-center justify-between px-[5vw] pb-4 pt-2">
<Text className="text-3xl font-bold leading-none text-white">{groupNameState}</Text>
<Pressable className="rounded-3xl bg-tethr-purple/40 px-4 py-2" onPress={leaveGroup}>
<Text className="text-white">Leave Group</Text>
Expand Down Expand Up @@ -213,7 +213,6 @@ const GroupPage = () => {

{tasks.map((task, idx) => {
const taskCompleted = isCompleted(task.task_name, groupId);
console.log(task);

return (
<TouchableOpacity
Expand Down
40 changes: 39 additions & 1 deletion src/app/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { photoRetrieve } from '@/controllers/photoRetrieve';
import { getAllGroups } from '@/controllers/group';
import { taskController, Task } from '@/controllers/tasks';
import { LinearGradient } from 'expo-linear-gradient';
import { registerHomeObserver, unregisterHomeObserver } from '@/controllers/observers/uiObservers';
import * as SplashScreen from 'expo-splash-screen';

import Tethr from '@/components/tethr';
import Groups from '@/components/groups/groups';
Expand All @@ -26,6 +28,8 @@ interface GroupWithPhotos {
}[];
}

SplashScreen.preventAutoHideAsync();

export default function Index() {
const [name, setName] = useState<string>('');
const [loading, setLoading] = useState(true);
Expand All @@ -35,16 +39,50 @@ export default function Index() {

useEffect(() => {
loadPageData();
registerHomeObserver((data) => {
console.log('Home: Observer, adding photos to relevant states', data);

setGroupsWithPhotos((prevGroups) =>
prevGroups.map((group) => {
if (group.group_id === data.groupId) {
return {
...group,
current_points: group.current_points + 1,
photos: [
{
name: data.photoUri.split('/').pop() || '',
publicUrl: data.photoUri,
createdAt: data.timestamp,
username: name,
taskName: data.taskName,
},
...group.photos,
],
};
}
return group;
})
);
});

return () => unregisterHomeObserver();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
if (!loading) {
SplashScreen.hideAsync();
}
}, [loading]);

const loadPageData = async () => {
try {
setLoading(true);

const userName = await userController.getName();
if (userName) setName(userName);

const allGroups = await getAllGroups.fetchUserData();
const allGroups = await getAllGroups.fetchUserData('Home');

const groupIds = allGroups.map((g) => g.group_id);

Expand Down
Loading