Skip to content

Commit 8afe1dc

Browse files
committed
feat: ラベルとアイコンを設定
1 parent fba061f commit 8afe1dc

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

interfaces/imasparql.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ interface Value {
22
value: string;
33
}
44

5-
interface Binding {
5+
export interface Binding {
66
class: Value;
77
count: Value;
88
label?: Value;

libs/create.ts

+33-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import { CardDetail } from "@interfaces/card.ts";
2-
import { ImasparqlResponse } from "@interfaces/imasparql.ts";
2+
import { Binding, ImasparqlResponse } from "@interfaces/imasparql.ts";
33

44
/**
5-
* クラス名をラベルに変換
6-
* @param c クラス名
5+
* ラベルを取得
6+
* @param b データ
77
* @returns ラベル
88
*/
9-
function toLabel(c: string): string {
9+
function getLabel(b: Binding): string {
10+
if (b.label) {
11+
return b.label.value;
12+
}
13+
1014
const altLabels = new Map([
1115
["MusicAlbum", "アルバム"],
1216
["MusicRelease", "CD"],
1317
["MusicComposition", "作詞・作曲家"],
1418
["MusicRecording", "楽曲"],
1519
]);
1620

17-
return altLabels.get(c) || "Unknown";
21+
return altLabels.get(b.class.value) || "不明なデータ";
1822
}
1923

2024
/**
@@ -25,6 +29,25 @@ function toLabel(c: string): string {
2529
function getIcon(c: string): string {
2630
const icons = new Map([
2731
["CallName", "messages"],
32+
["ScriptText", "message-circle"],
33+
["Unit", "users"],
34+
["SetlistNumber", "playlist"],
35+
["Clothes", "hanger"],
36+
["CinderellaRankingResult", "trophy"],
37+
["Introduction", "id"],
38+
["Idol", "user"],
39+
["Communication", "book-2"],
40+
["Live", "device-speaker"],
41+
["Event", "calendar-event"],
42+
["Staff", "briefcase"],
43+
["Idol_1st", "history"],
44+
["Facility", "building-community"],
45+
["MusicRecording", "music"],
46+
["Production", "building"],
47+
["CinderellaVoiceIdolAudition", "microphone-2"],
48+
["MusicComposition", "writing"],
49+
["MusicAlbum", "disc"],
50+
["MusicRelease", "disc"],
2851
]);
2952

3053
return icons.get(c) || "error-404";
@@ -38,13 +61,11 @@ function getIcon(c: string): string {
3861
export function createCardDetails(json: ImasparqlResponse): CardDetail[] {
3962
console.log(json);
4063

41-
const cards = json.results.bindings.map((e): CardDetail => {
42-
return {
43-
title: e.label?.value || toLabel(e.class.value),
44-
count: e.count.value,
45-
icon: getIcon(e.class.value),
46-
};
47-
});
64+
const cards = json.results.bindings.map((e): CardDetail => ({
65+
title: getLabel(e),
66+
count: e.count.value,
67+
icon: getIcon(e.class.value),
68+
}));
4869

4970
return cards;
5071
}

0 commit comments

Comments
 (0)