Wire Profile Backend to Frontend (#71)

* Search updates

* fixes2

* Some more work

* start instance page wiring

* Pack installation + Profile viewing

* Remove print statement

* Fix disappearing profiles

* fix compile err

* Finish Instance Running

* remove print statement

* fix prettier

* Fix clippy + early return
This commit is contained in:
Geometrically
2023-04-08 18:54:38 -07:00
committed by GitHub
parent 764d75181f
commit a62d931fe2
27 changed files with 502 additions and 739 deletions

View File

@@ -2,13 +2,15 @@
<div class="instance-container">
<div class="side-cards">
<Card class="instance-card">
<Avatar size="lg" :src="getInstance(instanceStore).img" />
<Avatar size="lg" :src="convertFileSrc(instance.metadata.icon)" />
<div class="instance-info">
<h2 class="name">{{ getInstance(instanceStore).name }}</h2>
Fabric {{ getInstance(instanceStore).version }}
<h2 class="name">{{ instance.metadata.name }}</h2>
<span class="metadata"
>{{ instance.metadata.loader }} {{ instance.metadata.game_version }}</span
>
</div>
<span class="button-group">
<Button color="primary" class="instance-button">
<Button color="primary" class="instance-button" @click="run($route.params.id)">
<PlayIcon />
Play
</Button>
@@ -18,15 +20,15 @@
</span>
</Card>
<div class="pages-list">
<RouterLink :to="`/instance/${$route.params.id}/`" class="btn">
<RouterLink :to="`/instance/${encodeURIComponent($route.params.id)}/`" class="btn">
<BoxIcon />
Mods
</RouterLink>
<RouterLink :to="`/instance/${$route.params.id}/options`" class="btn">
<RouterLink :to="`/instance/${encodeURIComponent($route.params.id)}/options`" class="btn">
<SettingsIcon />
Options
</RouterLink>
<RouterLink :to="`/instance/${$route.params.id}/logs`" class="btn">
<RouterLink :to="`/instance/${encodeURIComponent($route.params.id)}/logs`" class="btn">
<FileIcon />
Logs
</RouterLink>
@@ -34,26 +36,20 @@
</div>
<div class="content">
<Promotion />
<router-view />
<router-view :instance="instance" />
</div>
</div>
</template>
<script setup>
import { BoxIcon, SettingsIcon, FileIcon, Button, Avatar, Card, Promotion } from 'omorphia'
import { PlayIcon, OpenFolderIcon } from '@/assets/icons'
import { useInstances } from '@/store/state'
import { get, run } from '@/helpers/profile'
import { useRoute } from 'vue-router'
import { shallowRef } from 'vue'
import { convertFileSrc } from '@tauri-apps/api/tauri'
const instanceStore = useInstances()
instanceStore.fetchInstances()
</script>
<script>
export default {
methods: {
getInstance(instanceStore) {
return instanceStore.instances.find((i) => i.id === parseInt(this.$route.params.id))
},
},
}
const route = useRoute()
const instance = shallowRef(await get(route.params.id))
</script>
<style scoped lang="scss">
@@ -101,6 +97,10 @@ Button {
color: var(--color-contrast);
}
.metadata {
text-transform: capitalize;
}
.instance-container {
display: flex;
flex-direction: row;

View File

@@ -10,6 +10,7 @@
Sort By
<DropdownSelect
v-model="sortFilter"
name="sort-by"
:options="['Name', 'Version', 'Author']"
default-value="Name"
class="dropdown"
@@ -33,9 +34,9 @@
<div class="table-cell table-text">Author</div>
<div class="table-cell table-text">Actions</div>
</div>
<div v-for="mod in search" :key="mod.name" class="table-row">
<div v-for="mod in search" :key="mod.file_name" class="table-row">
<div class="table-cell table-text">
<Button v-if="mod.outdated" icon-only>
<Button v-if="true" icon-only>
<UpdatedIcon />
</Button>
<Button v-else disabled icon-only>
@@ -43,10 +44,14 @@
</Button>
</div>
<div class="table-cell table-text name-cell">
<router-link :to="`/project/${mod.slug}/`" class="mod-text">
<router-link v-if="mod.slug" :to="`/project/${mod.slug}/`" class="mod-text">
<Avatar :src="mod.icon" />
{{ mod.name }}
</router-link>
<div v-else class="mod-text">
<Avatar :src="mod.icon" />
{{ mod.name }}
</div>
</div>
<div class="table-cell table-text">{{ mod.version }}</div>
<div class="table-cell table-text">{{ mod.author }}</div>
@@ -54,118 +59,17 @@
<Button icon-only>
<TrashIcon />
</Button>
<input id="switch-1" type="checkbox" class="switch stylized-toggle" checked />
<input
id="switch-1"
type="checkbox"
class="switch stylized-toggle"
:checked="mod.disabled"
/>
</div>
</div>
</div>
</Card>
</template>
<script>
export default {
name: 'Mods',
data() {
return {
searchFilter: '',
sortFilter: '',
mods: [
{
name: 'Fabric API',
slug: 'fabric-api',
icon: 'https://cdn.modrinth.com/data/P7dR8mSH/icon.png',
version: '0.76.0+1.19.4',
author: 'modmuss50',
description:
'Lightweight and modular API providing common hooks and intercompatibility measures utilized by mods using the Fabric toolchain.',
outdated: true,
},
{
name: 'Spirit',
slug: 'spirit',
icon: 'https://cdn.modrinth.com/data/b1LdOZlE/465598dc5d89f67fb8f8de6def21240fa35e3a54.png',
version: '2.2.4',
author: 'CodexAdrian',
description: 'Create your own configurable mob spawner!',
outdated: true,
},
{
name: 'Botarium',
slug: 'botarium',
icon: 'https://cdn.modrinth.com/data/2u6LRnMa/98b286b0d541ad4f9409e0af3df82ad09403f179.gif',
version: '2.0.5',
author: 'CodexAdrian',
description:
'A crossplatform API for devs that makes transfer and storage of items, fluids and energy easier, as well as some other helpful things',
outdated: true,
},
{
name: 'Tempad',
slug: 'tempad',
icon: 'https://cdn.modrinth.com/data/gKNwt7xu/icon.gif',
version: '2.2.4',
author: 'CodexAdrian',
description: 'Create a portal to anywhere from anywhere',
outdated: false,
},
{
name: 'Sodium',
slug: 'sodium',
icon: 'https://cdn.modrinth.com/data/AANobbMI/icon.png',
version: '0.4.10',
author: 'jellysquid3',
description: 'Modern rendering engine and client-side optimization mod for Minecraft',
outdated: false,
},
],
}
},
computed: {
search() {
const filtered = this.mods.filter((mod) => {
return mod.name.toLowerCase().includes(this.searchFilter.toLowerCase())
})
return this.updateSort(filtered, this.sortFilter)
},
},
methods: {
updateSort(projects, sort) {
switch (sort) {
case 'Version':
return projects.slice().sort((a, b) => {
if (a.version < b.version) {
return -1
}
if (a.version > b.version) {
return 1
}
return 0
})
case 'Author':
return projects.slice().sort((a, b) => {
if (a.author < b.author) {
return -1
}
if (a.author > b.author) {
return 1
}
return 0
})
default:
return projects.slice().sort((a, b) => {
if (a.name < b.name) {
return -1
}
if (a.name > b.name) {
return 1
}
return 0
})
}
},
},
}
</script>
<script setup>
import {
Avatar,
@@ -178,6 +82,97 @@ import {
UpdatedIcon,
DropdownSelect,
} from 'omorphia'
import { computed, ref, shallowRef } from 'vue'
import { convertFileSrc } from '@tauri-apps/api/tauri'
const props = defineProps({
instance: {
type: Object,
default() {
return {}
},
},
})
const projects = shallowRef([])
for (const project of Object.values(props.instance.projects)) {
if (project.metadata.type === 'modrinth') {
let owner = project.metadata.members.find((x) => x.role === 'Owner')
projects.value.push({
name: project.metadata.project.title,
slug: project.metadata.project.slug,
author: owner ? owner.user.username : null,
version: project.metadata.version.version_number,
file_name: project.file_name,
icon: project.metadata.project.icon_url,
disabled: project.disabled,
})
} else if (project.metadata.type === 'inferred') {
projects.value.push({
name: project.metadata.title ?? project.file_name,
author: project.metadata.authors[0],
version: project.metadata.version,
file_name: project.file_name,
icon: project.metadata.icon ? convertFileSrc(project.metadata.icon) : null,
disabled: project.disabled,
})
} else {
projects.value.push({
name: project.file_name,
author: '',
version: null,
file_name: project.file_name,
icon: null,
disabled: project.disabled,
})
}
}
const searchFilter = ref('')
const sortFilter = ref('')
const search = computed(() => {
const filtered = projects.value.filter((mod) => {
return mod.name.toLowerCase().includes(searchFilter.value.toLowerCase())
})
return updateSort(filtered, sortFilter.value)
})
function updateSort(projects, sort) {
switch (sort) {
case 'Version':
return projects.slice().sort((a, b) => {
if (a.version < b.version) {
return -1
}
if (a.version > b.version) {
return 1
}
return 0
})
case 'Author':
return projects.slice().sort((a, b) => {
if (a.author < b.author) {
return -1
}
if (a.author > b.author) {
return 1
}
return 0
})
default:
return projects.slice().sort((a, b) => {
if (a.name < b.name) {
return -1
}
if (a.name > b.name) {
return 1
}
return 0
})
}
}
</script>
<style scoped lang="scss">