Cristiano Magro
2025-01-07 ada7d27da93a1a59a4b2c54abeaa1e072a5793d5
10 - course project/xno-prj-cmp-01-starting-setup/src/components/learning-resource/TheResources.vue
@@ -11,7 +11,9 @@
      >Add Resource</base-button
    >
  </base-card>
  <component :is="selectedTab"></component>
  <KeepAlive>
    <component :is="selectedTab"></component>
  </KeepAlive>
</template>
<script>
@@ -53,12 +55,31 @@
  provide() {
    return {
      resources: this.storedResouces,
      addResource: this.addResource,
      deleteResource: this.removeResource,
    };
  },
  methods: {
    setSelectedTab(tab) {
      this.selectedTab = tab;
    },
    addResource(title, description, url) {
      const newResource = {
        id: new Date().toISOString(),
        title: title,
        description: description,
        link: url,
      };
      this.storedResouces.unshift(newResource);
      this.selectedTab = 'stored-resources';
    },
    removeResource(resId) {
      this.storedResouces = this.storedResouces.filter(
        (res) => res.id !== resId
      );
      console.log(this.storedResouces.length);
    },
  },
};
</script>