Skip to content

Commit

Permalink
refactor: reuse url function
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding committed Dec 10, 2024
1 parent 2b464e4 commit 6cecf28
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ include ':capacitor-reader'
project(':capacitor-reader').projectDir = new File('../node_modules/.pnpm/capacitor-reader@0.2.0_@capacitor+core@6.2.0/node_modules/capacitor-reader/android')

include ':capacitor-stash-media'
project(':capacitor-stash-media').projectDir = new File('../node_modules/.pnpm/capacitor-stash-media@2.0.1_@capacitor+core@6.2.0/node_modules/capacitor-stash-media/android')
project(':capacitor-stash-media').projectDir = new File('../../capacitor-stash-media/android')

include ':capacitor-tips'
project(':capacitor-tips').projectDir = new File('../node_modules/.pnpm/capacitor-tips@1.0.0_@capacitor+core@6.2.0/node_modules/capacitor-tips/android')
15 changes: 4 additions & 11 deletions src/features/post/new/PostEditorRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ export default function PostEditorRoot({
errorMessage = "Please add a title to your post.";
} else if (title.length < 3) {
errorMessage = "Post title must contain at least three characters.";
} else if (postType === "link" && (!url || !validUrl(url))) {
} else if (
postType === "link" &&
(!url || !isValidUrl(url, { allowRelative: false }))
) {
errorMessage =
"Please add a valid URL to your post (start with https://).";
} else if (postType === "photo" && !photoUrl) {
Expand Down Expand Up @@ -527,13 +530,3 @@ export default function PostEditorRoot({
</>
);
}

function validUrl(url: string): boolean {
try {
new URL(url);
} catch (_) {
return false;
}

return true;
}

0 comments on commit 6cecf28

Please sign in to comment.