Skip to content

Commit

Permalink
feat(desktop): support for automatic component import
Browse files Browse the repository at this point in the history
  • Loading branch information
Red-Asuka authored and ysfscream committed Oct 31, 2024
1 parent bf4ac74 commit c55811c
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 31 deletions.
8 changes: 8 additions & 0 deletions apps/desktop/electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import VueRouter from 'unplugin-vue-router/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
main: {
Expand All @@ -25,6 +27,12 @@ export default defineConfig({
],
}),
vue(),
Components({
dts: true,
directoryAsNamespace: true,
dirs: ['src/components', '../../../../packages/ui/src/components'],
resolvers: [ElementPlusResolver()],
}),
],
},
})
1 change: 1 addition & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"sass": "^1.69.3",
"tailwindcss": "^3.3.3",
"typescript": "^5.1.6",
"unplugin-vue-components": "^0.27.4",
"unplugin-vue-router": "^0.10.8",
"vite": "^4.4.9",
"vitest": "^0.34.6",
Expand Down
23 changes: 23 additions & 0 deletions apps/desktop/src/renderer/components.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable */
// @ts-nocheck
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
export {}

/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
CommonEmptyView: typeof import('./../../../../packages/ui/src/components/common/EmptyView.vue')['default']
CommonLeftMenu: typeof import('./../../../../packages/ui/src/components/common/LeftMenu.vue')['default']
CommonMainView: typeof import('./../../../../packages/ui/src/components/common/MainView.vue')['default']
CommonSplitView: typeof import('./../../../../packages/ui/src/components/common/SplitView.vue')['default']
ConnectionsDetailsView: typeof import('./../../../../packages/ui/src/components/connections/DetailsView.vue')['default']
ConnectionsListView: typeof import('./../../../../packages/ui/src/components/connections/ListView.vue')['default']
ElAside: typeof import('element-plus/es')['ElAside']
ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider']
ElContainer: typeof import('element-plus/es')['ElContainer']
ElMain: typeof import('element-plus/es')['ElMain']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
}
}
14 changes: 6 additions & 8 deletions apps/desktop/src/renderer/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ console.log('MQTTX Desktop App init...')
</script>

<template>
<el-config-provider :locale="ElementI18nMap[settingsStore.lang]">
<el-container>
<left-menu />
<main-view />
</el-container>
</el-config-provider>
<ElConfigProvider :locale="ElementI18nMap[settingsStore.lang]">
<ElContainer>
<CommonLeftMenu />
<CommonMainView />
</ElContainer>
</ElConfigProvider>
</template>

<style lang="scss" scoped></style>
8 changes: 3 additions & 5 deletions apps/desktop/src/renderer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import './assets/scss/main.scss'
import { createApp } from 'vue'
import App from './App.vue'

import ElementPlus from 'element-plus'

import { router } from './router'
import MqttxUI, { pinia, i18n, useSettingsStore } from '@mqttx/ui'
import { pinia, i18n, useSettingsStore } from '@mqttx/ui'

// Create Vue
const app = createApp(App)

app.use(router).use(pinia).use(MqttxUI)
app.use(router).use(pinia)

// I18n
const settingsStore = useSettingsStore()
i18n.global.locale = settingsStore.lang

app.use(ElementPlus).use(i18n).mount('#app')
app.use(i18n).mount('#app')
13 changes: 7 additions & 6 deletions apps/desktop/src/renderer/src/pages/connections/[id].vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<script lang="ts" setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
// import { computed } from 'vue'
// import { useRoute } from 'vue-router'
const route = useRoute()
const id = computed(() => route.name === '/connections/[id]' && route.params.id)
// const route = useRoute()
// const id = computed(() => route.name === '/connections/[id]' && route.params.id)
</script>

<template>
<connection-details-view
TODO: Connection Details View
<!-- <ConnectionsDetailsView
:connection="{
name: 'test',
id,
}"
/>
/> -->
</template>
10 changes: 5 additions & 5 deletions apps/desktop/src/renderer/src/pages/connections/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ const { connections } = useMockData()
</script>

<template>
<split-view class="connections-container" min-size="180px" max-size="400px">
<CommonSplitView class="connections-container" min-size="180px" max-size="400px">
<template #panel-1>
<div class="connections-list">
<connection-list-view :data="connections" />
<ConnectionsListView :data="connections" />
</div>
</template>
<template #panel-2>
<div class="connection-detail">
<router-view v-if="connections.length" />
<empty-view v-else />
<RouterView v-if="connections.length" />
<CommonEmptyView v-else />
</div>
</template>
</split-view>
</CommonSplitView>
</template>
3 changes: 2 additions & 1 deletion apps/desktop/tsconfig.web.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"src/renderer/src/**/*",
"src/renderer/src/**/*.vue",
"src/preload/*.d.ts",
"./typed-router.d.ts"
"./typed-router.d.ts",
"src/renderer/components.d.ts"
],
"compilerOptions": {
"composite": true,
Expand Down
4 changes: 0 additions & 4 deletions packages/ui/src/components/common/MainView.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<script setup lang="ts"></script>

<template>
<el-main>
<router-view></router-view>
</el-main>
</template>

<style lang="scss" scoped></style>
2 changes: 0 additions & 2 deletions packages/ui/src/components/common/SplitView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,3 @@ onMounted(() => {
</div>
</div>
</template>

<style scoped></style>
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit c55811c

Please sign in to comment.