File size: 1,119 Bytes
7e5cb25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use client"

import { useEffect, useState } from "react"
import { useRouter } from "next/navigation"

export default function SelectModels({ models }) {
  const router = useRouter()
  const [model1, setModel1] = useState("")
  const [model2, setModel2] = useState("")

  useEffect(() => {
    if (model1 && model2) {
      router.push(`/compare/${model1}-vs-${model2}`)
    }
  }, [model1, model2])

  return (
    <div>
      <select onChange={(e) => setModel1(e.target.value)}>
        <option value="">Select model 1</option>
        {models

          .sort((a, b) => b.total_score - a.total_score)
          .map((model, i) => (
            <option key={i} value={model.slug}>
              {model.name}
            </option>
          ))}
      </select>
      <select onChange={(e) => setModel2(e.target.value)}>
        <option value="">Select model 2</option>
        {models

          .sort((a, b) => b.total_score - a.total_score)
          .map((model, i) => (
            <option key={i} value={model.slug}>
              {model.name}
            </option>
          ))}
      </select>
    </div>
  )
}