Skip to content

Commit ab9104f

Browse files
feat: problem ui done
1 parent b305ffb commit ab9104f

File tree

4 files changed

+49
-37
lines changed

4 files changed

+49
-37
lines changed

src/commands/show.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ def show(
3535

3636
if not data.get('data', {}).get('question'):
3737
typer.echo(typer.style(f"❌ Problem '{problem}' not found", fg=typer.colors.RED))
38-
raise typer.Exit(1)
38+
raise typer.Exit(data.get('errors', ['Unknown error']))
3939

4040
question = data.get('data', {}).get('question')
4141
problem_details = ProblemDetails(question)
4242

4343
if save:
4444
_save_problem_to_file(question)
4545

46-
if compact:
47-
problem_details.display()
48-
else:
49-
problem_details.display()
50-
# problem_details.display_full()
46+
problem_details.display_probelm()
47+
48+
if not compact:
49+
problem_details.display_stats()
50+
problem_details.display_additional_info()
5151

5252
except Exception as e:
5353
typer.echo(typer.style(f"❌ Error: {str(e)}", fg=typer.colors.RED))

src/lib/problem_ui.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ def __init__(self, problem_data: dict):
3636
self.difficulty = problem_data['difficulty']
3737
self.stats = problem_data['stats']
3838
self.topics = problem_data.get('topicTags', [])
39-
self.companies = problem_data.get('companyTagStats', {}).get('companies', []) if 'companyTagStats' in problem_data else []
40-
self.similar_questions = json.loads(problem_data.get('similarQuestions', '[]'))
39+
self.similar_questions = problem_data.get('similarQuestionList', [])
4140

4241
if isinstance(self.stats, str):
4342
try:
@@ -92,16 +91,26 @@ def _format_similar_questions(self) -> str:
9291
for q in self.similar_questions[:5]:
9392
title = q.get('title', '')
9493
difficulty = q.get('difficulty', '')
94+
question_id = q.get('questionId', '') or q.get('titleSlug', '')
95+
lock_symbol = " 🔒" if q.get('isPaidOnly', False) else ""
96+
diff_color = COLORS['difficulty'].get(difficulty, 'white')
97+
9598
if title and difficulty:
96-
diff_color = COLORS['difficulty'].get(difficulty, 'white')
97-
lines.append(f"- {title} ([{diff_color}]{difficulty}[/{diff_color}])")
99+
if 'titleSlug' in q:
100+
slug = q.get('titleSlug')
101+
title_display = f"[link=https://leetcode.com/problems/{slug}/]{title}[/link]"
102+
else:
103+
title_display = title
104+
105+
question_line = f"- [{COLORS['problem_number']}]#{question_id}[/] {title_display} {lock_symbol} ([{diff_color}]{difficulty}[/{diff_color}])"
106+
lines.append(question_line)
98107

99108
if len(lines) <= 1:
100109
return ""
101110

102111
return "\n".join(lines)
103112

104-
def display(self):
113+
def display_probelm(self):
105114
formatted_md = self._format_markdown(self.content)
106115

107116
content_panel = Panel(
@@ -114,6 +123,7 @@ def display(self):
114123
)
115124
console.print(content_panel)
116125

126+
def display_stats(self):
117127
stats_panel = Panel(
118128
self._format_stats(),
119129
title=f"[{COLORS['section_title']}]Statistics[/]",
@@ -122,6 +132,8 @@ def display(self):
122132
padding=STYLES['panel_padding']
123133
)
124134
console.print(stats_panel)
135+
136+
def display_additional_info(self):
125137
info_content = []
126138

127139
topics = self._format_topics()
@@ -142,19 +154,4 @@ def display(self):
142154
border_style=COLORS['border'],
143155
padding=STYLES['panel_padding']
144156
)
145-
console.print(info_panel)
146-
147-
def display_full(self):
148-
self.display()
149-
150-
if self.companies:
151-
company_names = [company.get('name', '') for company in self.companies if 'name' in company]
152-
if company_names:
153-
companies_panel = Panel(
154-
Text(", ".join(company_names)),
155-
box=SIMPLE,
156-
title="Companies",
157-
border_style=COLORS['border'],
158-
padding=STYLES['panel_padding']
159-
)
160-
console.print(companies_panel)
157+
console.print(info_panel)

src/server/config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
LEETCODE_BASE_URL = "https://leetcode.com"
33
STATUS_CODES = {
44
10: "Accepted",
5+
11: "Wrong Answer",
6+
12: "Memory Limit Exceeded",
7+
13: "Output Limit Exceeded",
58
14: "Time Limit Exceeded",
69
15: "Runtime Error",
7-
16: "Memory Limit Exceeded",
10+
16: "Internal Error",
811
20: "Compile Error",
9-
11: "Wrong Answer"
12+
30: "Timeout"
1013
}
1114
LANGUAGE_MAP = {
1215
'.py': 'python3',

src/server/solution_manager.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ def get_question_data(self, question_identifier: str) -> Dict[str, Any]:
7373
questionFrontendId
7474
title
7575
titleSlug
76+
topicTags {
77+
name
78+
}
79+
similarQuestionList {
80+
title
81+
titleSlug
82+
difficulty
83+
isPaidOnly
84+
}
7685
content
7786
difficulty
7887
exampleTestcaseList
@@ -88,15 +97,18 @@ def get_question_data(self, question_identifier: str) -> Dict[str, Any]:
8897
}
8998
"""
9099

91-
response = self.session.post(
92-
f"{self.BASE_URL}/graphql",
93-
json={
94-
"query": query,
95-
"variables": {"titleSlug": title_slug}
96-
}
97-
)
100+
try:
101+
response = self.session.post(
102+
f"{self.BASE_URL}/graphql",
103+
json={
104+
"query": query,
105+
"variables": {"titleSlug": title_slug}
106+
}
107+
)
98108

99-
return response.json()
109+
return response.json()
110+
except Exception as e:
111+
return {"error": str(e)}
100112

101113
def _format_output(self, output: Union[str, List, None]) -> str:
102114
"""Format output that could be string or list"""

0 commit comments

Comments
 (0)