1
1
<script setup lang="ts">
2
- import { computed , PropType , reactive , ref } from " vue" ;
3
- import { Plugin , ProjectMetadata , Flavor } from " @/types/app.types" ;
2
+ import { computed , reactive , ref , defineAsyncComponent } from " vue" ;
3
+ import { Flavor , Plugin , ProjectMetadata } from " @/types/app.types" ;
4
4
import RadioGroup from " @/components/RadioGroup.vue" ;
5
5
import { FLAVORS , PROJECT_DEFINITION } from " @/constant/constant" ;
6
6
import { pluginService } from " @/services/PluginService" ;
7
- import ItemPlugin from " @/components/ItemPlugin.vue" ;
8
- import Modal from " @/components/Modal.vue" ;
9
- import { useWindowSize } from " @vueuse/core" ;
7
+ import { useClipboard , useWindowSize } from " @vueuse/core" ;
10
8
import { DownloadProjectService } from " @/services/DownloadProjectService" ;
11
- import Loading from " @/components/Loading.vue" ;
12
- import SearchPlugins from " @/components/SearchPlugins.vue" ;
9
+ import { shared } from " @/utils/Shared" ;
10
+ import { SharedProject } from " @/types/share.types" ;
11
+ import { useRoute } from " vue-router" ;
12
+ import { useCommonStore } from " @/plugins/stores/Common.store" ;
13
+ const ItemPlugin = defineAsyncComponent (
14
+ () => import (" @/components/ItemPlugin.vue" )
15
+ );
16
+ const SearchPlugins = defineAsyncComponent (
17
+ () => import (" @/components/SearchPlugins.vue" )
18
+ );
19
+ const Modal = defineAsyncComponent (() => import (" @/components/Modal.vue" ));
20
+ const LoadingDownload = defineAsyncComponent (
21
+ () => import (" @/components/LoadingDownload.vue" )
22
+ );
23
+ const Loading = defineAsyncComponent (() => import (" @/components/Loading.vue" ));
13
24
14
25
const downloadProjectService: DownloadProjectService =
15
26
new DownloadProjectService ();
16
27
const { width } = useWindowSize ();
28
+ const route = useRoute ();
29
+ const commonStore = useCommonStore ();
17
30
const loading = ref (false );
31
+ const loadingPlugins = ref (false );
18
32
const refDownload = ref <HTMLAnchorElement >();
19
33
const formFlavor = ref <Flavor []>(FLAVORS );
20
34
const projectMetadata = reactive <ProjectMetadata >(PROJECT_DEFINITION );
21
35
const pluginsStore = ref <Plugin []>([]);
22
36
const addPlugins = ref <Plugin []>([]);
23
37
const openModalAddPlugin = ref (false );
24
- const reactNativePlugins = ref (false );
38
+
39
+ const flavorSelected = computed <Flavor | undefined >(() =>
40
+ formFlavor .value .find ((flavor ) => flavor .selected )
41
+ );
42
+ const sharedProjectData = reactive <
43
+ SharedProject & { openModal : boolean ; dataString : string }
44
+ > ({
45
+ flavor: " " ,
46
+ name: " " ,
47
+ plugins: [],
48
+ openModal: false ,
49
+ rnPlugins: false ,
50
+ dataString: " " ,
51
+ });
52
+ const { copy : copyClipboard } = useClipboard ();
25
53
26
54
const onSelectedFlavor = (index : number ) => {
27
- console .log (index );
28
55
formFlavor .value .forEach ((flavor ) => (flavor .selected = false ));
29
56
formFlavor .value [index ].selected = true ;
30
57
};
@@ -48,15 +75,40 @@ const removePlugin = (plugin: Plugin) => {
48
75
49
76
const download = async () => {
50
77
loading .value = true ;
51
- const flavor = formFlavor .value .find ((flavor ) => flavor .selected );
52
- if (flavor ) {
78
+ if (flavorSelected .value ) {
53
79
await downloadProjectService .download (
54
80
refDownload .value ! ,
55
- flavor ,
81
+ flavorSelected . value ,
56
82
projectMetadata ,
57
83
addPlugins .value
58
84
);
59
- loading .value = false ;
85
+ }
86
+ loading .value = false ;
87
+ };
88
+
89
+ if (shared .isSharedProject (route )) {
90
+ loadingPlugins .value = true ;
91
+ const shareData = shared .retrieveSharedProject (route );
92
+ const indexFlavor = FLAVORS .findIndex (
93
+ (flavor : Flavor ) => flavor .text === shareData .flavor
94
+ );
95
+ onSelectedFlavor (indexFlavor );
96
+ projectMetadata .name = shareData .name ;
97
+ projectMetadata .description = shareData .description ;
98
+ projectMetadata .package = shareData .package ;
99
+ commonStore .enableReactNativePlugins = shareData .rnPlugins ;
100
+ }
101
+
102
+ const sharedProject = () => {
103
+ if (flavorSelected .value ) {
104
+ const sharedData = shared .buildURL (
105
+ flavorSelected .value ,
106
+ projectMetadata ,
107
+ addPlugins .value ,
108
+ commonStore .enableReactNativePlugins
109
+ );
110
+ sharedProjectData .openModal = true ;
111
+ sharedProjectData .dataString = sharedData ;
60
112
}
61
113
};
62
114
@@ -67,16 +119,23 @@ pluginService.findAll().then((plugins) => {
67
119
return new Date (b .date ) - new Date (a .date );
68
120
})
69
121
);
122
+ if (shared .isSharedProject (route )) {
123
+ loadingPlugins .value = true ;
124
+ shared .resolvePlugins (route , pluginsStore .value ).then ((plugins ) => {
125
+ addPlugins .value .push (... plugins );
126
+ loadingPlugins .value = false ;
127
+ });
128
+ }
70
129
});
71
130
</script >
72
131
73
132
<template >
74
- <Loading
133
+ <LoadingDownload
75
134
:full =" true"
76
135
message =" Generating project"
77
136
:show =" loading"
78
137
position =" fixed"
79
- ></Loading >
138
+ ></LoadingDownload >
80
139
<div class =" px-3 my-8 mb-16" >
81
140
<a ref =" refDownload" ></a >
82
141
<div class =" width-content grid lg:grid-cols-2 grid-cols-1" >
@@ -100,7 +159,7 @@ pluginService.findAll().then((plugins) => {
100
159
</div >
101
160
</div >
102
161
</div >
103
- <div class =" lg:p-4 p-0 mt-9 lg:border-left" >
162
+ <div class =" lg:p-4 p-0 mt-9 lg:border-left relative " >
104
163
<div class =" flex justify-between items-center border-b pb-4" >
105
164
<h3 class =" text-2xl" >Plugins</h3 >
106
165
<div
@@ -110,7 +169,9 @@ pluginService.findAll().then((plugins) => {
110
169
Add plugins
111
170
</div >
112
171
</div >
113
- <div class =" mt-2 added-plugin" >
172
+ <div class =" mt-2 added-plugin relative" style =" min-height : 200px " >
173
+ <Loading :show =" loadingPlugins" position =" absolute" ></Loading >
174
+
114
175
<div
115
176
v-for =" (pluginAdded, i) in addPlugins"
116
177
:key =" i"
@@ -148,6 +209,12 @@ pluginService.findAll().then((plugins) => {
148
209
<span class =" mdi mdi-github ml-2" ></span >
149
210
</a >
150
211
</div >
212
+ <button
213
+ class =" px-3 md:px-5 py-2 text-white bg font-bold mr-4 rounded-full"
214
+ @click =" sharedProject"
215
+ >
216
+ Shared
217
+ </button >
151
218
<button
152
219
class =" px-5 py-2 color-bg font-bold mr-4 md:mr-0 rounded-full"
153
220
style =" background : var (--color-ns-cyan )"
@@ -171,6 +238,32 @@ pluginService.findAll().then((plugins) => {
171
238
>
172
239
</SearchPlugins >
173
240
</Modal >
241
+ <Modal
242
+ :open =" sharedProjectData.openModal"
243
+ @close =" sharedProjectData.openModal = false"
244
+ >
245
+ <div
246
+ class =" p-6 flex flex-col items-center relative"
247
+ :style =" { minWidth: width < 900 ? '85vw' : '35vw' }"
248
+ >
249
+ <h3 class =" text-2xl text-left w-full" >Copy and share project</h3 >
250
+ <input
251
+ class =" mt-8 w-full"
252
+ type =" text"
253
+ v-model =" sharedProjectData.dataString"
254
+ disabled
255
+ />
256
+ <VDropdown :distance =" 6" >
257
+ <button
258
+ @click =" copyClipboard(sharedProjectData.dataString)"
259
+ class =" mdi mdi-content-copy cursor-pointer mt-4"
260
+ ></button >
261
+ <template #popper >
262
+ <div class =" text-white p-3" >Copied</div >
263
+ </template >
264
+ </VDropdown >
265
+ </div >
266
+ </Modal >
174
267
</div >
175
268
</template >
176
269
0 commit comments