File tree Expand file tree Collapse file tree
src/components/Elements/UserTags Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { useCallback } from 'react'
12import { TiPlus } from 'react-icons/ti'
23import { Link } from 'react-router-dom'
34import { useUserPreferences } from 'src/stores/preferences'
5+ import { useShallow } from 'zustand/shallow'
46
57export const UserTags = ( ) => {
6- const { userSelectedTags } = useUserPreferences ( )
8+ const { cards, userSelectedTags, cardsSettings, setCardSettings } = useUserPreferences (
9+ useShallow ( ( state ) => ( {
10+ cards : state . cards ,
11+ userSelectedTags : state . userSelectedTags ,
12+ cardsSettings : state . cardsSettings ,
13+ setCardSettings : state . setCardSettings ,
14+ } ) )
15+ )
16+
17+ const onTagClicked = useCallback ( ( tagValue : string ) => {
18+ cards . forEach ( ( card ) => {
19+ setCardSettings ( card . name , {
20+ ...cardsSettings [ card . id ] ,
21+ language : tagValue ,
22+ } )
23+ } )
24+ } , [ ] )
725
826 return (
927 < div className = "tags" >
1028 { userSelectedTags . map ( ( tag , index ) => (
11- < span key = { index } className = "tag" >
29+ < button key = { index } className = "tag tagHoverable" onClick = { ( ) => onTagClicked ( tag . value ) } >
1230 { tag . value }
13- </ span >
31+ </ button >
1432 ) ) }
1533 < Link to = "/settings/topics" className = "tag tagHoverable" aria-label = "Open settings" >
1634 < TiPlus className = "tagIcon" />
You can’t perform that action at this time.
0 commit comments