Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/clean urls #104

Merged
merged 13 commits into from
Nov 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export default function LinkField({
const router = useRouter();
const { id } = useParams();

const cleanURL = (url: string): string => {
const match = url.match(/https?:\/\/[^\s]+/);
return match ? match[0].trim() : "";
};

useEffect(() => {
const validLinks = inputFields
.filter((field) => field.isValid)
Expand Down Expand Up @@ -114,31 +119,31 @@ export default function LinkField({
try {
const clipboardText = await navigator.clipboard.readText();
if (clipboardText.trim()) {
const cleanedText = cleanURL(clipboardText);
setInputFields((prevFields) =>
prevFields.map((fieldItem) =>
fieldItem.id === fieldId
? { ...fieldItem, text: clipboardText, isValid: false }
? { ...fieldItem, text: cleanedText, isValid: false }
: fieldItem
)
);

validateLink(fieldId, clipboardText, label);
validateLink(fieldId, cleanedText, label);
}
} catch (error) {
console.error("클립보드에서 텍스트를 읽는 데 실패했습니다:", error);
}
};

const handleInputChange = (fieldId: string, inputValue: string) => {
const cleanedValue = cleanURL(inputValue); // URL 정리
setInputFields((prevFields) =>
prevFields.map((fieldItem) =>
fieldItem.id === fieldId
? { ...fieldItem, text: inputValue, isValid: false, isTyping: true }
? { ...fieldItem, text: cleanedValue, isValid: false, isTyping: true }
: fieldItem
)
);

validateLink(fieldId, inputValue, label);
validateLink(fieldId, cleanedValue, label);
};

const handleFocus = (fieldId: string) => {
Expand Down
12 changes: 10 additions & 2 deletions fe/src/app/event-maps/[id]/load-mappin/forms/links/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export default function LinksPage() {
setIsFormComplete(isComplete);
}, [mapLinks, storeLinks, isChecked, isSubmitting]);

const cleanURL = (url: string): string => {
const match = url.match(/https?:\/\/[^\s]+/);
return match ? match[0].trim() : "";
};

const handleSubmit = async (e?: React.FormEvent) => {
if (e) e.preventDefault();

Expand All @@ -40,12 +45,15 @@ export default function LinksPage() {
return;
}

const cleanedMapLinks = mapLinks.map(cleanURL).filter(Boolean);
const cleanedStoreLinks = storeLinks.map(cleanURL).filter(Boolean);

const requestBody = {
uuid: id,
name,
password: pin,
bookmarkUrls: mapLinks,
storeUrls: storeLinks,
bookmarkUrls: cleanedMapLinks,
storeUrls: cleanedStoreLinks,
};

try {
Expand Down