Move AppstoreView to vue composition api

This commit is contained in:
Johannes Zellner
2025-01-06 18:52:44 +01:00
parent fca66222df
commit 5d6cf5789a

View File

@@ -18,62 +18,46 @@
</div>
</template>
<script>
<script setup>
import { ref, computed, useTemplateRef, onMounted } from 'vue';
import { TextInput } from 'pankow';
import AppstoreModel from '../models/AppstoreModel.js';
import AppInstallDialog from './AppInstallDialog.vue';
const API_ORIGIN = import.meta.env.VITE_API_ORIGIN ? import.meta.env.VITE_API_ORIGIN : window.location.origin;
const accessToken = localStorage.token;
const appstoreModel = AppstoreModel.create(API_ORIGIN, accessToken);
const appstoreModel = AppstoreModel.create(API_ORIGIN, localStorage.token);
export default {
name: 'AppstoreView',
components: {
AppInstallDialog,
TextInput,
},
data() {
return {
API_ORIGIN,
ready: false,
apps: [],
search: '',
activeApp: {
manifest: {}
},
};
},
computed: {
filteredApps() {
if (!this.search) return this.apps;
const ready = ref(false);
const apps = ref([]);
const search = ref('');
const filteredApps = computed(() => {
if (!search.value) return apps.value;
const search = this.search.toLowerCase();
const search = search.value.toLowerCase();
return this.apps.filter(a => {
if (a.manifest.title.toLowerCase().indexOf(search) !== -1) return true;
if (a.manifest.tagline.toLowerCase().indexOf(search) !== -1) return true;
if (a.manifest.tags.join().toLowerCase().indexOf(search) !== -1) return true;
return false;
});
}
},
methods: {
onInstall(app) {
this.$refs.appInstallDialog.open(app);
},
},
async mounted() {
this.apps = await appstoreModel.list();
return apps.value.filter(a => {
if (a.manifest.title.toLowerCase().indexOf(search) !== -1) return true;
if (a.manifest.tagline.toLowerCase().indexOf(search) !== -1) return true;
if (a.manifest.tags.join().toLowerCase().indexOf(search) !== -1) return true;
return false;
});
});
const appInstallDialog = useTemplateRef('appInstallDialog');
const searchInput = useTemplateRef('searchInput');
this.ready = true;
function onInstall(app) {
appInstallDialog.value.open(app);
}
setTimeout(() => this.$refs.searchInput.$el.focus(), 0);
}
};
onMounted(async () => {
apps.value = await appstoreModel.list();
ready.value = true;
setTimeout(() => searchInput.value.$el.focus(), 0);
});
</script>