Cristiano Magro
2025-01-07 1b68fe4dfebdd34300d05b156f66dc657b7c51bb
commit | author | age
2c19b5 1 <template>
CM 2   <base-card>
3     <base-button
4       @click="setSelectedTab('stored-resources')"
5       :mode="storedResButtonMode"
6       >Stored Resource</base-button
7     >
8     <base-button
9       @click="setSelectedTab('add-resource')"
10       :mode="addResButtonMode"
11       >Add Resource</base-button
12     >
13   </base-card>
1b68fe 14   <KeepAlive>
CM 15     <component :is="selectedTab"></component>
16   </KeepAlive>
2c19b5 17 </template>
CM 18
19 <script>
20 import StoredResources from './StoredResource.vue';
21 import AddResource from './AddResource.vue';
22
23 export default {
24   components: {
25     StoredResources: StoredResources,
26     AddResource: AddResource,
27   },
28   data() {
29     return {
30       selectedTab: 'stored-resources',
31       storedResouces: [
32         {
33           id: 'official-guide',
34           title: 'Official Guide',
35           description: 'The official Vue.js documentation',
36           link: 'https://vuejs.org',
37         },
38         {
39           id: 'google',
40           title: 'Google',
41           description: 'Learn to google...',
42           link: 'https://google.com',
43         },
44       ],
45     };
46   },
47   computed: {
48     storedResButtonMode() {
49       return this.selectedTab === 'stored-resources' ? null : 'flat';
50     },
51     addResButtonMode() {
52       return this.selectedTab === 'add-resource' ? null : 'flat';
53     },
54   },
55   provide() {
56     return {
57       resources: this.storedResouces,
1b68fe 58       addResource: this.addResource,
2c19b5 59     };
CM 60   },
61   methods: {
62     setSelectedTab(tab) {
63       this.selectedTab = tab;
64     },
1b68fe 65     addResource(title, description, url) {
CM 66       const newResource = {
67         id: new Date().toISOString(),
68         title: title,
69         description: description,
70         link: url,
71       };
72
73       this.storedResouces.unshift(newResource);
74       this.selectedTab = 'stored-resources';
75     },
2c19b5 76   },
CM 77 };
78 </script>
79
80 <style scoped></style>