Skip to content

Commit

Permalink
profiles can now be deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed Nov 21, 2024
1 parent e000fdc commit 64f41e8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
8 changes: 8 additions & 0 deletions backend/common/profile/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (pm *ProfileManager) SaveProfile(gameTitle, profileName string, prof Profil
return SaveManifest(gameTitle, profileName, prof)
}

func (pm *ProfileManager) DeleteProfile(gameTitle, profileName string) error {
return DeleteManifest(gameTitle, profileName)
}

func PathToProfilesDir(gameTitle string) string {
cacheDir, _ := os.UserConfigDir()
path := filepath.Join(cacheDir, "modm8", "Games", gameTitle, "Profiles")
Expand Down Expand Up @@ -94,6 +98,10 @@ func SaveManifest(gameTitle, profileName string, prof ProfileManifest) error {
return backend.SaveFile(PathToProfile(gameTitle, profileName), data)
}

func DeleteManifest(gameTitle, profileName string) error {
return os.Remove(PathToProfile(gameTitle, profileName))
}

func GetManifest(gameTitle, profileName string) (*ProfileManifest, error) {
contents, err := backend.ReadFile(PathToProfile(gameTitle, profileName))
if err != nil {
Expand Down
25 changes: 18 additions & 7 deletions frontend/src/components/selected-game/ProfileManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Listbox, { ListboxChangeEvent } from 'primevue/listbox'
import InputGroup from 'primevue/inputgroup'
import Popover from 'primevue/popover'
import { NewProfile } from '@backend/profile/ProfileManager'
import { NewProfile, DeleteProfile } from '@backend/profile/ProfileManager'
import { tooltipOpts } from '@frontend/src/util'
import { t } from '@i18n'
Expand Down Expand Up @@ -37,11 +37,11 @@ const onChange = (e: ListboxChangeEvent) => {
emit('profileSelected', e)
}
const toggleProfilePopover = (e: MouseEvent) => {
const togglePopover = (e: MouseEvent) => {
pp?.value.show(e)
}
const createProfile = async (e: MouseEvent) => {
const createNewProf = async (e: MouseEvent) => {
await NewProfile(selectedGame.value.title, newProfNameInput.value!)
await initProfiles()
Expand All @@ -50,6 +50,17 @@ const createProfile = async (e: MouseEvent) => {
emit('profileCreated', e)
}
const renameProf = (_: MouseEvent, name: string) => {
}
const deleteProf = async (e: MouseEvent, name: string) => {
e.stopPropagation()
await DeleteProfile(selectedGame.value.title, name)
await initProfiles()
}
const shouldDisableCreation = () => {
if (newProfNameInput.value.length < 1) return true // No input yet
Expand Down Expand Up @@ -86,7 +97,7 @@ onMounted(async () => {
<Button
icon="pi pi-plus" severity="primary"
v-tooltip.top="tooltipOpts(t('selected-game.profile-manager.new-profile'))"
@click="toggleProfilePopover"
@click="togglePopover"
/>

<Popover ref="pp">
Expand All @@ -97,7 +108,7 @@ onMounted(async () => {
<InputText v-model="newProfNameInput" v-keyfilter="/^[^<>*!\/]+$/"/>
<Button
label="Create" severity="success" icon="pi pi-check"
:disabled="shouldDisableCreation()" @click="createProfile"
:disabled="shouldDisableCreation()" @click="createNewProf"
/>
</InputGroup>
</div>
Expand Down Expand Up @@ -141,12 +152,12 @@ onMounted(async () => {
<div class="flex gap-1">
<Button
style="width: 34px; height: 32px;" icon="pi pi-pencil"
@click=""
@click="e => renameProf(e, profile.name)"
/>

<Button
style="width: 34px; height: 32px;" icon="pi pi-trash" severity="danger"
@click="e => e.stopPropagation()"
@click="e => deleteProf(e, profile.name)"
/>
</div>
</div>
Expand Down

0 comments on commit 64f41e8

Please sign in to comment.