Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscoOssian committed Jun 3, 2024
1 parent b1c9629 commit 885c95c
Show file tree
Hide file tree
Showing 36 changed files with 628 additions and 175 deletions.
13 changes: 11 additions & 2 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { startBackgroundFetch } from '@services/background';
import useAppState from '@src/hooks/useAppState';
import { useNetInfo } from '@react-native-community/netinfo';
import LottieView from 'lottie-react-native';
import { matchListener } from '@src/services/chalkSystem';
import { initMatching } from '@src/utils/backgroundPublishMatch';

const { RealmProvider } = realmContext;

Expand Down Expand Up @@ -42,8 +44,15 @@ function SplashScreenComp() {
);
}

const BACKGROUND_FETCH_TASK = 'fetch-new-messages-store-and-notify';
startBackgroundFetch(BACKGROUND_FETCH_TASK, async () => {
const BACKGROUND_FETCH_TASK_1 = 'publish-account-and-await-to-maitch';
startBackgroundFetch(BACKGROUND_FETCH_TASK_1, async () => {
initMatching();
});

initMatching();

const BACKGROUND_FETCH_TASK_2 = 'fetch-new-messages-store-and-notify';
startBackgroundFetch(BACKGROUND_FETCH_TASK_2, async () => {
iterateOverChats();
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@realm/react": "^0.4.3",
"axios": "^1.4.0",
"expo": "~48.0.21",
"expo-asset": "~8.9.1",
"expo-background-fetch": "^11.1.1",
"expo-camera": "~13.2.1",
"expo-constants": "~14.2.1",
Expand Down
1 change: 1 addition & 0 deletions src/components/common/Back/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import T from '../Touch';

export const Touch = styled(T)`
position: absolute;
padding: 10px;
left: 25px;
top: 25px;
`;
12 changes: 12 additions & 0 deletions src/components/common/Close/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { AntDesign } from '@expo/vector-icons';
import { Touch } from './styles';

const Close = ({ onPress, size }: { onPress: () => Promise<void>; size: number }) => {
return (
<Touch onPress={onPress}>
<AntDesign name="closecircle" size={size} color="red" />
</Touch>
);
};

export default Close;
5 changes: 5 additions & 0 deletions src/components/common/Close/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import styled from 'styled-components/native';

import T from '@components/common/Touch';

export const Touch = styled(T)``;
52 changes: 52 additions & 0 deletions src/components/pages/Home/NewChalk/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useRef } from 'react';
import { ActivityIndicator, Modal, Text } from 'react-native';
import LottieView from 'lottie-react-native';
import { Container, ContainerBox } from './styles';
import Close from '@src/components/common/Close';
import useRemoteAsset from '@src/hooks/useRemoteAsset';

const NewChalk = ({
text,
visible,
toggleModal,
}: {
text: string;
visible: boolean;
toggleModal: () => void;
}) => {
const animation = useRef(null);
const { data, loading } = useRemoteAsset(
'https://firebasestorage.googleapis.com/v0/b/chatalk-96c5b.appspot.com/o/app-assets%2Flottiefiles%2Fradar.json?alt=media&token=4f377968-7661-4911-8868-4de72991e798'
);

if (loading) {
return <ActivityIndicator />;
}

return (
<Modal transparent={true} animationType="slide" visible={visible}>
<Container>
<ContainerBox>
{data ? (
<LottieView
autoPlay
ref={animation}
style={{
width: 200,
height: 200,
backgroundColor: 'transparent',
}}
source={data}
/>
) : (
<Text>Error loading animation</Text>
)}
<Text>{text}</Text>
<Close size={60} onPress={async () => toggleModal()} />
</ContainerBox>
</Container>
</Modal>
);
};

export default NewChalk;
17 changes: 17 additions & 0 deletions src/components/pages/Home/NewChalk/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import styled from 'styled-components/native';

export const Container = styled.View`
flex: 1;
justify-content: center;
align-items: center;
`;

export const ContainerBox = styled.View`
width: 50%;
height: 50%;
background-color: white;
margin: 10px;
justify-content: space-between;
align-items: center;
border-radius: 100000px;
`;
File renamed without changes.
7 changes: 6 additions & 1 deletion src/hooks/useChats/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ const useChats = (id: string | undefined = undefined) => {
const chats = realmContext.useQuery<ChatType>('Chat');

if (id) return chats.filtered(`id == '${id}'`);
else return chats;
else
return [...chats].sort((a: ChatType, b: ChatType) => {
const dateA = a.lastMessage ? new Date(a.lastMessage.timestamp).getTime() : 0;
const dateB = b.lastMessage ? new Date(b.lastMessage.timestamp).getTime() : 0;
return dateB - dateA;
});
};

export default useChats;
30 changes: 0 additions & 30 deletions src/hooks/useMatchConfig/index.ts

This file was deleted.

26 changes: 26 additions & 0 deletions src/hooks/useMatchConfig/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import MatchConfigType from '@src/types/matchConfig';
import { useCallback } from 'react';
import realmContext from '@contexts/realm';
import useUser from '../useUser';
import updateRealmMatchConfig from '@src/services/realm/update/matchConfig';
import { matchingConfig } from '@src/services/localStorage/defaults';

const useMatchConfig = () => {
const realm = realmContext.useRealm();
const me = useUser();

const state = realmContext
.useQuery<MatchConfigType>('MatchingConfig')
.filtered(`id == '${me?.id}'`)[0];

const change = useCallback(
(value: MatchConfigType) => {
updateRealmMatchConfig(realm, { id: me.id, ...value });
},
[me]
);

return { matchConfig: state ?? matchingConfig, setMatchConfig: change };
};

export default useMatchConfig;
32 changes: 32 additions & 0 deletions src/hooks/useRemoteAsset/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useEffect, useState } from 'react';
import { Asset } from 'expo-asset';

const useRemoteAsset = (url: string) => {
const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);

useEffect(() => {
const loadRemote = async () => {
try {
const asset = Asset.fromURI(url);
await asset.downloadAsync();
const response = await fetch(asset.uri);
const jsonData = await response.json();
setData(jsonData);
} catch (error) {
console.error('Error loading remote JSON asset:', error);
} finally {
setLoading(false);
}
};

loadRemote();
}, []);

return {
data,
loading,
};
};

export default useRemoteAsset;
39 changes: 7 additions & 32 deletions src/pages/Account/editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useState } from 'react';
import * as FileSystem from 'expo-file-system';
import styled from 'styled-components/native';
import { useTranslation } from 'react-i18next';

