Removed validation
This commit is contained in:
@@ -1,12 +1,10 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import { validatePlayer } from "@/lib/hypixel/actions"
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import { Search } from "lucide-react"
|
import { Search } from "lucide-react"
|
||||||
import { useRouter } from "next/navigation"
|
import { useRouter } from "next/navigation"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { toast } from "sonner"
|
|
||||||
|
|
||||||
export function SearchBar({ navbar }: { navbar?: boolean }) {
|
export function SearchBar({ navbar }: { navbar?: boolean }) {
|
||||||
const [input, setInput] = useState("")
|
const [input, setInput] = useState("")
|
||||||
@@ -15,13 +13,13 @@ export function SearchBar({ navbar }: { navbar?: boolean }) {
|
|||||||
async function handleSearch(e: React.FormEvent) {
|
async function handleSearch(e: React.FormEvent) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
const validatedPlayer = await validatePlayer(input.trim())
|
// const validatedPlayer = await validatePlayer(input.trim())
|
||||||
|
//
|
||||||
if (validatedPlayer.error === true) {
|
// if (validatedPlayer.error === true) {
|
||||||
toast.error(validatedPlayer.message)
|
// toast.error(validatedPlayer.message)
|
||||||
setInput("")
|
// setInput("")
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (input.trim()) {
|
if (input.trim()) {
|
||||||
router.push(`/player/${encodeURIComponent(input.trim())}`)
|
router.push(`/player/${encodeURIComponent(input.trim())}`)
|
||||||
|
|||||||
@@ -1,29 +1,7 @@
|
|||||||
"use server"
|
"use server"
|
||||||
|
|
||||||
import { getUuid } from "./api/mojang"
|
import { _validatePlayer } from "./server"
|
||||||
import { getPlayer } from "./api/player"
|
|
||||||
|
|
||||||
export async function validatePlayer(ign: string) {
|
export async function validatePlayer(ign: string) {
|
||||||
const uuid = await getUuid(ign)
|
return await _validatePlayer(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"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
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