a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

persit votes when changing, make removing option instant,

+34 -8
+19 -5
components/Blocks/PollBlock.tsx
··· 112 112 }; 113 113 114 114 const PollVote = (props: { entityID: string; onSubmit: () => void }) => { 115 + let { data, mutate } = usePollData(); 115 116 let pollOptions = useEntity(props.entityID, "poll/options"); 116 - let [selectedPollOptions, setSelectedPollOptions] = useState<string[]>([]); 117 - let { mutate } = usePollData(); 117 + let currentVotes = data?.voter_token 118 + ? data.polls 119 + .filter( 120 + (p) => 121 + p.poll_votes_on_entity.poll_entity === props.entityID && 122 + p.poll_votes_on_entity.voter_token === data.voter_token, 123 + ) 124 + .map((v) => v.poll_votes_on_entity.option_entity) 125 + : []; 126 + let [selectedPollOptions, setSelectedPollOptions] = 127 + useState<string[]>(currentVotes); 118 128 119 129 return ( 120 130 <> ··· 161 171 }); 162 172 props.onSubmit(); 163 173 }} 164 - disabled={selectedPollOptions.length === 0} 174 + disabled={ 175 + selectedPollOptions.length === 0 || 176 + (selectedPollOptions.length === currentVotes.length && 177 + selectedPollOptions.every((s) => currentVotes.includes(s))) 178 + } 165 179 > 166 180 Vote! 167 181 </ButtonPrimary> ··· 419 433 <button 420 434 disabled={props.disabled} 421 435 className="text-accent-contrast disabled:text-border" 422 - onMouseDown={() => { 423 - rep?.mutate.removePollOption({ optionEntity: props.entityID }); 436 + onMouseDown={async () => { 437 + await rep?.mutate.removePollOption({ optionEntity: props.entityID }); 424 438 }} 425 439 > 426 440 <CloseTiny />
+13 -2
src/replicache/index.tsx
··· 172 172 }, 173 173 ); 174 174 let d = data || fallbackData; 175 - return Attributes[attribute].cardinality === "many" 176 - ? (d as CardinalityResult<A>) 175 + let a = Attributes[attribute]; 176 + return a.cardinality === "many" 177 + ? ((a.type === "ordered-reference" 178 + ? d.sort((a, b) => { 179 + return ( 180 + a as Fact<keyof FilterAttributes<{ type: "ordered-reference" }>> 181 + ).data.position > 182 + (b as Fact<keyof FilterAttributes<{ type: "ordered-reference" }>>) 183 + .data.position 184 + ? 1 185 + : -1; 186 + }) 187 + : d) as CardinalityResult<A>) 177 188 : d.length === 0 && data === null 178 189 ? (null as CardinalityResult<A>) 179 190 : (d[0] as CardinalityResult<A>);
+1 -1
src/replicache/mutations.ts
··· 594 594 const removePollOption: Mutation<{ 595 595 optionEntity: string; 596 596 }> = async (args, ctx) => { 597 - ctx.deleteEntity(args.optionEntity); 597 + await ctx.deleteEntity(args.optionEntity); 598 598 }; 599 599 600 600 export const mutations = {
+1
src/utils/elementId.ts
··· 3 3 text: `block/${id}/content`, 4 4 container: `block/${id}/container`, 5 5 input: `block/${id}/input`, 6 + pollInput: (entity: string) => `block/${id}/poll-input/${entity}`, 6 7 }), 7 8 page: (id: string) => ({ 8 9 container: `page/${id}/container`,