Skip to content

Commit 053fdf3

Browse files
committed
support adding arbitrary path
1 parent e33e052 commit 053fdf3

File tree

7 files changed

+40
-38
lines changed

7 files changed

+40
-38
lines changed

src/components/Editor/AddProblemModal.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ async function addProblem(
3131
difficulty: 'N/A',
3232
isStarred: false,
3333
tags: ['Add Tags'],
34-
solutionMetadata: parsed.solutionMetadata,
34+
solutionMetadata: { kind: 'internal' },
3535
};
3636
console.log(metadata);
3737
setMetadata(
38-
await prettier.format(JSON.stringify(metadata), {
38+
await prettier.format(JSON.stringify(metadata, null, 2), {
3939
parser: 'json',
4040
plugins: [babelParser],
4141
})

src/components/Editor/EditorFileModalInterface.tsx

+38-20
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ const FileSearch = ({
5050
}) => {
5151
const { query, refine: setQuery } = useSearchBox();
5252
const { hits } = useHits() as { hits: AlgoliaEditorFileHit[] };
53+
console.log(hits.map(hit => hit.__position));
54+
if (!hits.find(hit => hit.id === 'none')) {
55+
hits.push({ id: 'none' } as AlgoliaEditorFileHit); // blank hit
56+
}
5357
return (
5458
<div>
5559
<div className="flex items-center p-2">
@@ -70,26 +74,40 @@ const FileSearch = ({
7074
<div>
7175
<SearchResultsContainer>
7276
<div className="max-h-[20rem] overflow-y-auto border-t divide-y divide-gray-200 border-gray-200 dark:divide-gray-700 dark:border-gray-700">
73-
{hits.map(hit => (
74-
<button
75-
className="block hover:bg-blue-100 dark:hover:bg-gray-700 py-3 px-5 transition focus:outline-none w-full text-left"
76-
key={hit.id}
77-
onClick={() => onSelect(hit)}
78-
>
79-
<h3 className="text-gray-600 dark:text-gray-200 font-medium">
80-
<Highlight hit={hit} attribute="title" /> (
81-
{hit.kind === 'module' ? 'Module' : 'Solution'})
82-
</h3>
83-
<SearchResultDescription className="text-gray-700 dark:text-gray-400 text-sm">
84-
<Highlight hit={hit} attribute="id" /> -{' '}
85-
{hit.path == null ? (
86-
'Create New Internal Solution'
87-
) : (
88-
<Highlight hit={hit} attribute="path" />
89-
)}
90-
</SearchResultDescription>
91-
</button>
92-
))}
77+
{hits.length
78+
? hits.map(hit => (
79+
<button
80+
className="block hover:bg-blue-100 dark:hover:bg-gray-700 py-3 px-5 transition focus:outline-none w-full text-left"
81+
key={hit.id}
82+
onClick={() => {
83+
let trueHit = hit;
84+
if (hit.id === 'none') {
85+
trueHit = {
86+
path: prompt('path?'),
87+
} as AlgoliaEditorFileHit;
88+
}
89+
if (trueHit.path) onSelect(trueHit);
90+
}}
91+
>
92+
<h3 className="text-gray-600 dark:text-gray-200 font-medium">
93+
{hit.title ? (
94+
<Highlight hit={hit} attribute="title" />
95+
) : (
96+
'Add New Problem'
97+
)}{' '}
98+
({hit.kind === 'module' ? 'Module' : 'Solution'})
99+
</h3>
100+
<SearchResultDescription className="text-gray-700 dark:text-gray-400 text-sm">
101+
<Highlight hit={hit} attribute="id" /> -{' '}
102+
{hit.path == null ? (
103+
'Create New Internal Solution'
104+
) : (
105+
<Highlight hit={hit} attribute="path" />
106+
)}
107+
</SearchResultDescription>
108+
</button>
109+
))
110+
: 'test'}
93111
</div>
94112
<div className="px-5 py-3 border-t border-gray-200 dark:border-gray-700">
95113
<PoweredBy theme="dark" />

src/components/Editor/EditorSidebar/FileListSidebar.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ export const FileListSidebar: React.FC<{
1414
onNewFile: (file: AlgoliaEditorFile) => void;
1515
token: string;
1616
}> = ({
17-
className,
1817
files,
1918
activeFile,
2019
onOpenFile,
2120
onCloseFile,
2221
onCloseAllFiles,
2322
onNewFile,
24-
token,
2523
}) => {
2624
const [isFileModalOpen, setIsFileModalOpen] = useState(false);
2725
const handleFileSelect = (file: AlgoliaEditorFile) => {

src/components/Editor/parsers/ac.ts

-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,5 @@ export default function parseAc(url: string, html: string) {
77
uniqueId,
88
name,
99
source: 'AC',
10-
solutionMetadata: {
11-
kind: 'CHANGE THIS',
12-
},
1310
};
1411
}

src/components/Editor/parsers/cf.ts

-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,5 @@ export default function parseCf(url: string, html: string) {
1010
uniqueId: `cf${url.includes('gym') ? 'gym' : ''}-${contestId}${problemId}`, // e.g. cf-1917D
1111
name: html.match(titleRegex)?.[1] ?? 'Unknown',
1212
source: 'CF',
13-
solutionMetadata: {
14-
kind: 'autogen-label-from-site',
15-
site: 'CF',
16-
},
1713
};
1814
}

src/components/Editor/parsers/cses.ts

-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,5 @@ export default function parseCses(url: string, html: string) {
77
uniqueId: `cses-${problemId}`, // e.g. cses-1083
88
name: html.match(titleRegex)?.[1] ?? 'Unknown',
99
source: 'CSES',
10-
solutionMetadata: {
11-
kind: 'CHANGE THIS',
12-
},
1310
};
1411
}

src/components/Editor/parsers/usaco.ts

-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,5 @@ export default function parseUsaco(url: string, htmlContent: string) {
1414
uniqueId: `usaco-${id}`,
1515
name: title,
1616
source: division,
17-
solutionMetadata: {
18-
kind: 'USACO',
19-
usacoId: +id,
20-
},
2117
};
2218
}

0 commit comments

Comments
 (0)