Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added functionality to rename presets #320

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/components/display/PresetItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
class="button"
:title="t('misc.export')"
></el-button>
<el-button
:icon="IconEpEdit"
text
size="small"
circle
@click.stop="$emit('rename')"
class="button"
:title="t('misc.rename')"
></el-button>
</div>
</div>
<div class="body">
Expand Down Expand Up @@ -59,8 +68,8 @@ import { weaponData } from "@weapon"
import { targetFunctionData } from "@targetFunction"

import IconFa6SolidDownload from "~icons/fa6-solid/download"
import IconEpEdit from "~icons/ep/edit"
import IconEpDelete from "~icons/ep/delete"
import IconEpCPU from "~icons/ep/cpu"
import {IPreset} from "@/types/preset"
import {useI18n} from "@/i18n/i18n";

Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ export default {
exportAll: "Export All",
go: "Please go to",
toCalc: "page to add new presets",
wrongFormat: "Wrong format"
wrongFormat: "Wrong format",
renamePresetTitle:"Rename the preset",
renamePresetContent:"Please enter the new name for the preset",
},
calcPage: {
selectArt: "Select Artifact",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/zh-cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ export default {
exportAll: "导出全部",
go: "请前往",
toCalc: "页面添加预设",
wrongFormat: "导入格式错误"
wrongFormat: "导入格式错误",
renamePresetTitle:"重命名预设",
renamePresetContent:"请输入新的预设名字",
},
calcPage: {
selectArt: "选择圣遗物",
Expand Down
11 changes: 11 additions & 0 deletions src/pages/CharacterPresetsPage/CharacterPresetsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
:calculate-icon="false"
@delete="handleDeletePreset(entry.name)"
@download="handleDownload(entry.name)"
@rename="handleRename(entry.name)"
class="item"
@click="handleClickPreset(entry.name)"
></preset-item>
Expand Down Expand Up @@ -153,6 +154,16 @@ function handleDownload(name: string) {
downloadString(str, "application/json", name)
}

function handleRename(name:string){
ElMessageBox.prompt(t("presetPage.renamePresetContent"), t("presetPage.renamePresetTitle"), {
confirmButtonText: t("misc.confirm"),
cancelButtonText: t("misc.cancel"),
inputValue:name,
}).then(({ value }) => {
presetStore.renamePreset(name,value)
}).catch(() => {})
}

function handleExportAll() {
const str = JSON.stringify(presetStore.allFlat.value)

Expand Down
11 changes: 11 additions & 0 deletions src/store/pinia/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ function f() {
return presets.value[name]
}

function renamePreset(name:string,newName:string):boolean{
const preset = getPreset(name)
if(preset===undefined) return false
const item = preset.item
item.name = newName
deletePreset(name)
addOrOverwrite(newName,item)
return getPreset(newName)!==undefined
}

function deletePreset(name: string) {
delete presets.value[name]
}
Expand All @@ -68,6 +78,7 @@ function f() {
addOrOverwrite,
deletePreset,
getPreset,
renamePreset,

allFlat,
count
Expand Down