Skip to content

Commit

Permalink
fix: hardcoding available templates
Browse files Browse the repository at this point in the history
  • Loading branch information
BrewingWeasel committed Aug 15, 2024
1 parent 9e3eff3 commit 27f9e76
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
10 changes: 10 additions & 0 deletions data/templates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"language": "Custom",
"tags": []
},
{
"language": "Lithuanian",
"tags": ["Indo-European", "Baltic", "Full Support"]
}
]
48 changes: 34 additions & 14 deletions src/components/LanguageList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { DialogClose } from "@/components/ui/dialog";
import { Badge } from "@/components/ui/badge";
import { cn } from "@/lib/utils";
import { toast } from "vue-sonner";
const props = defineProps<{
isDialog: boolean;
Expand All @@ -13,38 +14,57 @@ const tagColors = new Map<string, string>([
["Baltic", "bg-pink-500"],
["Full Support", "bg-emerald-500"],
]);
// TAGS OVER
const languages: [string, string[]][] = [
["Custom", []],
// START
["Lithuanian", ["Indo-European", "Baltic", "Full Support"]],
// END
];
interface TemplateDetails {
language: string;
tags: string[];
}
async function getLanguages() {
try {
const response = await fetch(
"https://raw.githubusercontent.com/BrewingWeasel/Kalba/main/data/templates.json",
);
if (!response.ok) {
throw new Error(`Response status: ${response.status}`);
}
const json = (await response.json()) as TemplateDetails[];
return json;
} catch (error) {
toast.error(error as string);
return [];
}
}
const languages = await getLanguages();
</script>

<template>
<div>
<component
:is="props.isDialog ? DialogClose : 'div'"
as-child
v-for="[language, tags] in languages"
v-for="template in languages"
>
<div
@click="$emit('langSelected', language)"
@click="$emit('langSelected', template.language)"
:class="
cn(
'flex items-center p-2 rounded-md hover:bg-accent',
props.existingSelection === language
props.existingSelection === template.language
? 'bg-indigo-300 dark:bg-indigo-700 hover:bg-indigo-200 dark:hover:bg-indigo-800'
: '',
)
"
>
<h2 class="grow">{{ language }}</h2>
<Badge v-for="tag in tags" class="m-1" :class="tagColors.get(tag)">{{
tag
}}</Badge>
<h2 class="grow">{{ template.language }}</h2>
<Badge
v-for="tag in template.tags"
class="m-1"
:class="tagColors.get(tag)"
>{{ tag }}</Badge
>
</div>
</component>
</div>
Expand Down

0 comments on commit 27f9e76

Please sign in to comment.