@@ -1304,7 +1304,12 @@ export class CodeSnippetDisplay extends React.Component<
13041304 return null ;
13051305 }
13061306
1307- filterSnippets = ( searchValue : string , filterTags : string [ ] ) : void => {
1307+ filterSnippets = (
1308+ searchValue : string ,
1309+ filterTags : string [ ] ,
1310+ selectedLangTags : string [ ]
1311+ ) : void => {
1312+ // TODO: when language tag is selected, only display tags that have that tag AND the snippet tags selected.
13081313 // filter with search
13091314 let matchIndices : number [ ] [ ] = [ ] ;
13101315 const matchResults : StringExt . IMatchResult [ ] = [ ] ;
@@ -1351,12 +1356,34 @@ export class CodeSnippetDisplay extends React.Component<
13511356 const newMatchIndices = matchIndices . slice ( ) ;
13521357 filteredSnippets = filteredSnippets . filter ( ( codeSnippet , id ) => {
13531358 return filterTags . some ( ( tag ) => {
1359+ // check if filterTags has a language tag or pass in selectedLang tags
1360+ // then check if codeSnippet.language matches that lang. If it matches then
1361+ // filter by the rest of the selected snippet tags.
13541362 if ( codeSnippet . tags ) {
1355- if (
1356- codeSnippet . tags . includes ( tag ) ||
1357- codeSnippet . language === tag
1358- ) {
1359- return true ;
1363+ if ( selectedLangTags . length !== 0 ) {
1364+ // lang tags selected
1365+ console . log ( selectedLangTags ) ;
1366+ if (
1367+ codeSnippet . tags . includes ( tag ) &&
1368+ selectedLangTags . includes ( codeSnippet . language )
1369+ ) {
1370+ return true ;
1371+ } else if (
1372+ filterTags . length === selectedLangTags . length &&
1373+ filterTags . every ( ( value ) => selectedLangTags . includes ( value ) )
1374+ ) {
1375+ //if only language tags are selected
1376+ console . log ( 'hi' ) ;
1377+ if ( selectedLangTags . includes ( codeSnippet . language ) ) {
1378+ return true ;
1379+ }
1380+ }
1381+ } else {
1382+ // no lang tags selected
1383+ console . log ( 'reached' ) ;
1384+ if ( codeSnippet . tags . includes ( tag ) ) {
1385+ return true ;
1386+ }
13601387 }
13611388 }
13621389 // if the snippet does not have the tag, remove its mathed index
0 commit comments