Skip to content

Commit

Permalink
integrating web api project with server
Browse files Browse the repository at this point in the history
  • Loading branch information
cassohir committed Jun 21, 2022
1 parent 9c82c7e commit 2756c4b
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 51 deletions.
82 changes: 41 additions & 41 deletions mobile/src/components/Form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
import { ArrowLeft } from 'phosphor-react-native';
import React, {useState} from 'react';
import { View, TextInput,Image,Text, TouchableOpacity} from 'react-native';
import React, { useState } from 'react';
import { View, TextInput, Image, Text, TouchableOpacity } from 'react-native';
import { theme } from '../../theme';
import {FeedbackType} from '../../components/Widget';
import { FeedbackType } from '../../components/Widget';
import { ScreenShotButton } from '../../components/ScreenShotButton';
import { SubmitButton } from '../../components/SubmitButton';
import {captureScreen} from 'react-native-view-shot';
import { captureScreen } from 'react-native-view-shot';
import * as FileSystem from 'expo-file-system';

import { styles } from './styles';
import {feedbackTypes} from '../../utils/feedbackTypes';
import { feedbackTypes } from '../../utils/feedbackTypes';
import { api } from '../../libs/api';

interface PropsForm {
feedbackType: FeedbackType;
onFeedbackCanceled: ()=> void;
onFeedbackCanceled: () => void;
onFeedbackSent: () => void;
}

export function Form({feedbackType, onFeedbackCanceled, onFeedbackSent}: PropsForm) {
export function Form({ feedbackType, onFeedbackCanceled, onFeedbackSent }: PropsForm) {

const [isSendingFeedback, setIsSendingFeedback] = useState(false);

const [comment,setComment] = useState('');

const [screenshot,setScreenShot] = useState<string | null>(null);
const [comment, setComment] = useState('');

const [screenshot, setScreenShot] = useState<string | null>(null);

const feedbackTypeInfo = feedbackTypes[feedbackType];

function handleScreenshot(){
function handleScreenshot() {
captureScreen({
format: 'jpg',
quality: 0.8,

}).then(uri =>setScreenShot(uri)).catch(err => console.error(err));
}).then(uri => setScreenShot(uri)).catch(err => console.error(err));
}
function handleScreenshotRemove(){
function handleScreenshotRemove() {
setScreenShot(null);
}

async function handleSubmitFeedback(){
if(isSendingFeedback){
async function handleSubmitFeedback() {
if (isSendingFeedback) {
return;
}

setIsSendingFeedback(true);

const screenShotBase64 = screenshot && await FileSystem.readAsStringAsync(screenshot, {encoding:'base64'});
try{
await api.post('/feedbacks',{
const screenShotBase64 = screenshot && await FileSystem.readAsStringAsync(screenshot, { encoding: 'base64' });
try {
await api.post('/feedbacks', {
type: feedbackType,
screenshot:`data:image/png;base64,${screenShotBase64}`,
comment
screenshot: `data:image/png;base64, ${screenShotBase64}`,
comment,
});

onFeedbackSent();
onFeedbackSent();

}catch(erro){
console.log(erro);
} catch (erro) {
console.log("não consegui enviar o feedback");
setIsSendingFeedback(false);
}
}
Expand All @@ -68,7 +68,7 @@ export function Form({feedbackType, onFeedbackCanceled, onFeedbackSent}: PropsFo
<TouchableOpacity
onPress={onFeedbackCanceled}
>
<ArrowLeft
<ArrowLeft
size={20}
weight="bold"
color={theme.colors.primary}
Expand All @@ -85,30 +85,30 @@ export function Form({feedbackType, onFeedbackCanceled, onFeedbackSent}: PropsFo

</Text>

</View>
</View>

</View>
<TextInput
multiline
style={styles.inputText}
placeholder="Descreva com detalhes seu feedback..."
placeholderTextColor={theme.colors.text_secondary}
autoCorrect={false}
onChangeText= {setComment}
/>

<View style={styles.footer}>
<ScreenShotButton
</View>
<TextInput
multiline
style={styles.inputText}
placeholder="Descreva com detalhes seu feedback..."
placeholderTextColor={theme.colors.text_secondary}
autoCorrect={false}
onChangeText={setComment}
/>

<View style={styles.footer}>
<ScreenShotButton
onTakeShot={handleScreenshot}
onRemoveShot={handleScreenshotRemove}
screenshot={screenshot}
screenshot={screenshot}
/>
<SubmitButton
onPress={handleSubmitFeedback}
onPress={handleSubmitFeedback}
isLoading={isSendingFeedback}
/>

</View>
</View>
</View>
);
}
}
3 changes: 2 additions & 1 deletion mobile/src/components/Widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export type FeedbackType = keyof typeof feedbackTypes;
>
{
feedbackSent ?
<SuccessSubmitted onSendAnotherFeedback={handleRestartFeedback} /> :
<SuccessSubmitted onSendAnotherFeedback={handleRestartFeedback} />
:
<>
{

Expand Down
2 changes: 1 addition & 1 deletion mobile/src/libs/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from "axios";

export const api = axios.create({
baseURL: "http://192.168.100.81:3333"
baseURL: "http://192.168.100.80:3333"

});
Binary file modified server/prisma/dev.db
Binary file not shown.
5 changes: 4 additions & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import cors from 'cors'
//Inicialização do express pra ajudar no gerenciamento das rotas
const app = express();



app.use(cors({
origin: 'http://localhost:3001'
origin: 'http://:3000'
// origin: '192.168.100.80:3000'
}
));

Expand Down
Loading

0 comments on commit 2756c4b

Please sign in to comment.