a tool for shared writing and social publishing
0
fork

Configure Feed

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

fixed bug: focus a new text block if you add a link block

celine 318fb7e7 e1c371eb

+44 -19
+26 -6
components/Blocks/ExternalLinkBlock.tsx
··· 35 35 } else input?.blur(); 36 36 }, [isSelected, props.entityID, props.preview]); 37 37 38 - if (!url) { 38 + if (url === undefined) { 39 39 if (!permissions.write) return null; 40 40 return ( 41 41 <label ··· 115 115 let [linkValue, setLinkValue] = useState(""); 116 116 let { rep } = useReplicache(); 117 117 let submit = async () => { 118 - let entity = props.entityID; 119 - if (!entity) { 120 - entity = v7(); 118 + let linkEntity = props.entityID; 119 + if (!linkEntity) { 120 + linkEntity = v7(); 121 121 122 122 await rep?.mutate.addBlock({ 123 123 permission_set: entity_set.set, ··· 125 125 parent: props.parent, 126 126 type: "card", 127 127 position: generateKeyBetween(props.position, props.nextPosition), 128 - newEntityID: entity, 128 + newEntityID: linkEntity, 129 129 }); 130 130 } 131 131 let link = linkValue; 132 132 if (!linkValue.startsWith("http")) link = `https://${linkValue}`; 133 - addLinkBlock(link, entity, rep); 133 + addLinkBlock(link, linkEntity, rep); 134 + 135 + let textEntity = v7(); 136 + await rep?.mutate.addBlock({ 137 + permission_set: entity_set.set, 138 + factID: v7(), 139 + parent: props.parent, 140 + type: "text", 141 + position: generateKeyBetween(props.position, props.nextPosition), 142 + newEntityID: textEntity, 143 + }); 144 + 145 + focusBlock( 146 + { 147 + value: textEntity, 148 + type: "text", 149 + parent: props.parent, 150 + }, 151 + { type: "start" }, 152 + ); 134 153 }; 135 154 let smoke = useSmoker(); 136 155 ··· 169 188 /> 170 189 <div className="flex items-center gap-3 "> 171 190 <button 191 + autoFocus={false} 172 192 className={`p-1 ${isSelected ? "text-accent-contrast" : "text-border"}`} 173 193 onMouseDown={(e) => { 174 194 e.preventDefault();
+3 -1
src/replicache/index.tsx
··· 160 160 let d = data || fallbackData; 161 161 return Attributes[attribute].cardinality === "many" 162 162 ? (d as CardinalityResult<A>) 163 - : (d[0] as CardinalityResult<A>); 163 + : d.length === 0 && data === null 164 + ? (null as CardinalityResult<A>) 165 + : (d[0] as CardinalityResult<A>); 164 166 } 165 167 166 168 export function useReferenceToEntity<
+15 -12
src/utils/addLinkBlock.ts
··· 12 12 rep?: Replicache<ReplicacheMutators> | null, 13 13 ) { 14 14 if (!rep) return; 15 - await rep.mutate.assertFact({ 16 - entity: entityID, 17 - attribute: "block/type", 18 - data: { type: "block-type-union", value: "link" }, 19 - }); 20 - await rep?.mutate.assertFact({ 21 - entity: entityID, 22 - attribute: "link/url", 23 - data: { 24 - type: "text", 25 - value: url, 15 + 16 + await rep?.mutate.assertFact([ 17 + { 18 + entity: entityID, 19 + attribute: "link/url", 20 + data: { 21 + type: "text", 22 + value: url, 23 + }, 24 + }, 25 + { 26 + entity: entityID, 27 + attribute: "block/type", 28 + data: { type: "block-type-union", value: "link" }, 26 29 }, 27 - }); 30 + ]); 28 31 fetch("/api/link_previews", { 29 32 headers: { "Content-Type": "application/json" }, 30 33 method: "POST",