Removed validation
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
"use client"
|
||||
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { validatePlayer } from "@/lib/hypixel/actions"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Search } from "lucide-react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { useState } from "react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
export function SearchBar({ navbar }: { navbar?: boolean }) {
|
||||
const [input, setInput] = useState("")
|
||||
@@ -15,13 +13,13 @@ export function SearchBar({ navbar }: { navbar?: boolean }) {
|
||||
async function handleSearch(e: React.FormEvent) {
|
||||
e.preventDefault()
|
||||
|
||||
const validatedPlayer = await validatePlayer(input.trim())
|
||||
|
||||
if (validatedPlayer.error === true) {
|
||||
toast.error(validatedPlayer.message)
|
||||
setInput("")
|
||||
return
|
||||
}
|
||||
// const validatedPlayer = await validatePlayer(input.trim())
|
||||
//
|
||||
// if (validatedPlayer.error === true) {
|
||||
// toast.error(validatedPlayer.message)
|
||||
// setInput("")
|
||||
// return
|
||||
// }
|
||||
|
||||
if (input.trim()) {
|
||||
router.push(`/player/${encodeURIComponent(input.trim())}`)
|
||||
|
||||
@@ -1,29 +1,7 @@
|
||||
"use server"
|
||||
|
||||
import { getUuid } from "./api/mojang"
|
||||
import { getPlayer } from "./api/player"
|
||||
import { _validatePlayer } from "./server"
|
||||
|
||||
export async function validatePlayer(ign: string) {
|
||||
const uuid = await getUuid(ign)
|
||||
|
||||
if (!uuid) {
|
||||
return {
|
||||
error: true,
|
||||
message: "Player not found"
|
||||
}
|
||||
}
|
||||
|
||||
const player = await getPlayer(uuid)
|
||||
|
||||
if (!player) {
|
||||
return {
|
||||
error: true,
|
||||
message: "Player never logged on to Hypixel"
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
error: false,
|
||||
message: "Player found"
|
||||
}
|
||||
return await _validatePlayer(ign)
|
||||
}
|
||||
|
||||
27
src/lib/hypixel/server.ts
Normal file
27
src/lib/hypixel/server.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { getUuid } from "./api/mojang"
|
||||
import { getPlayer } from "./api/player"
|
||||
|
||||
export async function _validatePlayer(ign: string) {
|
||||
const uuid = await getUuid(ign)
|
||||
|
||||
if (!uuid) {
|
||||
return {
|
||||
error: true,
|
||||
message: "Player not found"
|
||||
}
|
||||
}
|
||||
|
||||
const player = await getPlayer(uuid)
|
||||
|
||||
if (!player) {
|
||||
return {
|
||||
error: true,
|
||||
message: "Player never logged on to Hypixel"
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
error: false,
|
||||
message: "Player found"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user