Skip to content

Commit b053dc1

Browse files
committed
Fix AiSummary
1 parent b012124 commit b053dc1

File tree

4 files changed

+20
-43
lines changed

4 files changed

+20
-43
lines changed

client/src/components/AiSummaries.vue

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
<template>
2-
<!-- <div v-for="(d, i) in data" v-bind:key="i" class="summary-container bg-success bg-opacity-25">
3-
<ai-summary
4-
:summary-data="d"
5-
:onAddTag="props.onAddTag"
6-
:onSetDescription="props.onSetDescription"
7-
@remove-data="removeData(d)"
8-
></ai-summary>
9-
</div> -->
10-
112
<small v-if="fullText.length < 500" class="text-muted"> 🤖 {{ t("ai.summary.hint", { count: 500 - fullText.length }) }}</small>
123
<button v-else-if="data.length < 3" type="button" class="btn btn-sm btn-outline-success" :disabled="loading" @click="loadNewSummary">
134
<loading-spinner v-if="loading" class="smallSpinner" /><span v-else>🤖🪄</span> {{ t("ai.summarize") }}
@@ -23,6 +14,7 @@
2314
@canceled="canceled()"
2415
@acceptDescription="props.onSetDescription"
2516
@addTag="props.onAddTag"
17+
@remove-ai-summary="removeAiSummary"
2618
></ai-summary-dialog>
2719
</template>
2820

