this repo has no description
0
fork

Configure Feed

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

MVP-ish add/remove featured tags

+83
+83
src/pages/hashtag.jsx
··· 140 140 141 141 const reachLimit = hashtags.length >= TOTAL_TAGS_LIMIT; 142 142 143 + const [featuredUIState, setFeaturedUIState] = useState('default'); 144 + const [featuredTags, setFeaturedTags] = useState([]); 145 + const [isFeaturedTag, setIsFeaturedTag] = useState(false); 146 + useEffect(() => { 147 + if (!authenticated) return; 148 + (async () => { 149 + try { 150 + const featuredTags = await masto.v1.featuredTags.list(); 151 + setFeaturedTags(featuredTags); 152 + setIsFeaturedTag( 153 + featuredTags.some( 154 + (tag) => tag.name.toLowerCase() === hashtag.toLowerCase(), 155 + ), 156 + ); 157 + } catch (e) { 158 + console.error(e); 159 + } 160 + })(); 161 + }, []); 162 + 143 163 return ( 144 164 <Timeline 145 165 key={instance + hashtagTitle} ··· 233 253 </> 234 254 )} 235 255 </MenuConfirm> 256 + <MenuItem 257 + type="checkbox" 258 + checked={isFeaturedTag} 259 + disabled={featuredUIState === 'loading' || !authenticated} 260 + onClick={() => { 261 + setFeaturedUIState('loading'); 262 + if (isFeaturedTag) { 263 + const featuredTagID = featuredTags.find( 264 + (tag) => tag.name.toLowerCase() === hashtag.toLowerCase(), 265 + ).id; 266 + if (featuredTagID) { 267 + masto.v1.featuredTags 268 + .$select(featuredTagID) 269 + .remove() 270 + .then(() => { 271 + setIsFeaturedTag(false); 272 + showToast('Unfeatured on profile'); 273 + setFeaturedTags( 274 + featuredTags.filter( 275 + (tag) => tag.id !== featuredTagID, 276 + ), 277 + ); 278 + }) 279 + .catch((e) => { 280 + console.error(e); 281 + }) 282 + .finally(() => { 283 + setFeaturedUIState('default'); 284 + }); 285 + } else { 286 + showToast('Unable to unfeature on profile'); 287 + } 288 + } else { 289 + masto.v1.featuredTags 290 + .create({ 291 + name: hashtag, 292 + }) 293 + .then((value) => { 294 + setIsFeaturedTag(true); 295 + showToast('Featured on profile'); 296 + setFeaturedTags(featuredTags.concat(value)); 297 + }) 298 + .catch((e) => { 299 + console.error(e); 300 + }) 301 + .finally(() => { 302 + setFeaturedUIState('default'); 303 + }); 304 + } 305 + }} 306 + > 307 + {isFeaturedTag ? ( 308 + <> 309 + <Icon icon="check-circle" /> 310 + <span>Featured on profile</span> 311 + </> 312 + ) : ( 313 + <> 314 + <Icon icon="check-circle" /> 315 + <span>Feature on profile</span> 316 + </> 317 + )} 318 + </MenuItem> 236 319 <MenuDivider /> 237 320 </> 238 321 )}