diff --git a/components/SelectNames.tsx b/components/SelectNames.tsx index 92efae2..abffaa2 100644 --- a/components/SelectNames.tsx +++ b/components/SelectNames.tsx @@ -1,6 +1,5 @@ import React from 'react'; import { useMyVariable } from '../context/MyVariableContext'; -import styles from '../styles/typea.module.css'; import CreatableSelect from 'react-select/creatable'; import { saveNewNames } from '../utils/saveNewNames' diff --git a/utils/saveNewNames.js b/utils/saveNewNames.js index a6f1211..d9eb04d 100644 --- a/utils/saveNewNames.js +++ b/utils/saveNewNames.js @@ -4,32 +4,29 @@ export async function saveNewNames(inputNames) { async function updateNames(inputNames) { let status = 'started'; - // Fetch all existing SubGroups from the database + // Fetch all existing names from the database const { data: existingNames, error: fetchError } = await supabase .from("names") .select("name"); if (fetchError) throw fetchError; - // Convert the existing Namess to a Set for faster lookup + // Convert the existing names to a Set for faster lookup const existingNamesSet = new Set(existingNames.map(item => item.name)); - // Filter out the Namess that already exist + // Filter out the names that already exist const newNames = inputNames.filter(name => !existingNamesSet.has(name)); - // Insert new labels + // Insert new names for (const name of newNames) { - const updates = { - name, - }; + const updates = { name }; const { data, error } = await supabase .from("names") - .upsert(updates) + .upsert(updates, { onConflict: ['name'] }) // Specify conflict target .select('*'); if (error) throw error; - if (!data) { throw new Error("Failed to update the name"); }