a tool for shared writing and social publishing

added migration for votes on entity table

+81 -10
-1
actions/pollActions.ts
··· 16 .from(poll_votes_on_entity) 17 .innerJoin(entities, eq(entities.id, poll_votes_on_entity.poll_entity)) 18 .where(and(inArray(entities.set, entity_sets))); 19 - console.log(polls); 20 return { polls, voter_token }; 21 } 22
··· 16 .from(poll_votes_on_entity) 17 .innerJoin(entities, eq(entities.id, poll_votes_on_entity.poll_entity)) 18 .where(and(inArray(entities.set, entity_sets))); 19 return { polls, voter_token }; 20 } 21
+17 -9
components/Blocks/PollBlock.tsx
··· 25 26 let dataPollOptions = useEntity(props.entityID, "poll/options"); 27 let { data: pollData } = usePollData(); 28 - console.log(pollData); 29 30 let [localPollOptionNames, setLocalPollOptionNames] = useState<{ 31 [k: string]: string; ··· 99 className="place-self-end" 100 onMouseDown={() => { 101 setPollState("voting"); 102 - rep?.mutate.assertFact( 103 - Object.entries(localPollOptionNames).map(([entity, name]) => ({ 104 - entity, 105 - attribute: "poll-option/name", 106 - data: { type: "string", value: name }, 107 - })), 108 ); 109 - // TODO: Currently, the options are updated onChange in thier inputs in PollOption. 110 - // However, they should instead be updated when this save button is clicked! 111 }} 112 > 113 Save <CheckTiny />
··· 25 26 let dataPollOptions = useEntity(props.entityID, "poll/options"); 27 let { data: pollData } = usePollData(); 28 29 let [localPollOptionNames, setLocalPollOptionNames] = useState<{ 30 [k: string]: string; ··· 98 className="place-self-end" 99 onMouseDown={() => { 100 setPollState("voting"); 101 + 102 + // Update the poll option names 103 + // rep?.mutate.assertFact( 104 + // Object.entries(localPollOptionNames).map(([entity, name]) => ({ 105 + // entity, 106 + // attribute: "poll-option/name", 107 + // data: { type: "string", value: name }, 108 + // })), 109 + // ); 110 + 111 + // remove any poll options that have no name 112 + // look through the localPollOptionNames object and remove any options that have no name 113 + let emptyOptions = Object.entries(localPollOptionNames).filter( 114 + ([optionEntity, optionName]) => { 115 + optionName === ""; 116 + }, 117 ); 118 + console.log(emptyOptions); 119 }} 120 > 121 Save <CheckTiny />
+64
supabase/migrations/20250220195709_add_poll_tables.sql
···
··· 1 + create table "public"."poll_votes_on_entity" ( 2 + "id" uuid not null default gen_random_uuid(), 3 + "created_at" timestamp with time zone not null default now(), 4 + "poll_entity" uuid not null, 5 + "option_entity" uuid not null, 6 + "voter_token" uuid not null 7 + ); 8 + 9 + 10 + alter table "public"."poll_votes_on_entity" enable row level security; 11 + 12 + CREATE UNIQUE INDEX poll_votes_on_entity_pkey ON public.poll_votes_on_entity USING btree (id); 13 + 14 + alter table "public"."poll_votes_on_entity" add constraint "poll_votes_on_entity_pkey" PRIMARY KEY using index "poll_votes_on_entity_pkey"; 15 + 16 + 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; 17 + 18 + alter table "public"."poll_votes_on_entity" validate constraint "poll_votes_on_entity_option_entity_fkey"; 19 + 20 + 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; 21 + 22 + alter table "public"."poll_votes_on_entity" validate constraint "poll_votes_on_entity_poll_entity_fkey"; 23 + 24 + grant delete on table "public"."poll_votes_on_entity" to "anon"; 25 + 26 + grant insert on table "public"."poll_votes_on_entity" to "anon"; 27 + 28 + grant references on table "public"."poll_votes_on_entity" to "anon"; 29 + 30 + grant select on table "public"."poll_votes_on_entity" to "anon"; 31 + 32 + grant trigger on table "public"."poll_votes_on_entity" to "anon"; 33 + 34 + grant truncate on table "public"."poll_votes_on_entity" to "anon"; 35 + 36 + grant update on table "public"."poll_votes_on_entity" to "anon"; 37 + 38 + grant delete on table "public"."poll_votes_on_entity" to "authenticated"; 39 + 40 + grant insert on table "public"."poll_votes_on_entity" to "authenticated"; 41 + 42 + grant references on table "public"."poll_votes_on_entity" to "authenticated"; 43 + 44 + grant select on table "public"."poll_votes_on_entity" to "authenticated"; 45 + 46 + grant trigger on table "public"."poll_votes_on_entity" to "authenticated"; 47 + 48 + grant truncate on table "public"."poll_votes_on_entity" to "authenticated"; 49 + 50 + grant update on table "public"."poll_votes_on_entity" to "authenticated"; 51 + 52 + grant delete on table "public"."poll_votes_on_entity" to "service_role"; 53 + 54 + grant insert on table "public"."poll_votes_on_entity" to "service_role"; 55 + 56 + grant references on table "public"."poll_votes_on_entity" to "service_role"; 57 + 58 + grant select on table "public"."poll_votes_on_entity" to "service_role"; 59 + 60 + grant trigger on table "public"."poll_votes_on_entity" to "service_role"; 61 + 62 + grant truncate on table "public"."poll_votes_on_entity" to "service_role"; 63 + 64 + grant update on table "public"."poll_votes_on_entity" to "service_role";