forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Mobile - Added first app initialization handling.
- Loading branch information
1 parent
fd39fb0
commit eaf5612
Showing
47 changed files
with
1,222 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
<template> | ||
<CommonNotifications /> | ||
<div | ||
class=" | ||
h-full | ||
max-h-full | ||
overflow-auto | ||
w-full | ||
bg-gray-200 | ||
text-center text-sm | ||
antialiased | ||
font-sans | ||
select-none | ||
" | ||
> | ||
<router-view v-if="applicationLoaded.value" v-slot="{ Component }"> | ||
<transition> | ||
<component v-bind:is="Component" /> | ||
</transition> | ||
</router-view> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
// This starter template is using Vue 3 <script setup> SFCs | ||
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup | ||
import CommonNotifications from '@common/components/CommonNotifications.vue' | ||
import useApplicationLoadedStore from '@common/stores/application/loaded' | ||
import { ref } from 'vue' | ||
import CommonHelloWorld from '@common/components/CommonHelloWorld.vue' | ||
const applicationLoaded = useApplicationLoadedStore() | ||
const state = ref<boolean>(false) | ||
applicationLoaded.setLoaded() | ||
</script> | ||
|
||
<template> | ||
<input v-model="state" type="checkbox" /> Show output? | ||
<CommonHelloWorld msg="Zammad Mobile!" :show="state" /> | ||
</template> | ||
|
||
<style> | ||
#app { | ||
font-family: Avenir, Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-align: center; | ||
color: #2c3e50; | ||
margin-top: 60px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,35 @@ | ||
import { createApp } from 'vue' | ||
import App from '@mobile/App.vue' | ||
import { DefaultApolloClient } from '@vue/apollo-composable' | ||
import apolloClient from '@common/server/apollo/client' | ||
import useSessionIdStore from '@common/stores/session/id' | ||
import '@common/styles/main.css' | ||
import initializeStore from '@common/stores' | ||
import InitializeHandler from '@common/initializer' | ||
import useApplicationConfigStore from '@common//stores/application/config' | ||
import initializeRouter from '@common/router/index' | ||
import routes from '@mobile/router' | ||
|
||
export default function mountApp(): void { | ||
createApp(App).mount('#app') | ||
export default async function mountApp(): Promise<void> { | ||
const app = createApp(App) | ||
|
||
app.provide(DefaultApolloClient, apolloClient) | ||
|
||
initializeStore(app) | ||
initializeRouter(app, routes) | ||
|
||
const initializer = new InitializeHandler( | ||
app, | ||
import.meta.globEager('/apps/mobile/initializer/*.ts'), | ||
) | ||
|
||
initializer.initialize() | ||
|
||
const sessionId = useSessionIdStore() | ||
await sessionId.checkSession() | ||
|
||
const applicationConfig = useApplicationConfigStore() | ||
await applicationConfig.getConfig() | ||
|
||
app.mount('#app') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { RouteRecordRaw } from 'vue-router' | ||
import Login from '@mobile/views/Login.vue' | ||
import Home from '@mobile/views/Home.vue' | ||
|
||
// TODO ...extend "meta" in RouteRecordRaw with real type behind. | ||
|
||
const routes: Array<RouteRecordRaw> = [ | ||
{ | ||
path: '/login', | ||
name: 'Login', | ||
props: true, | ||
component: Login, | ||
meta: {}, | ||
}, | ||
{ | ||
path: '/', | ||
name: 'Home', | ||
props: true, | ||
component: Home, | ||
meta: { | ||
requiresAuth: true, | ||
}, | ||
}, | ||
] | ||
|
||
export default routes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<template> | ||
<div> | ||
<h1>Home</h1> | ||
<p>{{ userData?.firstname }} {{ userData?.lastname }}</p> | ||
<br /> | ||
<p v-on:click="logout">Logout</p> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import useNotifications from '@common/composables/useNotifications' | ||
import useAuthenticatedStore from '@common/stores/authenticated' | ||
import useSessionUserStore from '@common/stores/session/user' | ||
import { storeToRefs } from 'pinia' | ||
import { useRouter } from 'vue-router' | ||
// TODO ... testing the notification | ||
const { notify } = useNotifications() | ||
notify({ | ||
message: 'Hello Home!!!', | ||
type: 'alert', | ||
}) | ||
const sessionUser = useSessionUserStore() | ||
const { value: userData } = storeToRefs(sessionUser) | ||
const authenticated = useAuthenticatedStore() | ||
const router = useRouter() | ||
const logout = (): void => { | ||
authenticated.logout().then(() => { | ||
router.push('/login') | ||
}) | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<template> | ||
<div> | ||
<h1>Login</h1> | ||
<p>Username: <input v-model="loginFormValues.login" type="text" /></p> | ||
<br /> | ||
<p> | ||
Password: <input v-model="loginFormValues.password" type="password" /> | ||
</p> | ||
<br /> | ||
<button v-on:click="login">Login</button> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import useAuthenticationStore from '@common/stores/authenticated' | ||
import { useRouter } from 'vue-router' | ||
const authentication = useAuthenticationStore() | ||
const loginFormValues = { | ||
login: '', | ||
password: '', | ||
} | ||
const router = useRouter() | ||
const login = (): void => { | ||
authentication | ||
.login(loginFormValues.login, loginFormValues.password) | ||
.then(() => { | ||
router.replace('/') | ||
}) | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue' | ||
defineProps<{ msg: string; show: boolean }>() | ||
const count = ref(0) | ||
</script> | ||
|
||
<template> | ||
<div v-if="show"> | ||
<h1>{{ msg }}</h1> | ||
<p>The first component.</p> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
defineProps<{ msg: string; show: boolean }>() | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<template> | ||
<div class="w-full flex justify-center"> | ||
<div class="fixed z-50" style="top: 30px; right: 0"> | ||
<transition-group | ||
tag="div" | ||
enter-class="opacity-0" | ||
leave-active-class="transition-opacity duration-1000 opacity-0" | ||
> | ||
<div v-for="notification in notifications" v-bind:key="notification.id"> | ||
<div class="flex justify-center"> | ||
<div class="flex items-center bg-black p-2 rounded text-white m-1"> | ||
<svg class="w-4 h-4 fill-current text-red-600"> | ||
<use | ||
xlink:href="assets/images/icons.svg#icon-diagonal-cross" | ||
></use> | ||
</svg> | ||
<span class="ml-2">{{ notification.message }}</span> | ||
</div> | ||
</div> | ||
</div> | ||
</transition-group> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import useNotifications from '@common/composables/useNotifications' | ||
const { notifications } = useNotifications() | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { v4 as uuid } from 'uuid' | ||
import { ref } from 'vue' | ||
|
||
interface NewNotificationInterface { | ||
id?: string | ||
message: string | ||
messagePlaceholder?: string[] | ||
type: string // TODO type for different types or enum? | ||
duration?: number | ||
} | ||
|
||
interface NotificationInterface extends NewNotificationInterface { | ||
id: string | ||
} | ||
|
||
const notifications = ref<NotificationInterface[]>([]) | ||
const defaultNotificationDuration = 5000 | ||
|
||
function removeNotification(id: string) { | ||
notifications.value = notifications.value.filter( | ||
(notification: NotificationInterface) => notification.id !== id, | ||
) | ||
} | ||
|
||
export default function useNotifications() { | ||
function notify(notification: NewNotificationInterface): string { | ||
// TODO: Check different solution for the optional id in the interface, but required field in the removeNotification function. | ||
let { id } = notification | ||
if (!id) { | ||
id = uuid() | ||
} | ||
|
||
const newNotification: NotificationInterface = { id, ...notification } | ||
|
||
notifications.value.push(newNotification) | ||
|
||
setTimeout(() => { | ||
removeNotification(newNotification.id) | ||
}, newNotification.duration || defaultNotificationDuration) | ||
|
||
return newNotification.id | ||
} | ||
|
||
return { | ||
notify, | ||
notifications, | ||
} | ||
} |
Oops, something went wrong.