diff --git a/actions/pollActions.ts b/actions/pollActions.ts index 23c5b0a4..ee53378d 100644 --- a/actions/pollActions.ts +++ b/actions/pollActions.ts @@ -16,7 +16,6 @@ export async function getPollData(entity_sets: string[]) { .from(poll_votes_on_entity) .innerJoin(entities, eq(entities.id, poll_votes_on_entity.poll_entity)) .where(and(inArray(entities.set, entity_sets))); - console.log(polls); return { polls, voter_token }; } diff --git a/components/Blocks/PollBlock.tsx b/components/Blocks/PollBlock.tsx index 2358e5ee..0f376ec3 100644 --- a/components/Blocks/PollBlock.tsx +++ b/components/Blocks/PollBlock.tsx @@ -25,7 +25,6 @@ export const PollBlock = (props: BlockProps) => { let dataPollOptions = useEntity(props.entityID, "poll/options"); let { data: pollData } = usePollData(); - console.log(pollData); let [localPollOptionNames, setLocalPollOptionNames] = useState<{ [k: string]: string; @@ -99,15 +98,24 @@ export const PollBlock = (props: BlockProps) => { className="place-self-end" onMouseDown={() => { setPollState("voting"); - rep?.mutate.assertFact( - Object.entries(localPollOptionNames).map(([entity, name]) => ({ - entity, - attribute: "poll-option/name", - data: { type: "string", value: name }, - })), + + // Update the poll option names + // rep?.mutate.assertFact( + // Object.entries(localPollOptionNames).map(([entity, name]) => ({ + // entity, + // attribute: "poll-option/name", + // data: { type: "string", value: name }, + // })), + // ); + + // remove any poll options that have no name + // look through the localPollOptionNames object and remove any options that have no name + let emptyOptions = Object.entries(localPollOptionNames).filter( + ([optionEntity, optionName]) => { + optionName === ""; + }, ); - // TODO: Currently, the options are updated onChange in thier inputs in PollOption. - // However, they should instead be updated when this save button is clicked! + console.log(emptyOptions); }} > Save diff --git a/supabase/migrations/20250220195709_add_poll_tables.sql b/supabase/migrations/20250220195709_add_poll_tables.sql new file mode 100644 index 00000000..6fbd5313 --- /dev/null +++ b/supabase/migrations/20250220195709_add_poll_tables.sql @@ -0,0 +1,64 @@ +create table "public"."poll_votes_on_entity" ( + "id" uuid not null default gen_random_uuid(), + "created_at" timestamp with time zone not null default now(), + "poll_entity" uuid not null, + "option_entity" uuid not null, + "voter_token" uuid not null +); + + +alter table "public"."poll_votes_on_entity" enable row level security; + +CREATE UNIQUE INDEX poll_votes_on_entity_pkey ON public.poll_votes_on_entity USING btree (id); + +alter table "public"."poll_votes_on_entity" add constraint "poll_votes_on_entity_pkey" PRIMARY KEY using index "poll_votes_on_entity_pkey"; + +alter table "public"."poll_votes_on_entity" add constraint "poll_votes_on_entity_option_entity_fkey" FOREIGN KEY (option_entity) REFERENCES entities(id) ON UPDATE CASCADE ON DELETE CASCADE not valid; + +alter table "public"."poll_votes_on_entity" validate constraint "poll_votes_on_entity_option_entity_fkey"; + +alter table "public"."poll_votes_on_entity" add constraint "poll_votes_on_entity_poll_entity_fkey" FOREIGN KEY (poll_entity) REFERENCES entities(id) ON UPDATE CASCADE ON DELETE CASCADE not valid; + +alter table "public"."poll_votes_on_entity" validate constraint "poll_votes_on_entity_poll_entity_fkey"; + +grant delete on table "public"."poll_votes_on_entity" to "anon"; + +grant insert on table "public"."poll_votes_on_entity" to "anon"; + +grant references on table "public"."poll_votes_on_entity" to "anon"; + +grant select on table "public"."poll_votes_on_entity" to "anon"; + +grant trigger on table "public"."poll_votes_on_entity" to "anon"; + +grant truncate on table "public"."poll_votes_on_entity" to "anon"; + +grant update on table "public"."poll_votes_on_entity" to "anon"; + +grant delete on table "public"."poll_votes_on_entity" to "authenticated"; + +grant insert on table "public"."poll_votes_on_entity" to "authenticated"; + +grant references on table "public"."poll_votes_on_entity" to "authenticated"; + +grant select on table "public"."poll_votes_on_entity" to "authenticated"; + +grant trigger on table "public"."poll_votes_on_entity" to "authenticated"; + +grant truncate on table "public"."poll_votes_on_entity" to "authenticated"; + +grant update on table "public"."poll_votes_on_entity" to "authenticated"; + +grant delete on table "public"."poll_votes_on_entity" to "service_role"; + +grant insert on table "public"."poll_votes_on_entity" to "service_role"; + +grant references on table "public"."poll_votes_on_entity" to "service_role"; + +grant select on table "public"."poll_votes_on_entity" to "service_role"; + +grant trigger on table "public"."poll_votes_on_entity" to "service_role"; + +grant truncate on table "public"."poll_votes_on_entity" to "service_role"; + +grant update on table "public"."poll_votes_on_entity" to "service_role";