@@ -41,25 +41,87 @@ document.addEventListener("DOMContentLoaded", () => {
4141document . addEventListener ( "DOMContentLoaded" , ( ) => {
4242 browser . storage . local . get ( null ) . then ( ( allData ) => {
4343 const problems = Object . values ( allData ) . filter ( p => p . status === "Solved" ) ;
44- const list = document . getElementById ( "solvedList" ) ;
44+ // Sort by solvedAt descending (most recent first)
45+ problems . sort ( ( a , b ) => ( b . solvedAt || 0 ) - ( a . solvedAt || 0 ) ) ;
4546
46- if ( problems . length === 0 ) {
47- list . innerHTML = "<p>No solved problems yet</p>"
47+ // Collect all unique tags (flattened)
48+ const tagSet = new Set ( ) ;
49+ problems . forEach ( p => {
50+ if ( Array . isArray ( p . tags ) ) {
51+ p . tags . forEach ( tag => tagSet . add ( tag ) ) ;
52+ }
53+ } ) ;
54+ const tags = Array . from ( tagSet ) ;
55+
56+ // Populate tag filter dropdown
57+ const tagFilter = document . getElementById ( "tagFilter" ) ;
58+ if ( tagFilter ) {
59+ // Remove old options except 'All'
60+ tagFilter . innerHTML = '<option value="all">All</option>' ;
61+ if ( tags . length > 0 ) {
62+ tags . forEach ( tag => {
63+ const opt = document . createElement ( "option" ) ;
64+ opt . value = tag ;
65+ opt . textContent = tag ;
66+ tagFilter . appendChild ( opt ) ;
67+ } ) ;
68+ } else {
69+ const opt = document . createElement ( "option" ) ;
70+ opt . value = "none" ;
71+ opt . textContent = "No tags" ;
72+ tagFilter . appendChild ( opt ) ;
73+ }
4874 }
4975
50- problems . forEach ( problem => {
51- const item = document . createElement ( "div" ) ;
52- item . className = "problem-item" ;
53- // Add difficulty as a class for color styling
54- const difficultyClass = problem . difficulty ? problem . difficulty . toLowerCase ( ) : "" ;
55- item . innerHTML = `
56- <a href="${ problem . url } " target="_blank">${ problem . title } </a>
57- <span class="difficulty ${ difficultyClass } ">${ problem . difficulty } </span>
58- ` ;
59- list . appendChild ( item ) ;
60- } )
61- } )
62- } )
76+ // Render problems (filtered and limited)
77+ function renderProblems ( ) {
78+ const list = document . getElementById ( "solvedList" ) ;
79+ list . innerHTML = "" ;
80+ let filtered = problems ;
81+ const selectedTag = tagFilter ? tagFilter . value : "all" ;
82+ if ( selectedTag && selectedTag !== "all" && selectedTag !== "none" ) {
83+ filtered = problems . filter ( p => Array . isArray ( p . tags ) && p . tags . includes ( selectedTag ) ) ;
84+ }
85+ const toShow = filtered . slice ( 0 , 5 ) ;
86+ if ( toShow . length === 0 ) {
87+ list . innerHTML = "<p>No solved problems yet</p>" ;
88+ }
89+ toShow . forEach ( problem => {
90+ const item = document . createElement ( "div" ) ;
91+ item . className = "problem-item" ;
92+ const difficultyClass = problem . difficulty ? problem . difficulty . toLowerCase ( ) : "" ;
93+ // Show tags if available
94+ const tagsHtml = Array . isArray ( problem . tags ) && problem . tags . length > 0
95+ ? `<span style='font-size:0.85em; color:#666; margin-left:8px;'>[${ problem . tags . join ( ", " ) } ]</span>`
96+ : "<span style='font-size:0.85em; color:#bbb; margin-left:8px;'>[No tags]</span>" ;
97+ item . innerHTML = `
98+ <a href="${ problem . url } " target="_blank">${ problem . title } </a>
99+ <span class="difficulty ${ difficultyClass } ">${ problem . difficulty } </span>
100+ ${ tagsHtml }
101+ ` ;
102+ list . appendChild ( item ) ;
103+ } ) ;
104+ }
105+
106+ if ( tagFilter ) {
107+ tagFilter . addEventListener ( "change" , renderProblems ) ;
108+ }
109+ renderProblems ( ) ;
110+ } ) ;
111+
112+ // View All link opens options page
113+ const viewAllLink = document . getElementById ( "viewAllLink" ) ;
114+ if ( viewAllLink ) {
115+ viewAllLink . addEventListener ( "click" , ( e ) => {
116+ e . preventDefault ( ) ;
117+ if ( browser . runtime && browser . runtime . openOptionsPage ) {
118+ browser . runtime . openOptionsPage ( ) ;
119+ } else {
120+ window . open ( "../options/options.html" , "_blank" ) ;
121+ }
122+ } ) ;
123+ }
124+ } ) ;
63125
64126document . addEventListener ( "DOMContentLoaded" , ( ) => {
65127 const optionsBtn = document . getElementById ( "optionsBtn" ) ;
0 commit comments