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

Natnael.demo practice #269

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ba02f26
Install nuxt dependency
natitedros Jul 28, 2022
d26db67
Create link from landing page to my blog page
natitedros Jul 29, 2022
ed09872
Create an Add Blog page
natitedros Jul 29, 2022
0f3021f
include Create Add and Delete blog functionalities
natitedros Jul 30, 2022
fd5bbf3
[web] andualem added basic UI
AndualemSebsbe Jul 31, 2022
17c8f1d
Get data from the blog backend
natitedros Aug 1, 2022
309ab4e
Add basic UI
natitedros Aug 2, 2022
c5f5b8a
fixed warnings
natitedros Aug 2, 2022
2e770ca
Merge pull request #259 from RealEskalate/andualem.web.blog
AndualemSebsbe Aug 2, 2022
a997e57
[web] Implement Article CRUD (#255)
LibenHailu Aug 2, 2022
5ced8f1
Yared.demo project UI (#270)
Yared04 Aug 3, 2022
a141f83
[WEB]: folder restructure to work with team
Mintaa911 Aug 3, 2022
6629dbf
Add Vuex and edit UI with vuetify
natitedros Aug 3, 2022
642e2e6
Add _id page for each blogs
natitedros Aug 3, 2022
ca856d2
Yohans.web.demo (#256)
yohans-kasaw Aug 3, 2022
1065f2d
[WEB]: folder restructure
Mintaa911 Aug 3, 2022
5f684c6
Create link from landing page to my blog page
natitedros Jul 29, 2022
7649b1d
Create an Add Blog page
natitedros Jul 29, 2022
28b20ae
include Create Add and Delete blog functionalities
natitedros Jul 30, 2022
e76da36
Get data from the blog backend
natitedros Aug 1, 2022
87308a9
Add basic UI
natitedros Aug 2, 2022
3767785
fixed warnings
natitedros Aug 2, 2022
06e816f
Add Vuex and edit UI with vuetify
natitedros Aug 3, 2022
ccfe2f6
Add _id page for each blogs
natitedros Aug 3, 2022
3cb2e34
[web] add vuex and vuetify
natitedros Aug 4, 2022
16a47a0
[web] Edit previously commented pr
natitedros Aug 4, 2022
f035e35
[web] Edited previously commented pr
natitedros Aug 4, 2022
5512cc9
Merged to remote branch
natitedros Aug 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
17 changes: 17 additions & 0 deletions starter-project-web-vue2/components/natnaelT/AddBlogButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<v-btn @click="onClick()">{{text}}</v-btn>
</template>
<script>
export default {
name:'AddBlogButton',
props:{
text: String,
color: String
},
methods:{
onClick(){
this.$emit("toggle-add-blog")
}
}
}
</script>
89 changes: 89 additions & 0 deletions starter-project-web-vue2/components/natnaelT/AddBlogForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<template>
<form class="add-form" @submit="onSubmit">
<div class="form-control">
<label>Title</label>
<input v-model="title" type="text" name="content" placeholder="Blog Title here..." />
</div>
<div class="form-control">
<label>Content</label>
<input
v-model="content"
type="text"
name="content"
placeholder="Write here..."
/>
</div>
<input type="submit" value="Save Blog" class="btn" />
</form>
</template>

<script>
import {mapActions} from 'vuex'
export default {
name: 'AddBlogForm',

data() {
return {
title: '',
content: ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, a better approach is to declare blog object

blog: {
  title: '',
  content: ''
}

}
},
methods: {
...mapActions('natnaelT',['addBlog']),

onSubmit(e) {
e.preventDefault()
if (!this.title) {
alert('Please add a blog')
return
}
const newBlog = {
title: this.title,
content: this.content
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary if the above comment is addressed.

this.addBlog(newBlog)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.addBlog(this.blog)

this.title = ''
this.content = ''
},
},
}
</script>

<style scoped>

.add-form {
margin-bottom: 40px;
}

.form-control {
margin: 20px 0;
}

.form-control label {
display: block;
}

.form-control input {
width: 100%;
height: 40px;
margin: 5px;
padding: 3px 7px;
font-size: 17px;
}

.form-control-check {
display: flex;
align-items: center;
justify-content: space-between;
}

.form-control-check label {
flex: 1;
}

.form-control-check input {
flex: 2;
height: 20px;
}

</style>
46 changes: 46 additions & 0 deletions starter-project-web-vue2/components/natnaelT/BlogList.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<template>
<div>
<div class="singleblog" v-for="blog in allBlogs" :key="blog.id">
<SingleBlog :blog="blog" @delete-blog="deleteBlog(blog.id)" @update-blog="updateBlog(blog.id)"/>

</div>
</div>
</template>

<script>
import {mapGetters, mapActions} from "vuex";
import SingleBlog from './SingleBlog.vue';

export default {
name:"BlogList",
methods:{
...mapActions('natnaelT',['fetchBlogs','deleteBlog','updateBlog']),
},
computed: mapGetters('natnaelT',['allBlogs']),
created(){
this.fetchBlogs();
},

components:{
SingleBlog
}
}
</script>
<style>

.btn {
display: flex;
padding: 1px;
margin: 1px;
border-radius: 0.5px;
}

.singleblog{
border: 1px solid;
border-radius: 6px;
padding: 10px;
margin: 15px;
box-shadow: 1px 1px 4px gray;
}

</style>
25 changes: 25 additions & 0 deletions starter-project-web-vue2/components/natnaelT/SingleBlog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<template>
<div class="card">
<v-card-text>
<h2>{{blog.title}}</h2>
<p>{{blog.content}}</p>
<v-btn class="btn" @click="$emit('update-blog',blog.id)">Update</v-btn>
<v-btn class="btn" @click="$emit('delete-blog',blog.id)">Delete</v-btn>
<nuxt-link style="text-decoration: none;" :to="'/natnaelT/'+ blog._id">
<v-btn>
Show more
</v-btn>
</nuxt-link>
</v-card-text>
</div>
</template>

<script>
export default {
name: "SingleBlog",
props: {
blog: Object
},
emits: ["delete-blog","update-blog"]
}
</script>
16 changes: 3 additions & 13 deletions starter-project-web-vue2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion starter-project-web-vue2/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ export default {
description: 'Summer Intern',
link:
'/abraham',
},
},{
name: "Natnael Tedros",
description: 'Summer Intern',
link:
'/natnaelT',
}
],
}
},
Expand Down
42 changes: 42 additions & 0 deletions starter-project-web-vue2/pages/natnaelT/_id.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<template>
<div>
<nuxt-link to="/natnaelT/">
<v-btn class="ma-2" color="#1F7087" dark>
<v-icon dark left> mdi-arrow-left </v-icon>Back
</v-btn>
</nuxt-link>
<v-card>
<h2>{{blog.title}}</h2>
<v-container>
<p>{{blog.content}}</p>
</v-container>
</v-card>
</div>
</template>