Expand All @@ -17,36 +16,12 @@ import useUser from '@hooks/useUser';
import setFireUser from '@services/firebase/set/user';
import setProfileImage from '@services/firebase/set/profileImage';

import { fileCache } from '@src/services/realm/fileCache';
import { classifyImage } from '@src/services/chalkSystem';

import realmContext from '@contexts/realm';
import Done from '@src/components/pages/Account/Done';
import Back from '@src/components/common/Back';

const classifyImage = async (
uri: string
): Promise<{ className: string; probability: number }[]> => {
try {
const response = await FileSystem.uploadAsync(
'https://nsfw-img-detect-node.onrender.com/classify',
uri,
{
fieldName: 'image',
httpMethod: 'POST',
uploadType: FileSystem.FileSystemUploadType.MULTIPART,
}
);

return JSON.parse(response.body);
} catch (error) {
console.error('Error classifying image:', error);
Snackbar.show({
text: 'Error, Failed to classify image',
duration: Snackbar.LENGTH_SHORT,
});
return [];
}
};
import { matchingConfig } from '@src/services/localStorage/defaults';

const isNSFW = async (uri: string) => {
const api_classes = await classifyImage(uri);
Expand Down Expand Up @@ -85,6 +60,7 @@ function MyProfile({ navigation }: any) {
profilePicture: defaultFirebaseProfilePicture,
authenticated: false,
gender: '',
matchingConfig: matchingConfig,
});

const realm = realmContext.useRealm();
Expand All @@ -96,14 +72,15 @@ function MyProfile({ navigation }: any) {

useEffect(() => {
if (!me) return;
const { profilePicture, name, age, bio, gender } = me;
const { profilePicture, name, age, bio, gender, matchingConfig } = me;
setNewMe({
profilePicture,
name,
bio,
age,
gender,
});
matchingConfig,
} as UserType);
}, [me]);

const [_, pick] = usePicker({ base64: false });
Expand All @@ -117,7 +94,6 @@ function MyProfile({ navigation }: any) {

const onHandleDone = async () => {
if (!me.id || newMe === me) return;
let cached: string | null = null;
try {
let imgFire = '';
if (me.profilePicture !== newMe.profilePicture) {
Expand All @@ -128,7 +104,6 @@ function MyProfile({ navigation }: any) {
user: { ...newMe, profilePicture: imgFire },
update: true,
});
cached = (await fileCache(imgFire, realm)).path;
} else {
const { profilePicture, ...userMe } = me;
setFireUser({
Expand All @@ -139,7 +114,7 @@ function MyProfile({ navigation }: any) {
realm.write(() => {
const usr = realm.objectForPrimaryKey<UserType>('User', me.id || '');
if (!usr) return;
if (cached) usr.profilePicture = cached;
usr.profilePicture = newMe.profilePicture;
usr.name = newMe.name;
usr.age = newMe.age;
usr.name = newMe.name;
Expand Down
Loading

0 comments on commit 885c95c

Please sign in to comment.