Skip to content

Commit

Permalink
feat: make get color name an action instead of api
Browse files Browse the repository at this point in the history
  • Loading branch information
fluid-design-io committed Jun 24, 2024
1 parent 6e0c29c commit cd14dbf
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions apps/web/app/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
"use server";
import { cookies } from "next/headers";
export const handleToggleReadability = async (value: string) => {
await cookies().set("showReadability", value);
};
'use server'

import colorNameList from '@/lib/converted_colors.json'
import { ColorNames } from '@/types/app'
import { differenceEuclidean, nearest } from 'culori'

interface ColorNameListWithIndex {
[key: string]: string
}

const indexedColorNameList: ColorNameListWithIndex = colorNameList

export const getColorNames = async (colors: ColorNames) => {
const colorKeys = Object.keys(indexedColorNameList)
const nearestNamedColors = nearest(colorKeys, differenceEuclidean(), (name) => indexedColorNameList[name])
let names = colors.map((color) => {
const name = nearestNamedColors(color, 1)
return name?.[0]
})
return names
}

0 comments on commit cd14dbf

Please sign in to comment.