<script>
import axios from 'axios'
export default {
data() {
return {
blog: {
title: '',
content: '',
},
}
},
async created() {
try {
const response = await axios.get(
`https://blog-app-backend.onrender.com/api/articles/${this.$route.params.id}`
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reading and writing data should be handled by vuex.

this.blog = response.data
} catch (err) {
this.$nuxt.error({
statusCode: err.statusCode,
message: err.message,
})
}
},
}
</script>
75 changes: 75 additions & 0 deletions starter-project-web-vue2/pages/natnaelT/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<template>
<div class="addblog">
<AddBlogButton :text="showAddBlog ? 'Close' : 'Add Blog'" :color= "showAddBlog ? 'red' : 'blue'" @toggle-add-blog="toggleAddBlog()" />
<div v-if="showAddBlog" class="addblogform">
<AddBlogForm />
</div>
<div class="bloglist">
<BlogList />
</div>
</div>
</template>

<script>

import AddBlogForm from '~/components/natnaelT/AddBlogForm.vue';
import AddBlogButton from '~/components/natnaelT/AddBlogButton.vue';
import BlogList from '~/components/natnaelT/BlogList.vue';
export default {
data() {
return {
showAddBlog: false
}
},
components: {
AddBlogButton,
AddBlogForm,
BlogList
},
head() {
return {
title: "Blog App",
meta: [{
hid: "description",
name: "Blog page",
content: "Blog to save thoughts"
}]
};
},

methods:{
toggleAddBlog(){
this.showAddBlog = !this.showAddBlog
},
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run npm run lintfix before committing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fix indentation and other style problems


}
</script>

<style>

.addblog p{
font-style: italic;
}

.addblog nuxt-link{
display: inline-block;
background: blue;
color: aliceblue;
padding: 0.3rem 1rem;
margin-right: 0.5rem;
}

.btn{
justify-content: center;
background: lightblue;
padding: 5px 10px;
color: black;
display: inline-block;
margin: 2px;
border-radius: 10px;

}

</style>
Loading