Skip to content

Commit

Permalink
fix: code editing bug (#578)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyChen777 authored Jul 11, 2024
1 parent 866bd5e commit cc30b10
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions app/renderer/ui/edit-view/components/codes-input.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { BIconDashCircle, BIconPlusLg } from "bootstrap-icons-vue";
import { ref } from "vue";
import { computed, ref } from "vue";
const props = defineProps({
codes: {
Expand All @@ -9,7 +9,7 @@ const props = defineProps({
},
});
const codes = ref(props.codes.map((code) => JSON.parse(code)));
const parsedCodes = computed(() => props.codes.map((code) => JSON.parse(code)));
const emits = defineEmits(["event:change"]);
// ======================
Expand All @@ -23,25 +23,26 @@ const onInput = (payload: Event, index: number, key: string) => {
} else {
value = (payload.target as HTMLInputElement).checked;
}
codes.value[index][key] = value;
parsedCodes.value[index][key] = value;
emits(
"event:change",
codes.value.map((code) => JSON.stringify(code))
parsedCodes.value.map((code) => JSON.stringify(code))
);
};
const onAddClicked = () => {
codes.value.unshift({
code: "",
name: "",
});
const newCodes = [...parsedCodes.value, { url: "", isOfficial: false }];
emits(
"event:change",
newCodes.map((code) => JSON.stringify(code))
);
};
const onDeleteClicked = (index: number) => {
codes.value.splice(index, 1);
const newCodes = parsedCodes.value.filter((_, i) => i !== index);
emits(
"event:change",
codes.value.map((code) => JSON.stringify(code))
newCodes.map((code) => JSON.stringify(code))
);
};
</script>
Expand All @@ -62,7 +63,7 @@ const onDeleteClicked = (index: number) => {
</div>
<div class="overflow-scroll">
<div
v-for="(code, index) in codes"
v-for="(code, index) in parsedCodes"
:key="index"
class="flex space-x-2 bg-neutral-300 dark:bg-neutral-600 rounded-md px-2 py-1 my-1"
>
Expand Down

0 comments on commit cc30b10

Please sign in to comment.