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

New filter options, owner aditions and feedback #110

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
5 changes: 3 additions & 2 deletions restapi/src/builders/locationBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export function thingToLocation(locationThing:Thing) : Location {
latitude: getDecimal(locationThing, SCHEMA_INRUPT.latitude)!,
longitude: getDecimal(locationThing, SCHEMA_INRUPT.longitude)!,
isShared: false,
isOwnLocation: false
isOwnLocation: false,
owner:""
}
}

//TODO: añadir owner
export function locationToThing(location:Location):Thing{
return buildThing(createThing())
.addStringNoLocale(SCHEMA_INRUPT.name, location.name)
Expand Down
6 changes: 4 additions & 2 deletions restapi/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ export type Location = {
latitude:number,
longitude:number
isShared:boolean,
isOwnLocation:boolean
isOwnLocation:boolean,
owner:string
};

export type Review = {
markerId:string,
comment:string,
score:double,
encodedPhoto:string
encodedPhoto:string,
owner:string
}

export type Friend = {
Expand Down
106 changes: 63 additions & 43 deletions webapp/src/components/FriendsPage/FriendsView.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import React, { ReactNode } from 'react';
import {
Stack,
Container,
Box,
Flex,
Text,
Heading,
SimpleGrid,
Grid,
Table,
Thead,
Th,
Tr,
Tbody,
useColorModeValue,
FormControl,
Input,
FormLabel,
Button,
HStack,
Spinner,
Stack,
Container,
Box,
Text,
Heading,
Grid,
Table,
Thead,
Th,
Tr,
Tbody,
useColorModeValue,
FormControl,
Input,
FormLabel,
Button,
HStack,
Spinner, useToast,
} from '@chakra-ui/react';
import {useGetFriendsQuery, useAddFriendMutation} from "../../app/services/Friend";
import {Friend} from '../../types';
Expand All @@ -29,6 +27,7 @@ export function AddFriendsView(){
let [addFriendMutation, {isLoading, isError, error}] = useAddFriendMutation();
let [webId, setWebId] = React.useState('');
let [nickName, setNickName] = React.useState('');
const toast = useToast();

return (
<Stack spacing={4} bg={useColorModeValue('gray.50', 'gray.800')} paddingBottom={'1'} paddingTop={'1'}>
Expand All @@ -38,27 +37,45 @@ export function AddFriendsView(){
<HStack maxW={'100vw'}>
<form id={"addFriend"} onSubmit={
(event) => {
event.preventDefault();
const newFriend: Friend = {
webId: webId, nickName: nickName,
loMapOnly: false, name: "", profilePic: "",
};
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
if(webId.trim().length>0 && nickName.trim().length>0) {
event.preventDefault();
addFriendMutation(newFriend);

};
handleSubmit(event)
/* TODO:
Right now when we do this, the textfield is not restored so:
- visually there is something written
- You can submit the form because the is something written
- But the field that is sent is empty
- We need to restore the textfield someway or dont erase the content here

setWebId("");
setNickName("");
*/
setWebId('');
setNickName('');
const newFriend: Friend = {
webId: webId, nickName: nickName,
loMapOnly: false, name: "", profilePic: "",
};
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
addFriendMutation(newFriend);
if (!isError) {
toast({
title: 'Friend Added',
description: "The friend has been added successfully.",
status: 'success',
duration: 7000,
isClosable: true,
});
} else {
toast({
title: 'Friend not added',
description: "There has been an error adding the friend.",
status: 'error',
duration: 7000,
isClosable: true,
});
}
};
handleSubmit(event)
} else {
toast({
title: 'Fields not correctly filled',
description: "Please fill both fields before submitting.",
status: 'warning',
duration: 7000,
isClosable: true,
});
}
}}/>
<Box>
<FormControl isRequired>
Expand All @@ -67,6 +84,7 @@ export function AddFriendsView(){
placeholder="asdfghjkl123456"
_placeholder={{color: 'gray.500'}}
type="text"
value={webId}
onChange={(e) => setWebId(e.currentTarget.value)}
/>
</FormControl>
Expand All @@ -78,6 +96,7 @@ export function AddFriendsView(){
placeholder="Motosarius"
_placeholder={{color: 'gray.500'}}
type="text"
value={nickName}
onChange={(e) => setNickName(e.currentTarget.value)}
/>
</FormControl>
Expand All @@ -90,9 +109,10 @@ export function AddFriendsView(){
_hover={{
bg: 'orange.500',
}}>
{ isLoading? <Spinner /> : "Add" }
{isLoading ?
( <Spinner ></Spinner>) :
(<p>Add</p>)}
</Button>

</HStack>
</Stack>

Expand Down Expand Up @@ -124,7 +144,7 @@ export default function FriendsView(): JSX.Element {
Your friends
</Heading>
{isLoading
? (<h2>Cargando amigos <Spinner></Spinner> </h2>)
? (<h2>Loading friends <Spinner></Spinner> </h2>)
: (<Table variant="striped" colorScheme="black" size="sm">
<Thead>
<Tr>
Expand Down
Loading