-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from s1lvax/dev
New patch, CodeWars integration
- Loading branch information
Showing
12 changed files
with
271 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script lang="ts"> | ||
import * as Form from '$lib/components/ui/form'; | ||
import { Input } from '$lib/components/ui/input'; | ||
import { codewarsSchema, type CodewarsSchema } from '$lib/schemas/integration-codewars'; | ||
import { type SuperValidated, type Infer, superForm } from 'sveltekit-superforms'; | ||
import { zodClient } from 'sveltekit-superforms/adapters'; | ||
export let data: SuperValidated<Infer<CodewarsSchema>>; | ||
const form = superForm(data, { | ||
validators: zodClient(codewarsSchema), | ||
resetForm: true | ||
}); | ||
const { form: formData, enhance } = form; | ||
</script> | ||
|
||
<form | ||
method="POST" | ||
use:enhance | ||
action="?/createCodewars" | ||
class="flex items-center justify-between space-x-4" | ||
> | ||
<div class="flex items-start space-x-2"> | ||
<Form.Field {form} name="username"> | ||
<Form.Control let:attrs> | ||
<Form.Label>Username</Form.Label> | ||
<Input {...attrs} bind:value={$formData.username} /> | ||
</Form.Control> | ||
<Form.FieldErrors /> | ||
</Form.Field> | ||
<div class="space-y-2"> | ||
<span class="invisible block">a</span> | ||
<Form.Button>Add</Form.Button> | ||
</div> | ||
</div> | ||
</form> |
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,78 @@ | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
import type { CodewarsStats } from '$lib/types/Codewars'; | ||
import { Award, Medal, Hash, Code, Hammer } from 'lucide-svelte'; | ||
import * as Card from '$lib/components/ui/card'; | ||
import * as Table from '$lib/components/ui/table'; | ||
export let codewarsUsername: string; | ||
let data: CodewarsStats; | ||
let loading = true; | ||
onMount(async () => { | ||
const response = await fetch(`https://www.codewars.com/api/v1/users/${codewarsUsername}`); | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
data = await response.json(); | ||
loading = false; | ||
}); | ||
</script> | ||
|
||
<Card.Root class="max-h-[400px] overflow-y-auto"> | ||
<Card.Header> | ||
<Card.Title>Codewars</Card.Title> | ||
<Card.Description>{codewarsUsername}'s Codewars stats</Card.Description> | ||
</Card.Header> | ||
<Card.Content> | ||
{#if loading} | ||
<p>Loading...</p> | ||
{:else} | ||
<!-- Metrics --> | ||
<h4 class="text-lg font-semibold mb-4">Metrics</h4> | ||
<Table.Root class="w-full"> | ||
<Table.Body> | ||
<Table.Row class="flex items-center space-x-4 mb-2"> | ||
<Award class="text-red-500 w-6 h-6" /> | ||
<Table.Cell class="font-medium">Rank:</Table.Cell> | ||
<Table.Cell class="text-{data.ranks.overall.color}-500">{data.ranks.overall.name}</Table.Cell> | ||
</Table.Row> | ||
<Table.Row class="flex items-center space-x-4 mb-2"> | ||
<Hash class="text-blue-500 w-6 h-6" /> | ||
<Table.Cell class="font-medium">Honor:</Table.Cell> | ||
<Table.Cell>{data.honor}</Table.Cell> | ||
</Table.Row> | ||
<Table.Row class="flex items-center space-x-4"> | ||
<Medal class="text-yellow-500 w-6 h-6" /> | ||
<Table.Cell class="font-medium">Ranking:</Table.Cell> | ||
<Table.Cell>{data.leaderboardPosition}</Table.Cell> | ||
</Table.Row> | ||
<Table.Row class="flex items-center space-x-4"> | ||
<Code class="text-green-500 w-6 h-6" /> | ||
<Table.Cell class="font-medium">Completed:</Table.Cell> | ||
<Table.Cell>{data.codeChallenges.totalCompleted}</Table.Cell> | ||
</Table.Row> | ||
<Table.Row class="flex items-center space-x-4"> | ||
<Hammer class="text-purple-500 w-6 h-6" /> | ||
<Table.Cell class="font-medium">Created:</Table.Cell> | ||
<Table.Cell>{data.codeChallenges.totalAuthored}</Table.Cell> | ||
</Table.Row> | ||
</Table.Body> | ||
</Table.Root> | ||
|
||
<h4 class="text-lg font-semibold mb-4 mt-3">Languages</h4> | ||
<Table.Root class="w-full"> | ||
<Table.Body> | ||
<Table.Row class="flex items-center space-x-4 mb-2"> | ||
{#each Object.keys(data.ranks.languages) as language} | ||
<Table.Cell>{language.charAt(0).toUpperCase() + language.slice(1)}</Table.Cell> | ||
<Table.Cell class="text-{data.ranks.languages[language].color}-500">{data.ranks.languages[language].name}</Table.Cell> | ||
{/each} | ||
</Table.Row> | ||
</Table.Body> | ||
</Table.Root> | ||
{/if} | ||
</Card.Content> | ||
</Card.Root> |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { z } from 'zod'; | ||
|
||
export const codewarsSchema = z.object({ | ||
username: z.string().min(3).max(20) | ||
}); | ||
|
||
export type CodewarsSchema = typeof codewarsSchema; |
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,32 @@ | ||
import { string } from "zod"; | ||
|
||
export type CodewarsStats = { | ||
username: string; | ||
name: string; | ||
honor: number; | ||
clan: string | null; | ||
leaderboardPosition: number; | ||
skills: string[] | null; | ||
|
||
ranks: { | ||
overall: { | ||
rank: number; | ||
name: string; | ||
color: string; | ||
score: number; | ||
}; | ||
languages: { | ||
[key: string]: { | ||
rank: number; | ||
name: string; | ||
color: string; | ||
score: number; | ||
}; | ||
}; | ||
}; | ||
|
||
codeChallenges: { | ||
totalAuthored: number; | ||
totalCompleted: number; | ||
}; | ||
}; |
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
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
Oops, something went wrong.