Skip to content

Commit

Permalink
Components Added
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitsinghania94 committed Jun 1, 2018
1 parent aba714d commit f624df6
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 117 deletions.
143 changes: 26 additions & 117 deletions App.vue
Original file line number Diff line number Diff line change
@@ -1,101 +1,60 @@
<template>
<view class="container">
<!-- <img src="'https://images.template.net/wp-content/uploads/2014/06/42567177.jpg'"/> -->
<view class="text-input-container">
<view class="text-input-wrapper">
<text-input placeholder = 'Enter new todo' v-bind:on-change-text = 'handleOnChangeText' v-model="newTodo"/>
</view>
<touchable-opacity class="add-button" title="Button" v-bind:on-press='handleAddPress' v-bind:disabled='emptyInput'>
<text class="text-color-primary">ADD</text>
</touchable-opacity>
</view>
<AddTodo
:onAdd='addTodo'
/>
<scroll-view>
<view class='todo-wrapper' v-for='(todo, index) in todos' :key='index'>
<touchable-opacity v-bind:on-press="() => onTaskPressed(index)" v-if="!todo.edited">
<text v-bind:class="[todo.isCompleted ? 'text-task-completed' : 'text-todo-task']">
• {{todo.task}}
</text>
</touchable-opacity>
<view class="task-input-wrapper" v-if="todo.edited">
<text-input placeholder='Enter Task' v-bind:on-change-text="(text) => handleOnChangeTask(text, index)" v-bind:value='todo.task'/>
</view>
<view class='todo-button-wrapper' v-if="todo.edited">
<touchable-opacity v-bind:on-press="() => handleDonePress(index)" class='done-button'>
<text class="text-color-primary">
DONE
</text>
</touchable-opacity>
<touchable-opacity v-bind:on-press="() => handleCancelPress(index)" class='done-button'>
<text class="text-color-primary">
X
</text>
</touchable-opacity>
</view>
<view class='todo-button-wrapper' v-if="!todo.edited">
<touchable-opacity v-bind:on-press="() => handleEditPress(index)" class='edit-button'>
<text class="text-color-primary">
E
</text>
</touchable-opacity>
<touchable-opacity v-bind:on-press="() => handleDeletePress(index)">
<text class="text-color-primary">
X
</text>
</touchable-opacity>
</view>
<TodoItem
:todo='todo'
:selectedIndex='index'
:onEditPressed='onEditPressed'
:editTodo='editTodo'
:deleteTodo='deleteTodo'
:cancelEdit='cancelEdit'
:onTaskPressed='onTaskPressed'
/>
</view>
</scroll-view>
</view>
</template>

<script>
import AddTodo from './src/AddTodo'
import TodoItem from './src/TodoItem'
export default {
data: function() {
return {
newTodo: undefined,
newTodo: '',
todos: [],
emptyInput: true,
taskStyle: 'text-todo-task',
editedText: ''
// image: 'https://images.template.net/wp-content/uploads/2014/06/42567177.jpg'
};
},
components: {
AddTodo,
TodoItem
},
methods: {
handleAddPress: function() {
let todo = {
task: this.newTodo,
isCompleted: false,
edited: false
}
addTodo: function(todo) {
this.todos.push(todo)
this.newTodo = ''
this.emptyInput = true
},
handleEditPress: function(index) {
onEditPressed: function(index) {
this.todos[index].edited = true
},
handleDonePress: function(index) {
if (this.editedText !== '')
this.todos[index].task = this.editedText
editTodo: function(index, editedTask) {
this.todos[index].task = editedTask
this.todos[index].edited = false
},
handleCancelPress: function(index) {
cancelEdit: function(index) {
this.todos[index].edited = false
},
handleOnChangeTask: function(text, index) {
this.editedText = text
},
onTaskPressed: function(index) {
this.todos[index].isCompleted = !this.todos[index].isCompleted
},
handleDeletePress: function(index) {
deleteTodo: function(index) {
this.todos.splice(index, 1)
},
handleOnChangeText: function(text) {
this.newTodo = text
if (text === '') this.emptyInput = true
else this.emptyInput = false
}
}
}
</script>
Expand All @@ -107,46 +66,6 @@ export default {
flex: 1;
padding-top: 40;
}
.todo-button-wrapper {
flex-direction: row
}
.done-button {
margin-left: 40
}
.edit-button {
padding-right: 20
}
.text-color-primary {
color: rgba(0, 0, 0, 0.767);
}
.text-todo-task {
color:grey;
}
.text-task-completed {
color: rgba(201, 29, 29, 0.534);
text-decoration-line: line-through;
}
.button-primary {
background-color: white;
padding: 5
}
.text-input-wrapper {
flex: 1;
border-width: 1;
border-color: rgb(112, 84, 46);
justify-content: center;
padding: 10
}
.task-input-wrapper {
flex: 1;
border-width: 1;
border-color: rgba(201, 29, 29, 0.534);
justify-content: center;
padding: 10
}
.text-input-primary {
flex: 1;
}
.todo-wrapper {
margin-horizontal: 15;
background-color: beige;
Expand All @@ -157,14 +76,4 @@ export default {
padding: 10;
border-radius: 5;
}
.add-button {
background-color: rgba(201, 29, 29, 0.534);
padding-horizontal: 10;
justify-content: center;
}
.text-input-container {
margin-horizontal: 15;
flex-direction: row;
padding-bottom: 20
}
</style>
Binary file added assets/.DS_Store
Binary file not shown.
Binary file added assets/check_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/cross_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/edit_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/.DS_Store
Binary file not shown.
58 changes: 58 additions & 0 deletions src/AddTodo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<template>
<view class="text-input-container">
<view class="text-input-wrapper">
<text-input placeholder = 'Enter new todo' v-model="newTodo"/>
</view>
<touchable-opacity class="add-button" title="Button" :on-press='addTodo' :disabled="(newTodo === '')">
<text class="text-color-primary">ADD</text>
</touchable-opacity>
</view>
</template>

<script>
export default {
data: function() {
return {
newTodo: ''
};
},
props: {
onAdd: Function
},
methods: {
addTodo: function() {
let todo = {
task: this.newTodo,
isCompleted: false,
edited: false
}
this.onAdd(todo)
this.newTodo = ''
},
}
}
</script>
>

<style>
.text-color-primary {
color: rgba(0, 0, 0, 0.767);
}
.text-input-wrapper {
flex: 1;
border-width: 1;
border-color: rgb(112, 84, 46);
justify-content: center;
padding: 10
}
.add-button {
background-color: rgba(201, 29, 29, 0.534);
padding-horizontal: 10;
justify-content: center;
}
.text-input-container {
margin-horizontal: 15;
flex-direction: row;
padding-bottom: 20
}
</style>
114 changes: 114 additions & 0 deletions src/TodoItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<template>
<view class='todo-wrapper'>
<touchable-opacity :on-press='handleTaskPressed' v-if="!todo.edited">
<text v-bind:class="[todo.isCompleted ? 'text-task-completed' : 'text-todo-task']">
• {{todo.task}}
</text>
</touchable-opacity>
<view class="task-input-wrapper" v-if="todo.edited">
<text-input placeholder='Enter Task' v-model='editedTask'/>
</view>
<view class='todo-button-wrapper' v-if="todo.edited">
<touchable-opacity :on-press="checkIconPress" class='done-button'>
<image :source='checkIcon' class='image-style'/>
</touchable-opacity>
<touchable-opacity v-bind:on-press="cancelIconPress" class='done-button'>
<image :source='crossIcon' class='image-style'/>
</touchable-opacity>
</view>
<view class='todo-button-wrapper' v-if="!todo.edited">
<touchable-opacity :on-press="editIconPress" class='edit-button'>
<image :source='editIcon' class='image-style'/>
</touchable-opacity>
<touchable-opacity :on-press="deleteIconPress">
<image :source='crossIcon' class='image-style'/>
</touchable-opacity>
</view>
</view>
</template>

<script>
import editIcon from '../assets/edit_icon.png';
import crossIcon from '../assets/cross_icon.png';
import checkIcon from '../assets/check_icon.png';
export default {
data: function() {
return {
editedTask: this.todo.task,
editIcon,
crossIcon,
checkIcon
};
},
props: {
todo: Object,
selectedIndex: Number,
editTodo: Function,
deleteTodo: Function,
cancelEdit: Function,
onTaskPressed: Function,
onEditPressed: Function
},
methods: {
editIconPress: function() {
this.onEditPressed(this.selectedIndex)
},
checkIconPress: function() {
if (this.editedTask !== '')
this.editTodo(this.selectedIndex, this.editedTask)
else {
this.editedTask = this.todo.task
this.cancelEdit(this.selectedIndex)
}
},
cancelIconPress: function() {
this.cancelEdit(this.selectedIndex)
},
handleTaskPressed: function() {
this.onTaskPressed(this.selectedIndex)
},
deleteIconPress: function(index) {
this.deleteTodo(this.selectedIndex)
},
}
}
</script>
>

<style>
.todo-button-wrapper {
flex-direction: row
}
.done-button {
margin-left: 20
}
.image-style {
height: 20;
width: 20;
}
.edit-button {
padding-right: 20
}
.text-todo-task {
color:grey;
}
.text-task-completed {
color: rgba(201, 29, 29, 0.534);
text-decoration-line: line-through;
}
.task-input-wrapper {
flex: 1;
border-width: 1;
border-color: rgba(201, 29, 29, 0.534);
justify-content: center;
padding: 10
}
.todo-wrapper {
justify-content: space-between;
align-items: center;
flex-direction: row;
flex: 1;
}
</style>

0 comments on commit f624df6

Please sign in to comment.