@@ -69,9 +61,9 @@ const data = ref<AiSummaryData[]>([]);
6961
const loading = ref<boolean>(false);
7062
const showAiDialog = ref<boolean>(false);
7163
72-
// const removeData = (d: AiSummaryData) => {
73-
// data.value = data.value.filter((it) => it != d);
74-
// };
64+
function removeAiSummary(d: AiSummaryData) {
65+
data.value = data.value.filter((it) => it != d);
66+
}
7567
7668
const loadNewSummary = (e: MouseEvent) => {
7769
e.preventDefault();

client/src/components/AiSummary.vue

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<template>
22
<div>
33
<div v-if="isSuccessfulAiSummaryData(summaryData)">
4-
<!-- <button type="button" class="btn-close btn-close-white float-end" aria-label="Close" @click="$emit('removeData')"></button> -->
4+
<button type="button" class="btn-close btn-close-white float-end" aria-label="Close" @click="$emit('removeAiSummary')"></button>
55
<div class="summary-text-container">
66
<div class="summary-text">{{ summaryData.summary }}</div>
7-
<button type="button" class="btn btn-sm btn-outline-success" @click="$emit('acceptDescription', summaryData.summary)">
7+
<button type="button" class="btn btn-sm btn-outline-success" @click="$emit('updateDescription', summaryData.summary)">
88
{{ t("ai.summary.accept") }}
99
</button>
1010
</div>
@@ -24,11 +24,12 @@
2424
<div class="row">
2525
<div class="col-md-4" v-for="prompt in summaryData.imagePrompts" v-bind:key="prompt">
2626
<button class="btn btn-sm btn-outline-success" @click="acceptImagePrompt($event, prompt)">
27-
<fa-icon :icon="faImage"></fa-icon>🪄
27+
<fa-icon :icon="faImage"></fa-icon><fa-icon :icon="faWandMagicSparkles"></fa-icon>
2828
{{ prompt }}
2929
</button>
3030
</div>
3131
</div>
32+
</div>
3233
<div v-else class="bg-danger">
3334
{{ summaryData.error }}
3435
</div>
@@ -44,28 +45,25 @@
4445
</style>
4546

4647
<script setup lang="ts">
47-
import { OpenAiEndpoints } from "@client/util/api-client.js";
4848
import { t } from "@client/plugins/i18n.js";
49+
import { OpenAiEndpoints } from "@client/util/api-client.js";
50+
import { faImage, faWandMagicSparkles } from "@fortawesome/free-solid-svg-icons";
4951
import type { AiSummaryData } from "@fumix/fu-blog-common";
5052
import { isSuccessfulAiSummaryData } from "@fumix/fu-blog-common";
51-
import { onMounted } from "vue";
5253
import type { PropType } from "vue";
53-
import { faImage, faWandSparkles } from "@fortawesome/free-solid-svg-icons";
54+
import { onMounted } from "vue";
5455
5556
const props = defineProps({
5657
summaryData: { type: Object as PropType<AiSummaryData>, required: true },
57-
onAddTag: { type: Function as PropType<(tag: string) => void> },
58-
onSetDescription: { type: Function as PropType<(description: string) => void> },
5958
});
6059
6160
function acceptDescription(e: MouseEvent, description: string) {
6261
e.preventDefault();
63-
props.onSetDescription?.(description);
62+
emit("updateDescription", description);
6463
}
6564
6665
async function acceptImagePrompt(e: MouseEvent, prompt: string) {
6766
e.preventDefault();
68-
alert(prompt); // TODO: send event to parent
6967
await OpenAiEndpoints.dallEGenerateImage(prompt)
7068
.then((it) => {
7169
alert(JSON.stringify(it));
@@ -77,16 +75,16 @@ async function acceptImagePrompt(e: MouseEvent, prompt: string) {
7775
7876
function acceptTag(e: MouseEvent, tag: string) {
7977
e.preventDefault();
80-
props.onAddTag?.(tag);
78+
emit("addTag", tag);
8179
}
8280
83-
const emit = defineEmits(["removeData", "acceptDescription"]);
81+
const emit = defineEmits(["updateDescription", "addTag", "removeAiSummary"]);
8482
8583
onMounted(() => {
8684
// auto remove if error
8785
if (!isSuccessfulAiSummaryData(props.summaryData)) {
8886
setTimeout(() => {
89-
emit("removeData");
87+
emit("removeAiSummary");
9088
}, 5000);
9189
}
9290
});

client/src/components/AiSummaryDialog.vue

+4-8
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
<div v-for="(d, i) in data" v-bind:key="i" class="summary-container">
1010
<ai-summary
1111
:summary-data="d"
12-
@addTag="addTag($event)"
13-
@acceptDescription="acceptDescription($event)"
14-
@remove-data="removeData(d)"
12+
@add-tag="addTag($event)"
13+
@update-description="acceptDescription($event)"
14+
@remove-ai-summary="$emit('removeAiSummary', d)"
1515
></ai-summary>
1616
</div>
1717
</div>
@@ -42,18 +42,14 @@ const props = defineProps({
4242
},
4343
});
4444
45-
const emits = defineEmits(["acceptDescription", "canceled", "addTag"]);
45+
const emits = defineEmits(["acceptDescription", "canceled", "addTag", "removeAiSummary"]);
4646
4747
watch(props, () => {
4848
const myModal = new Modal(document.getElementById("aiModal") || "", {});
4949
const show = props.show;
5050
show ? myModal?.show() : myModal.hide();
5151
});
5252
53-
const removeData = (d: AiSummaryData) => {
54-
alert("TODO remove data");
55-
// data.value = data.value.filter((it) => it != d);
56-
};
5753
const acceptDescription = (description: string) => {
5854
emits("acceptDescription", description);
5955
};

client/src/views/PostFormView.vue

+1-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
:placeholder="t('posts.form.tags.enter')"
2525
@on-tags-changed="handleTagsChanged"
2626
:add-tag-on-keys="[13, 188]"
27+
@input="handleAutocompletion"
2728
/>
2829
</div>
2930

@@ -46,16 +47,6 @@
4647
<div id="markdownHelp" class="form-text">{{ t("posts.form.message.hint") }}</div>
4748
</div>
4849

49-
<div class="form-floating mb-3">
50-
<label for="stringTags">{{ t("posts.form.tags") }}</label>
51-
<vue3-tags-input
52-
:tags="form.stringTags"
53-
placeholder="Geben Sie Schlagwörter ein..."
54-
@on-tags-changed="handleTagsChanged"
55-
@input="handleAutocompletion"
56-
/>
57-
</div>
58-
5950
<div class="form-check form-switch">
6051
<input v-model="form.draft" class="form-check-input" type="checkbox" id="draft" />
6152
<label class="form-check-label" for="draft">{{ t("posts.form.draft") }}</label>

0 commit comments

Comments
 (0)