Skip to content

Commit 89fa9cc

Browse files
committed
fix/436: add ux combobox open condition
1 parent c012a0a commit 89fa9cc

1 file changed

Lines changed: 28 additions & 11 deletions

File tree

src/app/components/UploadPanel.tsx

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export default function UploadPanel({ onBack }: { onBack: () => void }) {
3737
const [isModalVisible, setModalVisibility] = useState(false);
3838
const [url, setUrl] = useState("");
3939
const [file, setFile] = useState<File | null>(null);
40-
const [source, setSource] = useState<"gitlab" | "other">("other");
40+
const [comboboxOpen, setComboboxOpen] = useState(false);
41+
const [source, setSource] = useState<"gitlab" | "other">(null!);
4142
const [submitType, setSubmitType] = useState<"file" | "url" | undefined>(
4243
undefined
4344
);
@@ -100,17 +101,33 @@ export default function UploadPanel({ onBack }: { onBack: () => void }) {
100101
const { value } = event.target;
101102
setUrl(value);
102103

103-
// Automatically select gitlab source if URL contains gitlab.com
104-
if (value.includes('gitlab.com')) {
105-
setSource('gitlab');
104+
// Automatically select gitlab source if URL host is gitlab.com
105+
try {
106+
const parsedUrl = new URL(value);
107+
108+
if (parsedUrl.host === 'gitlab.com') {
109+
setSource('gitlab');
110+
}
111+
112+
if (parsedUrl.host === 'github.com') {
113+
setSource('other');
114+
}
115+
116+
if (parsedUrl.host !== 'gitlab.com' && parsedUrl.host !== 'github.com') {
117+
setComboboxOpen(true);
118+
}
119+
} catch (error) {
120+
console.error('Invalid URL:', error);
106121
}
107122
};
108123

109-
const handleSourceChange = (selectedValue: string | { value: string; text: string } | null) => {
110-
if (selectedValue && typeof selectedValue === 'object') {
124+
const handleSourceChange = (
125+
selectedValue: string | { value: string; text: string } | null
126+
) => {
127+
if (selectedValue && typeof selectedValue === "object") {
111128
setSource(selectedValue.value as "gitlab" | "other");
112-
} else if (typeof selectedValue === 'string') {
113-
const option = sourceOptions.find(opt => opt.value === selectedValue);
129+
} else if (typeof selectedValue === "string") {
130+
const option = sourceOptions.find((opt) => opt.value === selectedValue);
114131
if (option) {
115132
setSource(option.value as "gitlab" | "other");
116133
}
@@ -181,17 +198,17 @@ export default function UploadPanel({ onBack }: { onBack: () => void }) {
181198
<Row>
182199
<p className="text-dark">{t("editor.pastefile")}</p>
183200
</Row>
184-
<Row className="my-4">
201+
{comboboxOpen && (<Row className="my-4">
185202
<p className="text-dark mb-2">{t("editor.source")}</p>
186203
<Combobox
187204
data={sourceOptions}
188-
value={sourceOptions.find(opt => opt.value === source)}
205+
value={sourceOptions.find((opt) => opt.value === source)}
189206
onChange={handleSourceChange}
190207
textField="text"
191208
className="w-100"
192209
placeholder={t("editor.selectSource")}
193210
/>
194-
</Row>
211+
</Row>)}
195212
<Row>
196213
<InputGroup>
197214
<input

0 commit comments

Comments
 (0)