Skip to content

Commit

Permalink
feat: improve Error component to be more dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Aug 26, 2020
1 parent 9fd83b1 commit ebd57b8
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 48 deletions.
63 changes: 63 additions & 0 deletions components/utils/Error.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<template>
<div
class="p-2 m-6 text-center text-default-text"
:class="{ 'material-container': renderBorders }"
>
<!-- Header -->
<div>
<h1
class="px-2 mx-auto mb-1 text-2xl font-bold tracking-wide border w-max-content"
>
{{ errorTitle }}
</h1>
</div>

<!-- Body -->
<div>
<p>
{{ errorData }}
</p>
</div>

<!-- Action -->
<div v-if="showAction">
<button type="button" class="color-util" @click="reload()">
Reload the page?
</button>
</div>
</div>
</template>

<script>
export default {
name: 'Error',
props: {
errorTitle: {
type: String,
default: 'Error',
},
errorData: {
type: String,
default: 'Something went wrong',
},
showAction: {
type: Boolean,
default: true,
},
renderBorders: {
type: Boolean,
default: true,
},
},
methods: {
reload() {
location.reload()
},
},
}
</script>
21 changes: 21 additions & 0 deletions components/utils/ErrorManager.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<Error v-if="errors" />
</template>

<script>
import { mapState } from 'vuex'
import Error from './Error'
export default {
name: 'ErrorManager',
components: {
Error,
},
computed: {
...mapState(['errors']),
},
}
</script>
42 changes: 0 additions & 42 deletions components/utils/Errors.vue

This file was deleted.

6 changes: 3 additions & 3 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>

<!-- Content -->
<Errors />
<ErrorManager />

<Post v-for="post in posts.data" :key="post.id" :post="post" />

Expand All @@ -22,14 +22,14 @@ import { mapState } from 'vuex'
// Components
import DomainSelector from '~/components/pages/posts/domain/Selector.vue'
import Post from '~/components/pages/posts/content/Post.vue'
import Errors from '~/components/utils/Errors.vue'
import ErrorManager from '~/components/utils/ErrorManager.vue'
// Mixins
import PostsStartupMixin from '~/components/pages/posts/util/PostsStartupMixin.js'
export default {
components: {
Errors,
ErrorManager,
DomainSelector,
Notifications: () =>
import('~/components/pages/posts/navigation/Notifications.vue'),
Expand Down
6 changes: 3 additions & 3 deletions pages/premium/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<template v-else>
<div class="flex flex-col h-screen m-auto justify-evenly">
<!-- Log In -->
<errors />
<ErrorManager />

<login />

Expand All @@ -63,10 +63,10 @@ import Login from '@/components/pages/premium/Login'
import Subscription from '@/components/pages/premium/Subscription'
import PremiumDashboard from '@/components/pages/premium/PremiumDashboard'
import Errors from '~/components/utils/Errors.vue'
import ErrorManager from '~/components/utils/ErrorManager.vue'
export default {
components: { Login, Subscription, Errors, PremiumDashboard },
components: { Login, Subscription, ErrorManager, PremiumDashboard },
computed: {
...mapGetters('premium', ['hasValidLicenseKey']),
Expand Down

0 comments on commit ebd57b8

Please sign in to comment.