Merge pull request #238 from shikorism/feature/disable-inserted-tag

入力済みのタグ候補の背景色を変更する
This commit is contained in:
shibafu 2019-07-14 01:06:02 +09:00 committed by GitHub
commit c5cbad4475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 5 deletions

View File

@ -20,8 +20,8 @@
<p class="card-text mb-2" style="font-size: small;">タグ候補<br><span class="text-secondary">(クリックするとタグ入力欄にコピーできます)</span></p>
<ul class="list-inline d-inline">
<li v-for="tag in suggestions"
class="list-inline-item badge badge-primary metadata-tag-item"
@click="addTag(tag)"><span class="oi oi-tag"></span> {{ tag }}</li>
:class="tagClasses(tag)"
@click="addTag(tag.name)"><span class="oi oi-tag"></span> {{ tag.name }}</li>
</ul>
</template>
</div>
@ -54,6 +54,11 @@
}[],
};
type Suggestion = {
name: string,
used: boolean,
}
@Component
export default class MetadataPreview extends Vue {
@Prop() readonly state!: MetadataLoadState;
@ -62,16 +67,38 @@
// for use in v-if
private readonly MetadataLoadState = MetadataLoadState;
tags: string[] = [];
created() {
bus.$on("change-tag", (tags: string[]) => this.tags = tags);
bus.$emit("resend-tag");
}
addTag(tag: string) {
bus.$emit("add-tag", tag);
}
get suggestions() {
tagClasses(s: Suggestion) {
return {
"list-inline-item": true,
"badge": true,
"badge-primary": !s.used,
"badge-secondary": s.used,
"metadata-tag-item": true,
};
}
get suggestions(): Suggestion[] {
if (this.metadata === null) {
return [];
}
return this.metadata.tags.map(t => t.name);
return this.metadata.tags.map(t => {
return {
name: t.name,
used: this.tags.indexOf(t.name) !== -1
};
});
}
get hasImage() {

View File

@ -16,7 +16,7 @@
</template>
<script lang="ts">
import {Vue, Component, Prop} from "vue-property-decorator";
import {Vue, Component, Prop, Watch} from "vue-property-decorator";
import {bus} from "../checkin";
@Component
@ -31,6 +31,7 @@
created() {
bus.$on("add-tag", (tag: string) => this.tags.indexOf(tag) === -1 && this.tags.push(tag));
bus.$on("resend-tag", () => bus.$emit("change-tag", this.tags));
}
onKeyDown(event: KeyboardEvent) {
@ -56,6 +57,11 @@
this.tags.splice(index, 1);
}
@Watch("tags")
onTagsChanged() {
bus.$emit("change-tag", this.tags);
}
get containerClass(): object {
return {
"form-control": true,