Skip to content

Commit 87bfb42

Browse files
committed
clean up code
Combine files, shorten code Shorten and cleanup code
1 parent 6f6108c commit 87bfb42

File tree

4 files changed

+113
-224
lines changed

4 files changed

+113
-224
lines changed

src/components/markdown/FocusProblem.tsx

+12-55
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { ExternalLinkIcon } from '@heroicons/react/solid';
2-
import Tippy from '@tippyjs/react';
3-
import { navigate } from 'gatsby';
42
import * as React from 'react';
53
import { Instance } from 'tippy.js';
64
import { useDarkMode } from '../../context/DarkModeContext';
75
import { useMarkdownProblemLists } from '../../context/MarkdownProblemListsContext';
86
import { getProblemURL, ProblemInfo } from '../../models/problem';
9-
import FocusProblemDropdown from './FocusProblemDropdown';
7+
import ProblemsListItemDropdown from './ProblemsList/ProblemsListItemDropdown';
108
import ProblemStatusCheckbox from './ProblemsList/ProblemStatusCheckbox';
119

1210
export default function FocusProblem({
@@ -34,57 +32,6 @@ export default function FocusProblem({
3432
const tippyRef = React.useRef<Instance>();
3533
const [isDropdownShown, setIsDropdownShown] = React.useState(false);
3634

37-
const more = (
38-
<div>
39-
<Tippy
40-
onCreate={tippy => (tippyRef.current = tippy)}
41-
content={
42-
isDropdownShown ? (
43-
<FocusProblemDropdown
44-
onShowSolutionSketch={(problem: ProblemInfo) => {
45-
return problem;
46-
}}
47-
problem={problem}
48-
showTags={true}
49-
showDifficulty={true}
50-
onViewProblemSolutions={() => {
51-
tippyRef.current.hide();
52-
navigate('/problem-solutions/', {
53-
state: {
54-
problem,
55-
},
56-
});
57-
}}
58-
/>
59-
) : (
60-
''
61-
)
62-
}
63-
theme={darkMode ? 'dark' : 'light'}
64-
placement="bottom-end"
65-
arrow={true}
66-
animation="fade"
67-
trigger="click"
68-
interactive={true}
69-
onShow={() => setIsDropdownShown(true)}
70-
onHidden={() => setIsDropdownShown(false)}
71-
>
72-
<button className="focus:outline-none w-8 h-8 inline-flex items-center justify-center text-gray-400 rounded-full bg-transparent hover:text-gray-500 dark:hover:text-gray-300">
73-
{/* Heroicon name: solid/dots-vertical */}
74-
<svg
75-
className="w-5 h-5"
76-
xmlns="http://www.w3.org/2000/svg"
77-
viewBox="0 0 20 20"
78-
fill="currentColor"
79-
aria-hidden="true"
80-
>
81-
<path d="M10 6a2 2 0 110-4 2 2 0 010 4zM10 12a2 2 0 110-4 2 2 0 010 4zM10 18a2 2 0 110-4 2 2 0 010 4z" />
82-
</svg>
83-
</button>
84-
</Tippy>
85-
</div>
86-
);
87-
8835
// transform must go in the isHovered condition
8936
// See https://github.com/thecodingwizard/usaco-guide/issues/198
9037
// transform creates a new stacking context :(
@@ -125,7 +72,17 @@ export default function FocusProblem({
12572
</div>
12673
</div>
12774
<div className="flex-shrink-0 flex items-center justify-center mt-1 sm:mr-2 ml-2">
128-
{more}
75+
<div className="mr-2">
76+
<ProblemsListItemDropdown
77+
onShowSolutionSketch={(problem: ProblemInfo) => {
78+
return problem;
79+
}}
80+
problem={problem}
81+
showTags={true}
82+
showDifficulty={true}
83+
isFocusProblem={true}
84+
/>
85+
</div>
12986
<ProblemStatusCheckbox problem={problem} size="large" />
13087
</div>
13188
</div>

src/components/markdown/FocusProblemDropdown.tsx

-82
This file was deleted.

src/components/markdown/ProblemsList/ProblemsListItem.tsx

+3-49
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Tippy from '@tippyjs/react';
2-
import { navigate } from 'gatsby';
31
import * as React from 'react';
42
import styled, { css } from 'styled-components';
53
import { Instance } from 'tippy.js';
@@ -167,52 +165,6 @@ export default function ProblemsListItem(
167165
const tippyRef = React.useRef<Instance>();
168166
const [isDropdownShown, setIsDropdownShown] = React.useState(false);
169167

170-
const more = (
171-
<div>
172-
<Tippy
173-
onCreate={tippy => (tippyRef.current = tippy)}
174-
content={
175-
isDropdownShown ? (
176-
<ProblemsListItemDropdown
177-
{...props}
178-
onViewProblemSolutions={() => {
179-
tippyRef.current.hide();
180-
navigate('/problem-solutions/', {
181-
state: {
182-
problem,
183-
},
184-
});
185-
}}
186-
/>
187-
) : (
188-
''
189-
)
190-
}
191-
theme={darkMode ? 'dark' : 'light'}
192-
placement="bottom-end"
193-
arrow={true}
194-
animation="fade"
195-
trigger="click"
196-
interactive={true}
197-
onShow={() => setIsDropdownShown(true)}
198-
onHidden={() => setIsDropdownShown(false)}
199-
>
200-
<button className="focus:outline-none w-8 h-8 inline-flex items-center justify-center text-gray-400 rounded-full bg-transparent hover:text-gray-500 dark:hover:text-gray-300">
201-
{/* Heroicon name: solid/dots-vertical */}
202-
<svg
203-
className="w-5 h-5"
204-
xmlns="http://www.w3.org/2000/svg"
205-
viewBox="0 0 20 20"
206-
fill="currentColor"
207-
aria-hidden="true"
208-
>
209-
<path d="M10 6a2 2 0 110-4 2 2 0 010 4zM10 12a2 2 0 110-4 2 2 0 010 4zM10 18a2 2 0 110-4 2 2 0 010 4z" />
210-
</svg>
211-
</button>
212-
</Tippy>
213-
</div>
214-
);
215-
216168
return (
217169
<StyledProblemRow id={id} isActive={isActive}>
218170
{statusCol}
@@ -252,7 +204,9 @@ export default function ProblemsListItem(
252204
)}
253205
</td>
254206
)}
255-
<td className="text-center pr-2 md:pr-3">{more}</td>
207+
<td className="text-center pr-2 md:pr-3">
208+
<ProblemsListItemDropdown {...props} isFocusProblem={false} />
209+
</td>
256210
</StyledProblemRow>
257211
);
258212
}

0 commit comments

Comments
 (0)