Skip to content

Commit

Permalink
feat: allow reloading projects
Browse files Browse the repository at this point in the history
Makes use of the new load window state API to display that bridge. is reloading the com.mojang projects.
  • Loading branch information
solvedDev committed Sep 10, 2022
1 parent 0ce193a commit f801bd9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/components/OutputFolders/ComMojang/ProjectLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ export class ComMojangProjectLoader {
return this.app.comMojang.fileSystem
}

async reload() {
clearCache() {
this.cachedProjects = null
await this.loadProjects()
}

async loadProjects() {
Expand Down
23 changes: 22 additions & 1 deletion src/components/Projects/ProjectChooser/ProjectChooser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ export class ProjectChooserWindow extends NewBaseWindow {
super(ProjectChooserComponent, false, true)

this.state.actions.push(
new SimpleAction({
icon: 'mdi-refresh',
name: 'general.reload',
color: 'accent',
isDisabled: () => this.state.isLoading,
onTrigger: () => {
this.reload()
},
}),
new SimpleAction({
icon: 'mdi-import',
name: 'actions.importBrproject.name',
Expand Down Expand Up @@ -154,10 +163,22 @@ export class ProjectChooserWindow extends NewBaseWindow {
return app.projectManager.selectedProject
}

async reload() {
this.state.isLoading = true

this.comMojangProjectLoader.clearCache()
await this.loadProjects()

this.state.isLoading = false
}

async open() {
super.open()

this.state.isLoading = true
console.time('Load projects')
this.state.currentProject = await this.loadProjects()
console.timeEnd('Load projects')
super.open()
this.state.isLoading = false
}
}
10 changes: 8 additions & 2 deletions src/components/Projects/ProjectChooser/ProjectChooser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@closeWindow="onClose"
:sidebarItems="sidebar.elements"
:actions="state.actions"
:isLoading="state.isLoading"
v-model="sidebar.selected"
>
<template #sidebar>
Expand Down Expand Up @@ -162,7 +163,9 @@
<v-btn
v-if="!isComMojangProject"
color="primary"
:disabled="state.currentProject !== selectedSidebar"
:disabled="
state.currentProject !== selectedSidebar || state.isLoading
"
@click="onAddPack"
>
<v-icon class="mr-1">mdi-plus-box</v-icon>
Expand All @@ -174,6 +177,7 @@
v-if="!isComMojangProject"
color="error"
:loading="deletePending"
:disabled="state.isLoading"
@click="onDeleteProject(selectedSidebar)"
>
<v-icon>mdi-delete</v-icon>
Expand All @@ -183,7 +187,9 @@
<!-- Select Project -->
<v-btn
color="primary"
:disabled="state.currentProject === selectedSidebar"
:disabled="
state.currentProject === selectedSidebar || state.isLoading
"
@click="onSelectProject"
>
<v-icon>mdi-check</v-icon>
Expand Down

0 comments on commit f801bd9

Please sign in to comment.