diff --git a/App.js b/App.js
index ddeee2b..88e5b11 100644
--- a/App.js
+++ b/App.js
@@ -12,8 +12,10 @@ import {
import Home from "./components/Home/Home";
import HomeCategoria from "./components/HomeCategoria/HomeCategoria";
import AddCard from "./components/AddCard/AddCard";
+import EditCard from "./components/EditCard/EditCard";
import ConfirmDelete from "./components/ConfirmDelete/ConfirmDelete";
import AddCategoria from "./components/AddCategoria/AddCategoria";
+import EditCategoria from "./components/EditCategoria/EditCategoria";
import { SafeAreaView } from "react-native-safe-area-context";
import * as NavigationBar from "expo-navigation-bar";
import PlayCards from "./components/PlayCards/PlayCards";
@@ -41,6 +43,13 @@ export default function App() {
} />
+ }
+ />
+
+ } />
+
}
diff --git a/components/AddCard/AddCard.jsx b/components/AddCard/AddCard.jsx
index 35a7888..49e2d4d 100644
--- a/components/AddCard/AddCard.jsx
+++ b/components/AddCard/AddCard.jsx
@@ -9,6 +9,8 @@ import { vw, vh, vmin, vmax } from "react-native-expo-viewport-units";
import CardsDB from '../../services/sqlite/Card';
import DetalhesDB from '../../services/sqlite/Detalhes';
import CategoriaDB from '../../services/sqlite/Categoria';
+import TrashIcon from '../../assets/icons/trash-solid.svg'
+import EditIcon from '../../assets/icons/pen-solid.svg'
function withParams(Component) {
return props => ;
@@ -23,6 +25,7 @@ class AddCard extends React.Component {
respostaDetalhe: '',
detalheVisibility: false,
adicionarVisibility: true,
+ editMode: false,
idDetalhe: 0,
detalhes: [],
detalheSelected: -1,
@@ -44,7 +47,7 @@ class AddCard extends React.Component {
render (){
- const { titulo, resposta, tituloDetalhe, respostaDetalhe, detalheVisibility, adicionarVisibility,idDetalhe, detalhes, detalheSelected, categoria, categoriaId } = this.state
+ const { titulo, resposta, tituloDetalhe, respostaDetalhe, detalheVisibility, adicionarVisibility, editMode, idDetalhe, detalhes, detalheSelected, categoria, categoriaId } = this.state
const geraFlatList = () => {
console.log(detalhes.length)
@@ -52,7 +55,6 @@ class AddCard extends React.Component {
console.log(detalhes[idDetalhe-1])
return(
- Detalhes
this.setState({tituloDetalhe: novoTitulo})}
+ onChangeText={novoTitulo => {this.setState({tituloDetalhe: novoTitulo})}}
/>
escondeDetalhe()}>
x
- this.setState({respostaDetalhe: novaResposta})}
+ onChangeText={novaResposta => {this.setState({respostaDetalhe: novaResposta})}}
/>
+ {salvarDetalhe()}}>
+ Salvar
+
)
}
@@ -125,6 +130,14 @@ class AddCard extends React.Component {
this.setState({respostaDetalhe: ''})
}
+ const changeEditMode = () =>{
+ if (editMode){
+ this.setState({editMode: false, tituloDetalhe: '', respostaDetalhe: ''})
+ }else{
+ this.setState({editMode: true})
+ }
+ }
+
const salvarDetalhe = () => {
var novo_detalhe = {
id: idDetalhe,
@@ -140,11 +153,26 @@ class AddCard extends React.Component {
}
const deletarDetalhe = () => {
- var indexDetalhe = detalhes.findIndex(detalhe => detalhe.id == detalheSelected);
+ let indexDetalhe = detalhes.findIndex(detalhe => detalhe.id == detalheSelected);
this.setState({detalhes: detalhes.filter((_, i) => i !== indexDetalhe)})
this.setState({detalheSelected: -1})
}
+ const editarDetalhe = () => {
+ var novo_detalhe = {
+ id: detalheSelected,
+ titulo: tituloDetalhe,
+ resposta: respostaDetalhe
+ }
+ var indexDetalhe = detalhes.findIndex(detalhe => detalhe.id == detalheSelected);
+ var detalhesUpdated = detalhes
+ detalhesUpdated[indexDetalhe] = novo_detalhe
+
+ this.setState({detalhes: detalhesUpdated})
+ this.setState({tituloDetalhe: ''})
+ this.setState({respostaDetalhe: ''})
+ }
+
const showMenuDetalhe = () => {
if (detalheSelected != -1){
return (
@@ -170,12 +198,61 @@ class AddCard extends React.Component {
this.setState({detalheSelected: item.id})
}
}
- return (
- selecionaDetalhe()}>
- {item.titulo}
- {item.resposta}
-
- );
+
+ if(isSelected && !this.state.editMode){
+ return (
+
+ selecionaDetalhe()}>
+ {item.titulo}
+ {item.resposta}
+
+
+ {this.setState({editMode: true, tituloDetalhe: item.titulo, respostaDetalhe: item.resposta})}}/>
+
+ {deletarDetalhe()}}>
+
+
+
+
+ );
+ }else if(isSelected && this.state.editMode){
+ return(
+
+
+ this.setState({tituloDetalhe: novoTitulo})}
+ />
+ {this.setState({editMode: false, tituloDetalhe: '', respostaDetalhe: ''})}}>
+ x
+
+
+ this.setState({respostaDetalhe: novaResposta})}
+ />
+ {editarDetalhe();this.setState({editMode: false})}}>
+ Salvar
+
+
+ )
+ }else{
+ return (
+ selecionaDetalhe()}>
+ {item.titulo}
+ {item.resposta}
+
+ );
+ }
+
}
if (categoria.id != undefined) {
@@ -211,15 +288,14 @@ class AddCard extends React.Component {
numberOfLines={3}
onChangeText={novaResposta => this.setState({resposta:novaResposta})}
/>
-
- {geraFlatList()}
+ {(detalhes.length != 0) ? Detalhes : null}
+
{setaDetalhes()}
-
-
+ {geraFlatList()}
- {exibeSalvarDetalhe()}
+
+
{setaButtonAdicionar()}
- {showMenuDetalhe()}
diff --git a/components/AddCard/AddCard.styles.js b/components/AddCard/AddCard.styles.js
index 3f8e31f..0a26b82 100644
--- a/components/AddCard/AddCard.styles.js
+++ b/components/AddCard/AddCard.styles.js
@@ -73,6 +73,14 @@ export const styles = StyleSheet.create({
textAlign: "center",
},
+ btn_card_text_salvar: {
+ color: "#f2f2f2",
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 18,
+ paddingHorizontal: 10,
+ textAlign: "center",
+ },
+
btn_right: {
position: "absolute",
right: 20,
@@ -92,6 +100,33 @@ export const styles = StyleSheet.create({
borderRadius: 50,
},
+ trash_button: {
+ position: "absolute",
+ backgroundColor: "#c0392b",
+ padding: 10,
+ borderRadius: 50,
+ bottom: 10,
+ right: 10,
+ },
+
+ edit_button: {
+ position: "absolute",
+ backgroundColor: "#16a085",
+ padding: 10,
+ borderRadius: 50,
+ bottom: 10,
+ right: 60,
+ },
+
+ salvar_button: {
+ position: "absolute",
+ backgroundColor: "#16a085",
+ padding: 10,
+ borderRadius: 50,
+ bottom: 10,
+ right: 0,
+ },
+
header: {
width: "100%",
},
diff --git a/components/AddCategoria/AddCategoria.jsx b/components/AddCategoria/AddCategoria.jsx
index 4d4074b..749b13e 100644
--- a/components/AddCategoria/AddCategoria.jsx
+++ b/components/AddCategoria/AddCategoria.jsx
@@ -15,9 +15,14 @@ const AddCategoria = () => {
const [nome, setNome] = useState('')
const [colorSelected, setColorSelected] = useState("237A57-093028")
const colors = [
+ {hexa:"C6426E-512DA8"},
+ {hexa:"005C97-363795"},
+ {hexa:"ff8c00-C02425"},
{hexa:"237A57-093028"},
- {hexa:"C6426E-642B73"},
- {hexa:"569FF7-0052D4"},
+ {hexa:"267871-136a8a"},
+ {hexa:"8093a2-304352"},
+ {hexa:"BE5869-403A3E"},
+ {hexa:"e35d5b-e53935"},
]
const renderColor = ({item}) => {
diff --git a/components/Card/Card.jsx b/components/Card/Card.jsx
index f4905d3..22d9a02 100644
--- a/components/Card/Card.jsx
+++ b/components/Card/Card.jsx
@@ -9,6 +9,7 @@ import LampIconOff from '../../assets/icons/lamp-off.svg';
import StarIcon from '../../assets/icons/star.svg';
import TurnCardIcon from '../../assets/icons/repeat-solid.svg'
import TrashIcon from '../../assets/icons/trash-solid.svg'
+import EditIcon from '../../assets/icons/pen-solid.svg'
import CardsDB from '../../services/sqlite/Card'
import DetalhesDB from '../../services/sqlite/Detalhes'
import { Link } from 'react-router-native';
@@ -57,6 +58,9 @@ class Card extends React.Component {
>
{this.state.isTurned ? verso(this.state): frente(this.state)}
+
+
+
@@ -82,17 +86,24 @@ class Card extends React.Component {
}
function verso(card){
+ const TitleCard = () => {
+ return(
+
+ {card.titulo}
+ {card.resposta}
+ {(card.detalhes.length > 0) ? Tópicos : null}
+
+ )
+ }
return(
// Constrói a visualização do card
- {card.titulo}
- {card.resposta}
- {(card.detalhes.length > 0) ? Tópicos : null}
item.id}
- contentContainerStyle={styles.cardList}>
+ contentContainerStyle={styles.cardList}
+ ListHeaderComponent={TitleCard}>
);
diff --git a/components/Card/Verso.styles.js b/components/Card/Verso.styles.js
index 9b7c17b..3d3cd61 100644
--- a/components/Card/Verso.styles.js
+++ b/components/Card/Verso.styles.js
@@ -16,11 +16,21 @@ export const verso_styles = StyleSheet.create({
bottom: 23,
},
- trash_button: {
+ edit_button: {
position: "absolute",
left: 23,
//top: 0,
bottom: 23,
+ backgroundColor: "#16a085",
+ padding: 15,
+ borderRadius: 50,
+ },
+
+ trash_button: {
+ position: "absolute",
+ left: 90,
+ //top: 0,
+ bottom: 23,
backgroundColor: "#c0392b",
padding: 15,
borderRadius: 50,
diff --git a/components/CardList/CardList.jsx b/components/CardList/CardList.jsx
index a716b81..97bb1a1 100644
--- a/components/CardList/CardList.jsx
+++ b/components/CardList/CardList.jsx
@@ -13,23 +13,23 @@ class CardList extends React.Component {
cards: null,
categoriaId: this.props.categoriaId,
cor: this.props.cor,
+ search: this.props.search
}
componentDidMount() {
- this.getCards(this.state.categoriaId);
+ this.getCards(this.props.categoriaId, this.props.search);
}
componentDidUpdate(prevProps) {
- if(this.props.categoriaId != prevProps.categoriaId){
- this.getCards(this.state.categoriaId);
+ if(this.props.categoriaId != prevProps.categoriaId || this.props.search != prevProps.search){
+ this.getCards(this.state.categoriaId, this.props.search);
}
}
- getCards = (categoriaId) => {
- console.log(categoriaId)
- CardsDB.allCardsCategory(categoriaId).then(res => {
+ getCards = (categoriaId, search) => {
+ CardsDB.allCardsCategory(categoriaId, search).then(res => {
this.setState({
cards: res,
});
diff --git a/components/Categoria/Categoria.jsx b/components/Categoria/Categoria.jsx
index ba94da6..5889b9a 100644
--- a/components/Categoria/Categoria.jsx
+++ b/components/Categoria/Categoria.jsx
@@ -16,7 +16,7 @@ const Categoria = (props) => {
if (editMode){
return(
-
+
diff --git a/components/CategoriasList/CategoriasList.jsx b/components/CategoriasList/CategoriasList.jsx
index abf6cd2..8faf481 100644
--- a/components/CategoriasList/CategoriasList.jsx
+++ b/components/CategoriasList/CategoriasList.jsx
@@ -10,21 +10,21 @@ import { Link } from 'react-router-native'
class CategoriasList extends React.Component {
state = {
- categorias: [],
+ categorias: []
}
componentDidMount() {
this.getCategorias();
}
- componentDidUpdate(prevState){
- if (this.state.categorias !== prevState.categorias) {
- this.getCategorias();
+ componentDidUpdate(prevState, prevProps){
+ if (this.state.categorias !== prevState.categorias || this.props.search !== prevProps.search) {
+ this.getCategorias(this.props.search);
}
}
- getCategorias = () => {
- CategoriaDB.allCategorias().then(res => {
+ getCategorias = (search) => {
+ CategoriaDB.allCategorias(search).then(res => {
this.setState({
categorias: res,
});
diff --git a/components/Detalhe/Detalhe.jsx b/components/Detalhe/Detalhe.jsx
deleted file mode 100644
index cc17d6f..0000000
--- a/components/Detalhe/Detalhe.jsx
+++ /dev/null
@@ -1,21 +0,0 @@
-import React from 'react';
-import { View, Text } from 'react-native';
-import PropTypes from 'prop-types';
-import * as styles from './Detalhe.styles';
-//import { DetalheWrapper } from './Detalhe.styles';
-
-const Detalhe = (props) => (
-
- Test content
-
-);
-
-Detalhe.propTypes = {
- // bla: PropTypes.string,
-};
-
-Detalhe.defaultProps = {
- // bla: 'test',
-};
-
-export default Detalhe;
diff --git a/components/Detalhe/Detalhe.styles.js b/components/Detalhe/Detalhe.styles.js
deleted file mode 100644
index 4f6955d..0000000
--- a/components/Detalhe/Detalhe.styles.js
+++ /dev/null
@@ -1,5 +0,0 @@
-import styled from 'styled-components/native';
-
-export const DetalheWrapper = styled.View`
- flex: 1
-`;
diff --git a/components/Detalhe/index.js b/components/Detalhe/index.js
deleted file mode 100644
index c5c83e0..0000000
--- a/components/Detalhe/index.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import Detalhe from './Detalhe';
-
-export default Detalhe;
diff --git a/components/EditCard/EditCard.jsx b/components/EditCard/EditCard.jsx
new file mode 100644
index 0000000..c14a687
--- /dev/null
+++ b/components/EditCard/EditCard.jsx
@@ -0,0 +1,402 @@
+import React, { useState, useEffect } from 'react';
+import { View, Text, ScrollView, FlatList, TextInput, Button, TouchableOpacity } from 'react-native';
+import { styles } from './EditCard.styles';
+import { useParams } from 'react-router-native';
+import { LinearGradient } from 'expo-linear-gradient';
+import CategoriasIcon from '../../assets/icons/categorias.svg'
+import { Link } from 'react-router-native';
+import { vw, vh, vmin, vmax } from "react-native-expo-viewport-units";
+import CardsDB from '../../services/sqlite/Card';
+import DetalhesDB from '../../services/sqlite/Detalhes';
+import CategoriaDB from '../../services/sqlite/Categoria';
+import TrashIcon from '../../assets/icons/trash-solid.svg'
+import EditIcon from '../../assets/icons/pen-solid.svg'
+import Card from '../Card/Card';
+
+function withParams(Component) {
+ return props => ;
+ }
+
+class EditCard extends React.Component {
+
+ state = {
+ titulo: '',
+ resposta: '',
+ tituloDetalhe: '',
+ respostaDetalhe: '',
+ detalheVisibility: false,
+ adicionarVisibility: true,
+ editMode: false,
+ idDetalhe: 0,
+ detalhes: [],
+ detalhesDeleted: [],
+ detalheSelected: -1,
+ cardId: this.props.params.id,
+ categoriaId: this.props.params.categoriaId,
+ cor: this.props.params.cor,
+ card: undefined,
+ detalhesSetted: false,
+ categoriaNome: '',
+ idDetalhesBD: []
+ }
+
+ componentDidMount() {
+ this.getCategoria(this.state.categoriaId);
+ }
+
+
+
+ getCategoria = (idCategoria) => {
+ CategoriaDB.findCategoria(idCategoria).then(res => {
+ this.setState({
+ categoriaNome: res.nome,
+ });
+ this.getCard(this.state.cardId)
+ }).catch(err=>err);
+ }
+
+ getCard = (cardId) => {
+ CardsDB.findCard(cardId).then(res => {
+ this.setState({
+ card: res,
+ titulo: res.titulo,
+ resposta: res.resposta
+ });
+ this.getDetalhes(this.state.cardId)
+ }).catch(err=>err);
+ }
+
+ getDetalhes = (cardId) => {
+ let newIdDetalhesBD = []
+ DetalhesDB.allDetalhesCard(cardId).then(res => {
+ res.forEach((detalhe) => {
+ newIdDetalhesBD = newIdDetalhesBD.concat(detalhe.id)
+ })
+
+ this.setState({
+ detalhes: res,
+ detalhesSetted: true,
+ idDetalhesBD: newIdDetalhesBD,
+ idDetalhe: Math.max.apply(null, newIdDetalhesBD) + 1
+ });
+
+ }).catch(err=>err);
+ }
+
+ render (){
+
+ const { titulo, resposta, tituloDetalhe, respostaDetalhe, detalheVisibility, adicionarVisibility, editMode, idDetalhe, detalhes, detalheSelected, cardId, categoriaId, cor, card, detalhesSetted, categoriaNome, idDetalhesBD, idDetalhesUpdate, idDetalhesInsert, idDetalhesDelete} = this.state
+
+ const geraFlatList = () => {
+ console.log(detalhes.length)
+ if(detalhes.length != 0) {
+ console.log(detalhes[idDetalhe-1])
+ return(
+
+ item.id}
+ contentContainerStyle={styles.cardList}>
+
+
+ );
+ }
+ }
+
+ const setaDetalhes = () => {
+ if (detalheVisibility){
+ return(
+
+
+ {this.setState({tituloDetalhe: novoTitulo})}}
+ />
+ escondeDetalhe()}>
+ x
+
+
+ {this.setState({respostaDetalhe: novaResposta})}}
+ />
+ {salvarDetalhe()}}>
+ Salvar
+
+
+ )
+ }
+ }
+
+ const setaButtonAdicionar = () => {
+ if(adicionarVisibility && detalheSelected == -1 && !detalheVisibility){
+ return(
+ exibeDetalhe()}>
+ Adicionar Detalhe
+
+ )
+ }
+ }
+
+ const exibeDetalhe = () =>{
+ this.setState({adicionarVisibility: false})
+ this.setState({detalheVisibility: true})
+ }
+
+ const escondeDetalhe = () =>{
+ this.setState({adicionarVisibility: true})
+ this.setState({detalheVisibility: false})
+ this.setState({tituloDetalhe: ''})
+ this.setState({respostaDetalhe: ''})
+ }
+
+ const salvarDetalhe = () => {
+ var novo_detalhe = {
+ id: idDetalhe,
+ titulo: tituloDetalhe,
+ resposta: respostaDetalhe
+ }
+ this.setState({detalhes: detalhes.concat([novo_detalhe])})
+ this.setState({idDetalhe: novo_detalhe.id + 1})
+ this.setState({tituloDetalhe: ''})
+ this.setState({respostaDetalhe: ''})
+ this.setState({adicionarVisibility: true})
+ this.setState({detalheVisibility: false})
+ }
+
+ const deletarDetalhe = () => {
+ let indexDetalhe = detalhes.findIndex(detalhe => detalhe.id == detalheSelected);
+ this.setState({detalhes: detalhes.filter((_, i) => i !== indexDetalhe)})
+ this.setState({detalheSelected: -1})
+ }
+
+ const editarDetalhe = () => {
+ var novo_detalhe = {
+ id: detalheSelected,
+ titulo: tituloDetalhe,
+ resposta: respostaDetalhe
+ }
+ var indexDetalhe = detalhes.findIndex(detalhe => detalhe.id == detalheSelected);
+ var detalhesUpdated = detalhes
+ detalhesUpdated[indexDetalhe] = novo_detalhe
+
+ this.setState({detalhes: detalhesUpdated})
+ this.setState({tituloDetalhe: ''})
+ this.setState({respostaDetalhe: ''})
+ }
+
+ const showMenuDetalhe = () => {
+ if (detalheSelected != -1){
+ return (
+ deletarDetalhe()}>
+ Deletar
+
+ );
+ }
+ }
+
+ const renderDetalhe = ({item}) => {
+ id = item.id
+ var isSelected = false
+
+ if (detalheSelected == item.id){
+ isSelected = true
+ }
+
+ const selecionaDetalhe = () => {
+ if (detalheSelected == item.id){
+ this.setState({detalheSelected: -1})
+ }else{
+ this.setState({detalheSelected: item.id})
+ }
+ }
+
+ if(isSelected && !this.state.editMode){
+ return (
+
+ selecionaDetalhe()}>
+ {item.titulo}
+ {item.resposta}
+
+
+ {this.setState({editMode: true, tituloDetalhe: item.titulo, respostaDetalhe: item.resposta})}}/>
+
+ {deletarDetalhe()}}>
+
+
+
+
+ );
+ }else if(isSelected && this.state.editMode){
+ return(
+
+
+ this.setState({tituloDetalhe: novoTitulo})}
+ />
+ {this.setState({editMode: false, tituloDetalhe: '', respostaDetalhe: ''})}}>
+ x
+
+
+ this.setState({respostaDetalhe: novaResposta})}
+ />
+ {editarDetalhe();this.setState({editMode: false})}}>
+ Salvar
+
+
+ )
+ }else{
+ return (
+ selecionaDetalhe()}>
+ {item.titulo}
+ {item.resposta}
+
+ );
+ }
+
+ }
+
+ if (card != undefined && detalhesSetted == true) {
+ return (
+ // Constrói a visualização do card
+
+
+ Editar Card
+
+
+ {categoriaNome}
+
+
+
+
+
+
+ this.setState({titulo:novoTitulo})}
+ />
+ this.setState({resposta:novaResposta})}
+ />
+ {(detalhes.length != 0) ? Detalhes : null}
+
+ {setaDetalhes()}
+ {geraFlatList()}
+
+
+
+ {setaButtonAdicionar()}
+
+
+
+ updateCard(cardId, titulo, resposta, detalhes)}>
+ Salvar
+
+
+ Cancelar
+
+
+
+ )
+ }else{
+ return(
+
+ )
+ }
+
+ }
+
+}
+
+/** Transforma as cores em HEXADECIMAL para construir o gradiente */
+function getColors(colorStr){
+ var initialColor = colorStr.split("-")[0]
+ var finalColor = colorStr.split("-")[1]
+ return ["#" + initialColor, "#" + finalColor]
+
+}
+
+function updateCard(cardId, titulo, resposta, detalhes){
+
+ console.log(cardId)
+ var novoCard = {
+ id: cardId,
+ titulo: titulo,
+ resposta: resposta
+ }
+
+ //create
+ CardsDB.updateCard(novoCard)
+ .then( rows => {
+ deleteDetalhes(detalhes, cardId)
+ })
+ .catch( err => console.log(err))
+
+
+}
+
+function deleteDetalhes(detalhes, cardId){
+
+ //delete
+ DetalhesDB.removeDetalhe(cardId)
+ .then( rows=> {
+ insertDetalhes(detalhes, cardId)
+ })
+ .catch( err => console.log(err) )
+
+
+}
+
+function insertDetalhes(detalhes, cardId){
+ // Adiciona Detalhes
+ console.log(cardId)
+ for(let detalhe of detalhes){
+
+ var novoDetalhe = {
+ cardId: cardId,
+ titulo: detalhe.titulo,
+ resposta: detalhe.resposta
+ }
+
+ console.log(novoDetalhe)
+
+ //create
+ DetalhesDB.createDetalhe(novoDetalhe)
+ .then( id => console.log('Detalhe created with id: '+ id) )
+ .catch( err => console.log(err) )
+ }
+}
+
+
+export default withParams(EditCard)
\ No newline at end of file
diff --git a/components/EditCard/EditCard.styles.js b/components/EditCard/EditCard.styles.js
new file mode 100644
index 0000000..0a26b82
--- /dev/null
+++ b/components/EditCard/EditCard.styles.js
@@ -0,0 +1,212 @@
+import { StyleSheet } from "react-native";
+import { vw, vh, vmin, vmax } from "react-native-expo-viewport-units";
+
+export const styles = StyleSheet.create({
+ container: {
+ flex: 1,
+ backgroundColor: "#1a1a1a",
+ width: "100%",
+ height: "100%",
+ alignItems: "center",
+ },
+
+ header_detalhe: {
+ marginTop: 20,
+ display: "flex",
+ flexDirection: "row",
+ alignItems: "center",
+ justifyContent: "space-between",
+ },
+
+ close_detalhe: {
+ backgroundColor: "#c0392b",
+ padding: 4,
+ paddingTop: 0,
+ width: 32,
+ borderRadius: 50,
+ },
+
+ cardTituloDetalhe: {
+ width: vw(70),
+ color: "#f2f2f2",
+ textAlign: "left",
+ fontFamily: "Epilogue_700Bold",
+ fontSize: 17,
+ //borderBottomWidth: 2,
+ //borderBottomColor: "#f2f2f2",
+ },
+
+ btn_card: {
+ position: "absolute",
+ bottom: 20,
+ backgroundColor: "#1a1a1a",
+ borderRadius: 50,
+ textAlign: "center",
+ padding: 12,
+ },
+
+ menu_footer: {
+ height: vh(10),
+ width: "100%",
+ },
+
+ btn_text: {
+ color: "#f2f2f2",
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 20,
+ width: vw(36),
+ textAlign: "center",
+ },
+
+ btn_card_text: {
+ color: "#f2f2f2",
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 20,
+ textAlign: "center",
+ width: vw(70),
+ },
+
+ btn_card_text_x: {
+ color: "#f2f2f2",
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 20,
+ textAlign: "center",
+ },
+
+ btn_card_text_salvar: {
+ color: "#f2f2f2",
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 18,
+ paddingHorizontal: 10,
+ textAlign: "center",
+ },
+
+ btn_right: {
+ position: "absolute",
+ right: 20,
+ bottom: 20,
+ },
+
+ btn_left: {
+ position: "absolute",
+ left: 20,
+ bottom: 20,
+ backgroundColor: "#c0392b",
+ },
+
+ btn_layout: {
+ backgroundColor: "#16a085",
+ padding: 10,
+ borderRadius: 50,
+ },
+
+ trash_button: {
+ position: "absolute",
+ backgroundColor: "#c0392b",
+ padding: 10,
+ borderRadius: 50,
+ bottom: 10,
+ right: 10,
+ },
+
+ edit_button: {
+ position: "absolute",
+ backgroundColor: "#16a085",
+ padding: 10,
+ borderRadius: 50,
+ bottom: 10,
+ right: 60,
+ },
+
+ salvar_button: {
+ position: "absolute",
+ backgroundColor: "#16a085",
+ padding: 10,
+ borderRadius: 50,
+ bottom: 10,
+ right: 0,
+ },
+
+ header: {
+ width: "100%",
+ },
+
+ titulo: {
+ color: "#f2f2f2",
+ marginLeft: 20,
+ marginTop: 20,
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 40,
+ },
+
+ categoria: {
+ display: "flex",
+ flexDirection: "row",
+ alignItems: "center",
+ marginLeft: 20,
+ marginTop: 10,
+ },
+
+ categoryText: {
+ color: "#f2f2f2",
+ marginLeft: 10,
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 23,
+ },
+
+ categoryItem: {
+ marginTop: 10,
+ borderRadius: 10,
+ width: "100%",
+ },
+
+ cardBody: {
+ flex: 1,
+ width: vw(90),
+ height: vh(70),
+ borderRadius: 40,
+ padding: 20,
+ marginLeft: vw(3),
+ marginRight: vw(3),
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ },
+
+ scrollView: {
+ marginTop: "5%",
+ marginBottom: 70,
+ },
+
+ cardTitulo: {
+ marginTop: 10,
+ width: vw(70),
+ color: "#f2f2f2",
+ textAlign: "left",
+ fontFamily: "Epilogue_700Bold",
+ fontSize: 25,
+ //backgroundColor: "#1a1a1a80",
+ borderRadius: 8,
+ //borderWidth: 1,
+ //borderColor: "#f2f2f2",
+ },
+
+ cardResposta: {
+ marginTop: 10,
+ width: vw(70),
+ color: "#f2f2f2",
+ textAlign: "left",
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 17,
+ backgroundColor: "#1a1a1a60",
+ borderRadius: 8,
+ //borderWidth: 1,
+ // borderColor: "#f2f2f2",
+ padding: 8,
+ },
+
+ elevation: {
+ elevation: 15,
+ shadowColor: "#121212",
+ },
+});
diff --git a/components/EditCategoria/EditCategoria.jsx b/components/EditCategoria/EditCategoria.jsx
new file mode 100644
index 0000000..8416a1b
--- /dev/null
+++ b/components/EditCategoria/EditCategoria.jsx
@@ -0,0 +1,128 @@
+import React, { useState, useEffect } from 'react';
+import { View, Text, ScrollView, FlatList, TextInput, Button, TouchableOpacity } from 'react-native';
+import { styles } from './EditCategoria.styles';
+import { useParams } from 'react-router-native';
+import { LinearGradient } from 'expo-linear-gradient';
+import { Link } from 'react-router-native';
+import CategoriasDB from '../../services/sqlite/Categoria'
+
+function withParams(Component) {
+ return props => ;
+}
+
+const EditCategoria = (props) => {
+
+ // Cria os states para atualizar enquanto o usuário modifica
+ const [nome, setNome] = useState('')
+ const [colorSelected, setColorSelected] = useState("")
+ const colors = [
+ {hexa:"C6426E-512DA8"},
+ {hexa:"005C97-363795"},
+ {hexa:"ff8c00-C02425"},
+ {hexa:"237A57-093028"},
+ {hexa:"267871-136a8a"},
+ {hexa:"8093a2-304352"},
+ {hexa:"BE5869-403A3E"},
+ {hexa:"e35d5b-e53935"},
+ ]
+
+ const id = props.params.id
+
+ useEffect(() => {
+ console.log(id)
+ CategoriasDB.findCategoria(id).then(res => {
+ console.log(res)
+ setNome(res.nome)
+ setColorSelected(res.cor)
+ });
+ },[])
+
+ const renderColor = ({item}) => {
+ var isSelected = false
+
+ if (colorSelected == item.hexa){
+ isSelected = true
+ }
+
+ return (
+ setColorSelected(item.hexa)}>
+
+
+ );
+ }
+
+ return (
+
+ // Constrói a visualização do card
+
+
+ Editar Deck
+ setNome(novoNome)}
+ />
+
+
+ Cor
+ item.hexa}
+ contentContainerStyle={styles.colorsList}>
+
+
+
+ Card
+
+
+
+
+
+ updateCategoria(nome, colorSelected, id)}>
+ Salvar
+
+
+ Cancelar
+
+
+
+ )
+}
+
+/** Transforma as cores em HEXADECIMAL para construir o gradiente */
+function getColors(colorStr){
+ var initialColor = colorStr.split("-")[0]
+ var finalColor = colorStr.split("-")[1]
+ return ["#" + initialColor, "#" + finalColor]
+
+}
+
+function updateCategoria(nome, cor, id){
+ // Adiciona Card
+ var novaCategoria = {
+ id: id,
+ cor: cor,
+ nome: nome
+ }
+
+ //create
+ CategoriasDB.updateCategoria(novaCategoria)
+ .then( id => {
+ console.log('Categoria atualizada: '+ id)
+ })
+ .catch( err => console.log(err) )
+
+}
+
+export default withParams(EditCategoria)
\ No newline at end of file
diff --git a/components/EditCategoria/EditCategoria.styles.js b/components/EditCategoria/EditCategoria.styles.js
new file mode 100644
index 0000000..e3dd86d
--- /dev/null
+++ b/components/EditCategoria/EditCategoria.styles.js
@@ -0,0 +1,228 @@
+import { StyleSheet } from "react-native";
+import { vw, vh, vmin, vmax } from "react-native-expo-viewport-units";
+
+export const styles = StyleSheet.create({
+ background: {
+ flex: 1,
+ backgroundColor: "#1a1a1a",
+ width: "100%",
+ height: "100%",
+ },
+
+ subtitulo: {
+ color: "#888",
+ textAlign: "left",
+ fontFamily: "Epilogue_500Medium",
+ marginBottom: 0,
+ fontSize: 20,
+ marginLeft: 20,
+ marginRight: 20,
+ },
+
+ color_card: {
+ display: "flex",
+ flexDirection: "row",
+ justifyContent: "space-between",
+ },
+
+ cardText: {
+ marginTop: vh(8),
+ color: "#f2f2f2",
+ textAlign: "center",
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 30,
+ },
+
+ card_example: {
+ width: vw(59),
+ height: vh(50),
+ marginRight: 20,
+ borderRadius: 30,
+ },
+
+ colorItem: {
+ marginTop: 10,
+ borderRadius: 10,
+ width: 60,
+ height: 60,
+ },
+
+ color: {
+ flex: 1,
+ borderRadius: 8,
+ padding: 20,
+ margin: 0,
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ },
+
+ colorsList: {
+ alignItems: "center",
+ },
+
+ colorText: {
+ color: "#f2f2f2",
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 20,
+ textAlign: "center",
+ },
+
+ color_container: {
+ borderRadius: 8,
+ marginLeft: 20,
+ padding: 15,
+ width: vw(25),
+ height: vh(50),
+ backgroundColor: "#2a2a2a",
+ },
+
+ header_detalhe: {
+ marginTop: 20,
+ display: "flex",
+ flexDirection: "row",
+ alignItems: "center",
+ justifyContent: "space-between",
+ },
+
+ close_detalhe: {
+ backgroundColor: "#c0392b",
+ padding: 4,
+ paddingTop: 0,
+ width: 32,
+ borderRadius: 50,
+ },
+
+ cardTituloDetalhe: {
+ width: vw(70),
+ color: "#f2f2f2",
+ textAlign: "left",
+ fontFamily: "Epilogue_700Bold",
+ fontSize: 17,
+ //borderBottomWidth: 2,
+ //borderBottomColor: "#f2f2f2",
+ },
+
+ btn_card: {
+ position: "absolute",
+ bottom: 20,
+ backgroundColor: "#1a1a1a",
+ borderRadius: 50,
+ textAlign: "center",
+ padding: 12,
+ },
+
+ menu_footer: {
+ height: vh(10),
+ width: "100%",
+ position: "absolute",
+ backgroundColor: "#1a1a1a",
+ bottom: 0,
+ },
+
+ btn_text: {
+ color: "#f2f2f2",
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 20,
+ width: vw(36),
+ textAlign: "center",
+ },
+
+ btn_card_text: {
+ color: "#f2f2f2",
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 20,
+ textAlign: "center",
+ width: vw(70),
+ },
+
+ btn_card_text_x: {
+ color: "#f2f2f2",
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 20,
+ textAlign: "center",
+ },
+
+ btn_right: {
+ position: "absolute",
+ right: 20,
+ bottom: 20,
+ },
+
+ btn_left: {
+ position: "absolute",
+ left: 20,
+ bottom: 20,
+ backgroundColor: "#c0392b",
+ },
+
+ btn_layout: {
+ backgroundColor: "#16a085",
+ padding: 10,
+ borderRadius: 50,
+ },
+
+ header: {
+ width: "100%",
+ },
+
+ titulo: {
+ color: "#f2f2f2",
+ marginLeft: 20,
+ marginTop: 20,
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 40,
+ },
+
+ categoria: {
+ display: "flex",
+ flexDirection: "row",
+ alignItems: "center",
+ marginLeft: 20,
+ marginTop: 10,
+ },
+
+ categoryText: {
+ color: "#f2f2f2",
+ marginLeft: 10,
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 23,
+ },
+
+ scrollView: {
+ marginTop: "5%",
+ marginBottom: 70,
+ },
+
+ cardNome: {
+ margin: 20,
+ color: "#f2f2f2",
+ textAlign: "left",
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 25,
+ backgroundColor: "#2a2a2a",
+ borderRadius: 8,
+ padding: 10,
+ //borderWidth: 1,
+ //borderColor: "#f2f2f2",
+ },
+
+ cardResposta: {
+ marginTop: 10,
+ width: vw(70),
+ color: "#f2f2f2",
+ textAlign: "left",
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 17,
+ backgroundColor: "#1a1a1a60",
+ borderRadius: 8,
+ //borderWidth: 1,
+ // borderColor: "#f2f2f2",
+ padding: 8,
+ },
+
+ elevation: {
+ elevation: 15,
+ shadowColor: "#121212",
+ },
+});
diff --git a/components/Home/Home.jsx b/components/Home/Home.jsx
index 1266d15..368b375 100644
--- a/components/Home/Home.jsx
+++ b/components/Home/Home.jsx
@@ -1,5 +1,5 @@
-import React from 'react';
-import { View, Text } from 'react-native';
+import React, { useState, useEffect } from 'react';
+import { View, Text, TextInput } from 'react-native';
import { styles } from './Home.styles';
import BtnAddCategoria from '../BtnAdd/BtnAddCategoria';
import BtnCategorias from '../BtnCategorias/BtnCategorias';
@@ -9,12 +9,20 @@ import SearchIcon from '../../assets/icons/search.svg'
import * as categorias from '../test/categorias.json';
const Home = (props) => {
+ const [search, setSearch] = useState('');
+
return (
+ setSearch(text)}
+ />
+
+
Decks
-
-
+
diff --git a/components/Home/Home.styles.js b/components/Home/Home.styles.js
index 02b7f66..1f2fedc 100644
--- a/components/Home/Home.styles.js
+++ b/components/Home/Home.styles.js
@@ -1,30 +1,44 @@
-import { StyleSheet } from 'react-native';
-import { vw, vh, vmin, vmax } from 'react-native-expo-viewport-units';
+import { StyleSheet } from "react-native";
+import { vw, vh, vmin, vmax } from "react-native-expo-viewport-units";
export const styles = StyleSheet.create({
- home: {
- flex: 1,
- backgroundColor: '#1a1a1a',
- width: '100%',
- height: '100%',
- },
+ home: {
+ flex: 1,
+ backgroundColor: "#1a1a1a",
+ width: "100%",
+ height: "100%",
+ },
- categoryText: {
- color: '#f2f2f2',
- marginLeft: 20,
- marginTop: 20,
- fontFamily: 'Epilogue_500Medium',
- fontSize: 40,
- },
+ categoryText: {
+ color: "#f2f2f2",
+ marginLeft: 20,
+ marginTop: 80,
+ fontFamily: "Epilogue_500Medium",
+ fontSize: 40,
+ },
- searchIcon: {
- position: 'absolute',
- top: 30,
- right: 30,
- },
+ searchIcon: {
+ position: "absolute",
+ top: 35,
+ right: 35,
+ },
- cardList: {
- height: '100%',
- marginTop: '5%',
- }
- });
+ searchInput: {
+ width: vw(90),
+ color: "#f2f2f2",
+ textAlign: "left",
+ fontFamily: "Epilogue_700Bold",
+ fontSize: 17,
+ borderBottomWidth: 2,
+ borderBottomColor: "#454545",
+ position: "absolute",
+ top: 20,
+ left: 20,
+ padding: 12,
+ },
+
+ cardList: {
+ height: "100%",
+ marginTop: "5%",
+ },
+});
diff --git a/components/HomeCategoria/HomeCategoria.jsx b/components/HomeCategoria/HomeCategoria.jsx
index d82977b..49fba88 100644
--- a/components/HomeCategoria/HomeCategoria.jsx
+++ b/components/HomeCategoria/HomeCategoria.jsx
@@ -1,5 +1,5 @@
import React from 'react';
-import { View, Text, ScrollView } from 'react-native';
+import { View, Text, ScrollView, TextInput} from 'react-native';
import { styles } from './HomeCategoria.styles';
import BtnAddCard from '../BtnAdd/BtnAddCard';
import BtnPlay from '../BtnPlay/BtnPlay';
@@ -19,7 +19,8 @@ class HomeCategoria extends React.Component {
state = {
categoria: {},
- id: this.props.params.id
+ id: this.props.params.id,
+ search: ''
}
componentDidMount() {
@@ -39,9 +40,15 @@ class HomeCategoria extends React.Component {
return (
{this.state.categoria.nome}
-
+ {this.setState({search: text,})}}
+ />
+
+
-
+
diff --git a/components/HomeCategoria/HomeCategoria.styles.js b/components/HomeCategoria/HomeCategoria.styles.js
index a8b211a..1736386 100644
--- a/components/HomeCategoria/HomeCategoria.styles.js
+++ b/components/HomeCategoria/HomeCategoria.styles.js
@@ -12,7 +12,7 @@ export const styles = StyleSheet.create({
categoryText: {
color: "#f2f2f2",
marginLeft: 20,
- marginTop: 20,
+ marginTop: 85,
fontFamily: "Epilogue_500Medium",
fontSize: 30,
},
@@ -21,17 +21,31 @@ export const styles = StyleSheet.create({
position: "absolute",
top: 0,
left: 0,
- right: 90,
+ right: 0,
},
searchIcon: {
position: "absolute",
- top: 30,
- right: 30,
+ top: 35,
+ right: 35,
+ },
+
+ searchInput: {
+ width: vw(90),
+ color: "#f2f2f2",
+ textAlign: "left",
+ fontFamily: "Epilogue_700Bold",
+ fontSize: 17,
+ borderBottomWidth: 2,
+ borderBottomColor: "#454545",
+ position: "absolute",
+ top: 20,
+ left: 20,
+ padding: 12,
},
cardList: {
height: "100%",
- marginTop: vh(13),
+ marginTop: vh(17),
},
});
diff --git a/components/PlayCards/CardPlay.jsx b/components/PlayCards/CardPlay.jsx
index d204d8e..f82ad0c 100644
--- a/components/PlayCards/CardPlay.jsx
+++ b/components/PlayCards/CardPlay.jsx
@@ -6,6 +6,7 @@ import { verso_styles } from './Verso.styles';
import { LinearGradient } from 'expo-linear-gradient';
import TurnCardIcon from '../../assets/icons/arrows-rotate-solid.svg'
import DetalhesDB from '../../services/sqlite/Detalhes'
+import { vh } from 'react-native-expo-viewport-units';
class CardPlay extends React.Component {
@@ -22,12 +23,14 @@ class CardPlay extends React.Component {
componentDidMount() {
console.log("Montou")
this.getDetalhes();
+ this.setState({isTurned: false})
}
getDetalhes = () => {
DetalhesDB.allDetalhesCard(this.state.id).then(res => {
this.setState({
detalhes: res,
+ isTurned: false
});
});
}
@@ -39,12 +42,13 @@ class CardPlay extends React.Component {
{item.titulo}
{item.resposta}
+ {(card.detalhes.length > 0) ? Tópicos : null}
);
}
return (
-
+
-
-
+
+
);
function frente(card){
return(
-
{card.titulo}
-
)
}
function verso(card){
+
+ const TitleCard = () => {
+ return(
+
+ {card.titulo}
+ {card.resposta}
+
+ )
+ }
return(
// Constrói a visualização do card
-
- {card.titulo}
- {card.resposta}
- {(card.detalhes.length > 0) ? Tópicos : null}
- item.id}
- contentContainerStyle={styles.cardList}>
-
-
+ item.id}
+ contentContainerStyle={styles.cardList}
+ >
+
);
}
}
diff --git a/components/PlayCards/PlayCards.jsx b/components/PlayCards/PlayCards.jsx
index 28200a5..f1e8c03 100644
--- a/components/PlayCards/PlayCards.jsx
+++ b/components/PlayCards/PlayCards.jsx
@@ -15,6 +15,7 @@ import BackIcon from '../../assets/icons/chevron-left-solid.svg'
import TurnCardIcon from '../../assets/icons/repeat-solid.svg'
import ResetIcon from '../../assets/icons/rotate-right-solid.svg'
import DetalhesDB from '../../services/sqlite/Detalhes'
+import { vw } from 'react-native-expo-viewport-units';
function withParams(Component) {
return props => ;
@@ -39,14 +40,17 @@ class PlayCards extends React.Component {
if(this.state.clicked){
console.log("click")
this.setState({clicked: false})
+ this.setState({isTurned: false})
this.createPlay();
}
}
createPlay = () => {
+ console.log(this.state.categoriaId)
PlayDB.createPlay(this.state.categoriaId).then(idPlay => {
PlayDB.selectNextCard(this.state.categoriaId).then(nextCard => {
CardDB.findCard(nextCard.cardId).then(playCard => {
+ console.log(playCard)
this.setState({
card: playCard
});
@@ -54,10 +58,12 @@ class PlayCards extends React.Component {
this.setState({
categoria: categoriaObj
});
+ console.log(categoriaObj);
DetalhesDB.allDetalhesCard(nextCard.cardId).then(detalhes => {
this.setState({
detalhes: detalhes,
});
+ console.log(detalhes)
});
})
})
@@ -132,17 +138,26 @@ class PlayCards extends React.Component {
}
function verso(card, detalhes){
+
+ const TitleCard = () => {
+ return(
+
+ {card.titulo}
+ {card.resposta}
+ {(detalhes.length > 0) ? Tópicos : null}
+
+ )
+ }
return(
// Constrói a visualização do card
- {card.titulo}
- {card.resposta}
- {(detalhes.length > 0) ? Tópicos : null}
item.id}
- contentContainerStyle={styles.cardList}>
+ contentContainerStyle={styles.cardList}
+ ListHeaderComponent={TitleCard}
+ >
);
diff --git a/components/PlayCards/PlayCards.styles.js b/components/PlayCards/PlayCards.styles.js
index e688434..febad87 100644
--- a/components/PlayCards/PlayCards.styles.js
+++ b/components/PlayCards/PlayCards.styles.js
@@ -39,6 +39,7 @@ export const styles = StyleSheet.create({
display: "flex",
flexDirection: "column",
alignItems: "center",
+ flexGrow: 1,
},
scrollView: {
diff --git a/components/PlayCards/Verso.styles.js b/components/PlayCards/Verso.styles.js
index 9b7c17b..7269642 100644
--- a/components/PlayCards/Verso.styles.js
+++ b/components/PlayCards/Verso.styles.js
@@ -157,6 +157,7 @@ export const verso_styles = StyleSheet.create({
scrollView: {
marginTop: "5%",
marginBottom: 70,
+ flexGrow: 1,
},
cardTitulo: {
@@ -174,7 +175,7 @@ export const verso_styles = StyleSheet.create({
cardResposta: {
marginTop: 10,
- width: vw(70),
+ width: "100%",
color: "#f2f2f2",
textAlign: "left",
fontFamily: "Epilogue_500Medium",
diff --git a/index.js b/index.js
index 1d6e981..e201557 100644
--- a/index.js
+++ b/index.js
@@ -1,6 +1,7 @@
-import { registerRootComponent } from 'expo';
+import { registerRootComponent } from "expo";
+import "expo-asset";
-import App from './App';
+import App from "./App";
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in Expo Go or in a native build,
diff --git a/package.json b/package.json
index ce707a8..a6806ec 100644
--- a/package.json
+++ b/package.json
@@ -20,6 +20,7 @@
"expo-splash-screen": "~0.14.1",
"expo-sqlite": "~10.1.0",
"expo-status-bar": "~1.2.0",
+ "expo-updates": "~0.11.7",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
diff --git a/services/sqlite/Card.js b/services/sqlite/Card.js
index 6676b3f..eec53f7 100644
--- a/services/sqlite/Card.js
+++ b/services/sqlite/Card.js
@@ -53,17 +53,17 @@ const createCard = (obj) => {
* - O resultado da Promise é a quantidade de registros atualizados;
* - Pode retornar erro (reject) caso o ID não exista ou então caso ocorra erro no SQL.
*/
-const updateCard = (id, obj) => {
+const updateCard = (obj) => {
return new Promise((resolve, reject) => {
db.transaction((tx) => {
//comando SQL modificável
tx.executeSql(
- "UPDATE cars SET titulo=?, resposta=? WHERE id=?;",
- [obj.titulo, obj.resposta, id],
+ "UPDATE cards SET titulo=?, resposta=? WHERE id=?;",
+ [obj.titulo, obj.resposta, obj.id],
//-----------------------
(_, { rowsAffected }) => {
if (rowsAffected > 0) resolve(rowsAffected);
- else reject("Error updating obj: id=" + id); // nenhum registro alterado
+ else reject("Error updating obj: id=" + obj.id); // nenhum registro alterado
},
(_, error) => reject(error) // erro interno em tx.executeSql
);
@@ -130,20 +130,33 @@ const findCardByTitulo = (brand) => {
* - Pode retornar erro (reject) caso o ID não exista ou então caso ocorra erro no SQL;
* - Pode retornar um array vazio caso não existam registros.
*/
-const allCardsCategory = (categoriaId) => {
+const allCardsCategory = (categoriaId, search) => {
return new Promise((resolve, reject) => {
db.transaction((tx) => {
- //comando SQL modificável
- tx.executeSql(
- "SELECT * FROM cards WHERE categoriaId=?;",
- [categoriaId],
- //-----------------------
- (_, { rows }) => {
- if (rows.length > 0) resolve(rows._array);
- else resolve([]); // nenhum registro encontrado
- },
- (_, error) => reject(error) // erro interno em tx.executeSql
- );
+ if (search == "") {
+ //comando SQL modificável
+ tx.executeSql(
+ "SELECT * FROM cards WHERE categoriaId=?;",
+ [categoriaId],
+ //-----------------------
+ (_, { rows }) => {
+ if (rows.length > 0) resolve(rows._array);
+ else resolve([]); // nenhum registro encontrado
+ },
+ (_, error) => reject(error) // erro interno em tx.executeSql
+ );
+ } else {
+ tx.executeSql(
+ "SELECT * FROM cards WHERE categoriaId=? AND titulo LIKE ?;",
+ [categoriaId, `%${search}%`],
+ //-----------------------
+ (_, { rows }) => {
+ if (rows.length > 0) resolve(rows._array);
+ else resolve([]); // nenhum registro encontrado
+ },
+ (_, error) => reject(error) // erro interno em tx.executeSql
+ );
+ }
});
});
};
diff --git a/services/sqlite/Categoria.js b/services/sqlite/Categoria.js
index b13bf3f..36546ba 100644
--- a/services/sqlite/Categoria.js
+++ b/services/sqlite/Categoria.js
@@ -60,17 +60,17 @@ const createCategoria = (obj) => {
* - O resultado da Promise é a quantidade de registros atualizados;
* - Pode retornar erro (reject) caso o ID não exista ou então caso ocorra erro no SQL.
*/
-const updateCategoria = (id, obj) => {
+const updateCategoria = (obj) => {
return new Promise((resolve, reject) => {
db.transaction((tx) => {
//comando SQL modificável
tx.executeSql(
"UPDATE categorias SET cor=?, nome=? WHERE id=?;",
- [obj.cor, obj.nome, id],
+ [obj.cor, obj.nome, obj.id],
//-----------------------
(_, { rowsAffected }) => {
if (rowsAffected > 0) resolve(rowsAffected);
- else reject("Error updating obj: id=" + id); // nenhum registro alterado
+ else reject("Error updating obj: id=" + obj.id); // nenhum registro alterado
},
(_, error) => reject(error) // erro interno em tx.executeSql
);
@@ -111,17 +111,27 @@ const findCategoria = (id) => {
* - Pode retornar erro (reject) caso o ID não exista ou então caso ocorra erro no SQL;
* - Pode retornar um array vazio caso não existam registros.
*/
-const allCategorias = () => {
+const allCategorias = (search) => {
return new Promise((resolve, reject) => {
db.transaction((tx) => {
//comando SQL modificável
- tx.executeSql(
- "SELECT cat.*, COUNT(c.id) as quantCards FROM categorias as cat LEFT JOIN cards as c ON cat.id = c.categoriaId GROUP BY cat.id;",
- [],
- //-----------------------
- (_, { rows }) => resolve(rows._array),
- (_, error) => reject(error) // erro interno em tx.executeSql
- );
+ if (search == "") {
+ tx.executeSql(
+ "SELECT cat.*, COUNT(c.id) as quantCards FROM categorias as cat LEFT JOIN cards as c ON cat.id = c.categoriaId GROUP BY cat.id;",
+ [],
+ //-----------------------
+ (_, { rows }) => resolve(rows._array),
+ (_, error) => reject(error) // erro interno em tx.executeSql
+ );
+ } else {
+ tx.executeSql(
+ "SELECT cat.*, COUNT(c.id) as quantCards FROM categorias as cat LEFT JOIN cards as c ON cat.id = c.categoriaId WHERE cat.nome LIKE ? GROUP BY cat.id;",
+ [`%${search}%`],
+ //-----------------------
+ (_, { rows }) => resolve(rows._array),
+ (_, error) => reject(error) // erro interno em tx.executeSql
+ );
+ }
});
});
};
diff --git a/services/sqlite/PlayDB.js b/services/sqlite/PlayDB.js
index 3456d52..c0a1447 100644
--- a/services/sqlite/PlayDB.js
+++ b/services/sqlite/PlayDB.js
@@ -18,7 +18,7 @@ import CardDB from "./Card";
db.transaction((tx) => {
tx.executeSql(
// "CREATE TABLE play ( id INTEGER PRIMARY KEY AUTOINCREMENT, cardId INTEGER, categoriaId INTEGER, status INTEGER, espaco INTEGER, UNIQUE(cardId))"
- "CREATE TABLE play ( id INTEGER PRIMARY KEY AUTOINCREMENT, cardId INTEGER, categoriaId INTEGER, status INTEGER, views INTEGER, erros INTEGER, espaco INTEGER, UNIQUE(cardId))"
+ "CREATE TABLE IF NOT EXISTS play ( id INTEGER PRIMARY KEY AUTOINCREMENT, cardId INTEGER, categoriaId INTEGER, status INTEGER, views INTEGER, erros INTEGER, espaco INTEGER, UNIQUE(cardId))"
);
});
@@ -32,7 +32,7 @@ db.transaction((tx) => {
const createPlay = (categoriaId) => {
return new Promise((resolve, reject) => {
// puxando todos os cards da categoria
- CardDB.allCardsCategory(categoriaId).then((res) => {
+ CardDB.allCardsCategory(categoriaId, "").then((res) => {
db.transaction((tx) => {
// setando nova jogada para cada card que não foi setado
for (let obj of res) {
diff --git a/yarn.lock b/yarn.lock
index 8ca88cc..2c89b15 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2987,6 +2987,11 @@ expo-font@~10.0.4:
dependencies:
fontfaceobserver "^2.1.0"
+expo-json-utils@~0.2.0:
+ version "0.2.1"
+ resolved "https://registry.yarnpkg.com/expo-json-utils/-/expo-json-utils-0.2.1.tgz#a8d15181e361f3fc782d5241ce381851bab4465b"
+ integrity sha512-wU7gXGtaUlyxFLTp5e3PbnJB90/92r6gEc2BuMHdqE0OxhTQKyKzRszk2szCsdkeI7L4XntvZhCs1Px+gL1gvA==
+
expo-keep-awake@~10.0.1:
version "10.0.1"
resolved "https://registry.npmjs.org/expo-keep-awake/-/expo-keep-awake-10.0.1.tgz"
@@ -2997,6 +3002,13 @@ expo-linear-gradient@~11.0.1:
resolved "https://registry.yarnpkg.com/expo-linear-gradient/-/expo-linear-gradient-11.0.2.tgz#e59d28bb7f30f92f4a4da58955443860dc2335ca"
integrity sha512-zV3aNlPh92iRjC0A8r8lYHxEOZL9u2oqPUUJr6iz7nlcq2XEsa9nlT+CVs9LGRf+tVxBuIUvb/EjJyoe8IBXpA==
+expo-manifests@~0.2.2:
+ version "0.2.4"
+ resolved "https://registry.yarnpkg.com/expo-manifests/-/expo-manifests-0.2.4.tgz#28aa7a0b21d8b932e1a49c836cfc31b5a9cd1f9c"
+ integrity sha512-8PrMPyvElKXflYd1ApDHJR9JF0SR996iVEVQgHAMLzVP7OqEAM6dQaFeqrRqVn/DSsxEWkJTpxv8WJ5NWrT4Lg==
+ dependencies:
+ expo-json-utils "~0.2.0"
+
expo-modules-autolinking@0.5.5, expo-modules-autolinking@~0.5.1:
version "0.5.5"
resolved "https://registry.npmjs.org/expo-modules-autolinking/-/expo-modules-autolinking-0.5.5.tgz"
@@ -3045,6 +3057,31 @@ expo-status-bar@~1.2.0:
resolved "https://registry.npmjs.org/expo-status-bar/-/expo-status-bar-1.2.0.tgz"
integrity sha512-pVZZ/kDCXFK79E4dCtRecs3XLC8aiwlciutSd/fFmUPJSQZ1Txia6hlKajPt0GAYft8/YnT0V3URXzWZOBniYQ==
+expo-structured-headers@~2.1.0:
+ version "2.1.1"
+ resolved "https://registry.yarnpkg.com/expo-structured-headers/-/expo-structured-headers-2.1.1.tgz#bdbf8752af36c7d3203540476af55562546b6aeb"
+ integrity sha512-0up4sfHHsiK2YLpTwD/ssUD2oeSGzVUeARnu/itKAJO4zHqjpc+m8N1s7HPSJcdC7fdDpMjzcdrDasT0o+cOAw==
+
+expo-updates-interface@~0.5.0:
+ version "0.5.2"
+ resolved "https://registry.yarnpkg.com/expo-updates-interface/-/expo-updates-interface-0.5.2.tgz#5bb1e9be05db8013d5904fa8ed636c8c40604290"
+ integrity sha512-8BTaTl5pE5DYvqbJubnSH3rL55ay+wonPZe53f8CGj4PN3bV4UAQXbG9wFTDBtOaT982oyUUWdjUh/a1P3EVDw==
+
+expo-updates@~0.11.7:
+ version "0.11.7"
+ resolved "https://registry.yarnpkg.com/expo-updates/-/expo-updates-0.11.7.tgz#c267ce8818d42a997d49a1e24b11b4887a2fb17b"
+ integrity sha512-zmteCFOBj2OtDOZO5eGgFHR4EXZvFUv5DM56aMkZ6+PE/fo+8ZjNZLxkQWD33GXmXs/9jLCLKXPj2+6kCJvyhg==
+ dependencies:
+ "@expo/config" "^6.0.6"
+ "@expo/config-plugins" "^4.0.2"
+ "@expo/metro-config" "~0.2.6"
+ expo-manifests "~0.2.2"
+ expo-structured-headers "~2.1.0"
+ expo-updates-interface "~0.5.0"
+ fbemitter "^2.1.1"
+ resolve-from "^5.0.0"
+ uuid "^3.4.0"
+
expo@~44.0.0:
version "44.0.5"
resolved "https://registry.npmjs.org/expo/-/expo-44.0.5.tgz"