Skip to content

Commit

Permalink
feat(search): api integration filters
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisCusihuaman committed Nov 12, 2023
1 parent 040f4e0 commit 456f76d
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/screens/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import type { SubmitHandler } from 'react-hook-form';
import { useForm } from 'react-hook-form';
import * as z from 'zod';

import type { Snap } from '@/api';
import { getUserState } from '@/core';
import type { UserType } from '@/core/auth/utils';
import { Button, ControlledInput, ScrollView, View } from '@/ui';

const schema = z.object({
username: z
.string()
.min(3, 'First Name must be at least 3 characters')
.max(50, 'First Name cannot exceed 50 characters')
.optional(),
content: z
.string()
.min(3, 'Last Name must be at least 3 characters')
.max(50, 'Last Name cannot exceed 50 characters')
.optional(),
hashtag: z
.string()
.min(3, 'Last Name must be at least 3 characters')
.max(50, 'Last Name cannot exceed 50 characters')
.optional(),
});
Expand All @@ -30,8 +30,30 @@ export interface SearchFormProps {
onSearchSubmit?: SubmitHandler<FormType>;
}

const whenSearch: SearchFormProps['onSearchSubmit'] = (data) => {
const whenSearch: SearchFormProps['onSearchSubmit'] = async (data) => {
const currentUser = getUserState();
console.log(data);
if (data.username && data.username.trim() !== '') {
const response = await fetch(
`https://api-identity-socializer-luiscusihuaman.cloud.okteto.net/api/filter/${data.username}`
);
const users: UserType[] = await response.json();
console.log(`username: ${JSON.stringify(users)}`);
}
if (data.content && data.content.trim() !== '') {
const responseC = await fetch(
`https://api-content-discovery-luiscusihuaman.cloud.okteto.net/api/filter/content?user_id=${currentUser?.id}&content=${data.content}`
);
const snapsFromContent: Snap[] = await responseC.json();
console.log(`content:${JSON.stringify(snapsFromContent)}`);
}
if (data.hashtag && data.hashtag.trim() !== '') {
const responseH = await fetch(
`https://api-content-discovery-luiscusihuaman.cloud.okteto.net/api/filter/hashtag?user_id=${currentUser?.id}&hashtag=${data.hashtag}`
);
const snapFromHashtags: Snap[] = await responseH.json();
console.log(`hashtag: ${JSON.stringify(snapFromHashtags)}`);
}
};

export const Search: React.FC = () => {
Expand Down

0 comments on commit 456f76d

Please sign in to comment.