Move AppstoreView to vue composition api
This commit is contained in:
@@ -18,62 +18,46 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script setup>
|
||||||
|
|
||||||
|
import { ref, computed, useTemplateRef, onMounted } from 'vue';
|
||||||
import { TextInput } from 'pankow';
|
import { TextInput } from 'pankow';
|
||||||
|
|
||||||
import AppstoreModel from '../models/AppstoreModel.js';
|
import AppstoreModel from '../models/AppstoreModel.js';
|
||||||
import AppInstallDialog from './AppInstallDialog.vue';
|
import AppInstallDialog from './AppInstallDialog.vue';
|
||||||
|
|
||||||
const API_ORIGIN = import.meta.env.VITE_API_ORIGIN ? import.meta.env.VITE_API_ORIGIN : window.location.origin;
|
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 {
|
const ready = ref(false);
|
||||||
name: 'AppstoreView',
|
const apps = ref([]);
|
||||||
components: {
|
const search = ref('');
|
||||||
AppInstallDialog,
|
const filteredApps = computed(() => {
|
||||||
TextInput,
|
if (!search.value) return apps.value;
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
API_ORIGIN,
|
|
||||||
ready: false,
|
|
||||||
apps: [],
|
|
||||||
search: '',
|
|
||||||
activeApp: {
|
|
||||||
manifest: {}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
filteredApps() {
|
|
||||||
if (!this.search) return this.apps;
|
|
||||||
|
|
||||||
const search = this.search.toLowerCase();
|
const search = search.value.toLowerCase();
|
||||||
|
|
||||||
return this.apps.filter(a => {
|
return apps.value.filter(a => {
|
||||||
if (a.manifest.title.toLowerCase().indexOf(search) !== -1) return true;
|
if (a.manifest.title.toLowerCase().indexOf(search) !== -1) return true;
|
||||||
if (a.manifest.tagline.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;
|
if (a.manifest.tags.join().toLowerCase().indexOf(search) !== -1) return true;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
},
|
const appInstallDialog = useTemplateRef('appInstallDialog');
|
||||||
methods: {
|
const searchInput = useTemplateRef('searchInput');
|
||||||
onInstall(app) {
|
|
||||||
this.$refs.appInstallDialog.open(app);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
async mounted() {
|
|
||||||
this.apps = await appstoreModel.list();
|
|
||||||
|
|
||||||
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>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user