-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove Tool.vue component and update error handling
Signed-off-by: tylerslaton <[email protected]>
- Loading branch information
1 parent
c6c9876
commit ffc33e6
Showing
8 changed files
with
103 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<template> | ||
<div> | ||
<Navigation /> | ||
<Navigation class="fixed w-full top-0 z-50"/> | ||
<NuxtPage /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<template> | ||
<div class="flex flex-col items-center justify-center h-screen"> | ||
<h1 class="text-4xl font-bold mb-4">{{ props.title }}</h1> | ||
<p class="text-lg"> {{ props.message }}</p> | ||
<router-link to="/" class="mt-4 text-blue-500 hover:underline">Go back to home</router-link> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const props = defineProps({ | ||
title: String, | ||
message: String, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
<template> | ||
<div class="sidebar text-gray-600"> | ||
<div v-for="header in headers" :key="header.id" class="mb-4 overflow-auto"> | ||
<a :href="`#${header.id}`">{{ header.innerHTML || "root" }}</a> | ||
<div v-for="header in props.headers" :key="'sidebar-'+header" class="mb-4 overflow-auto"> | ||
<a :href="`#tool-${header}`">{{ header || "root" }}</a> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, onMounted } from 'vue'; | ||
const headers = ref([]); | ||
onMounted(() => { | ||
fetchHeaders(); | ||
const props = defineProps({ | ||
headers: { | ||
type: Array, | ||
required: true | ||
} | ||
}); | ||
const fetchHeaders = () => headers.value = Array.from(document.querySelectorAll('h2')); | ||
</script> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,63 @@ | ||
<template> | ||
<div class="flex"> | ||
<div class="hidden md:block border-r border-gray-200"> | ||
<Sidebar class="mx-20 sticky top-8 pt-10"/> | ||
</div> | ||
<div class="pt-10 mx-auto w-auto sm:mx-20"> | ||
<Tool :owner="owner" :path="path"/> | ||
<div> | ||
<div v-if="!error.status" class="flex"> | ||
<div class="hidden md:block border-r border-gray-200"> | ||
<Sidebar :headers="tools.map(tool => tool.name)" class="mt-28 sticky top-28 px-20"/> | ||
</div> | ||
|
||
<div class="prose my-28 mx-20"> | ||
<h1 class="mb-0">{{ path }}</h1> | ||
<a :href="githubURL" target="_blank" class="text-blue-500 underline">{{ githubURL }}</a> | ||
<div v-for="tool in tools" :key="tool.id"> | ||
<h2 :id="'tool-' + tool.name">{{ tool.name }}</h2> | ||
<p class="">{{ tool.description }}</p> | ||
|
||
<h3 :id="tool+ '-arguments'">Arguments</h3> | ||
<table> | ||
<tbody> | ||
<tr v-for="(properties, arg) in tool.arguments?.properties" :key="arg"> | ||
<td class="font-semibold">{{ arg }}</td> | ||
<td class="">{{ properties.description }}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<h3 v-if="tool.tools && tool.tools.length" :id="tool.name + 'tools-used'">Tools used</h3> | ||
<div v-if="tool.tools && tool.tools.length"> | ||
<p v-for="(usedTool) in tool.tools" :key="usedTool">{{ usedTool }}</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<Error class="flex flex-col items-center justify-center h-screen" v-else :title="`${error.status}`" :message="error.message"/> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
// todo: this calls the endpoint twice. the first time fails and the second succeeds. | ||
// at the time of writing this comment, I don't know why. This likely has something | ||
// to do with the lifecycle of the component since putting this behind onMounted | ||
// causes there to be no data at all. | ||
import type { Tool } from '@/lib/types'; | ||
import { ref } from "vue"; | ||
import { useRoute, useRouter } from "vue-router"; | ||
const route = useRoute(); | ||
const router = useRouter(); | ||
const owner = ref(""); | ||
const path = ref(""); | ||
const tools = ref([] as Tool[]) | ||
const error = ref({status: 0, message: ''}); | ||
const githubURL = route.path.replace(/^\//, ""); | ||
const validRepo = /^(https?:\/\/)?(www\.)?github\.com\/[\w-]+\/[\w-]+$/.test(githubURL); | ||
[owner.value, path.value] = githubURL.split("/").slice(-2); | ||
if (!validRepo) { | ||
router.push({ path: "/404" }); | ||
} | ||
onMounted(async () => { | ||
document.title = `${owner.value}/${path.value}`; | ||
const toolAPIResponse = await fetch(`/api/github.com/${owner.value}/${path.value}`, { method: 'POST' }); | ||
if (!toolAPIResponse.ok) { | ||
error.value = { status: toolAPIResponse.status, message: toolAPIResponse.statusText }; | ||
return; | ||
} | ||
[owner.value, path.value] = githubURL.split("/").slice(-2); | ||
const toolAPIResponseJSON = await toolAPIResponse.json(); | ||
tools.value = toolAPIResponseJSON as Tool[]; | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters