-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Regex implementation for Seed Request (#71)
- Loading branch information
1 parent
6efc3c7
commit e287fb3
Showing
12 changed files
with
225 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import Swal from "sweetalert2"; | ||
|
||
export function requestCoordinate() { | ||
const apiUrl = import.meta.env.VITE_API_URL; | ||
// Lets pop up a swal to ask for the seed name and then send it to the backend | ||
Swal.fire({ | ||
title: "Request a seed thats not found in the database yet", | ||
input: "text", | ||
inputLabel: "Coordinate:", | ||
inputPlaceholder: "Enter the Coordinate here...", | ||
showCancelButton: true, | ||
confirmButtonText: "Request", | ||
showLoaderOnConfirm: true, | ||
inputValidator: (coordinate) => validateCoordinate(coordinate), | ||
preConfirm: (coordinates) => { | ||
return fetch(`${apiUrl}/coordinates/request/` + coordinates, { | ||
method: "GET", | ||
headers: { | ||
Authorization: `Bearer ${useUserStore().token}`, | ||
}, | ||
}) | ||
.then((response) => { | ||
return response.json(); | ||
}) | ||
.then((data) => { | ||
if (data.error) { | ||
throw new Error(data.error); | ||
} | ||
return data; | ||
}) | ||
|
||
.catch((error) => { | ||
Swal.showValidationMessage(`${error}`); | ||
}); | ||
}, | ||
allowOutsideClick: () => !Swal.isLoading(), | ||
}).then((result) => { | ||
if (result.isConfirmed) { | ||
Swal.fire({ | ||
title: "Seed Requested", | ||
text: result.value.message, | ||
icon: "success", | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
export function validateCoordinate(coordinate) { | ||
const coordinateValidationRegex = RegExp( | ||
/(^(SNDST-A|CER-A|CERS-A|OCAN-A|S-FRZ|LUSH-A|FRST-A|VOLCA|BAD-A|HTFST-A|OASIS-A|V-SNDST-C|V-CER-C|V-CERS-C|V-OCAN-C|V-SWMP-C|V-SFRZ-C|V-LUSH-C|V-FRST-C|V-VOLCA-C|V-BAD-C|V-HTFST-C|V-OASIS-C|SNDST-C|CER-C|FRST-C|SWMP-C|M-SWMP-C|M-BAD-C|M-FRZ-C|M-FLIP-C|M-RAD-C)-\d+-[^-]*-[^-]*-[^-]*)/gm | ||
); | ||
return new Promise((resolve) => { | ||
console.log(coordinate); | ||
let coordinateValid = coordinateValidationRegex.test(coordinate); | ||
if (!coordinateValid) { | ||
resolve("Not a valid Coordinate!"); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
7 changes: 7 additions & 0 deletions
7
frontend/src/content/en/components/coordinate_request_dialog.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default { | ||
request_coordinate_title: "Request Coordinate", | ||
request_coordinate_text: "Request a Coordinage thats not in the database yet", | ||
request_coordinate_invalid_syntax: "Not a valid Coordinate!", | ||
request_coordinate_already_in_db: "Coordinate is already in database!", | ||
request_coordinate_view_seed: "View in Map Explorer", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
export default { | ||
"title": "MapsNotIncluded", | ||
"map_explorer_link": "Map Explorer", | ||
"world_trait_finder_link": "World Trait Finder", | ||
"starmap_link": "StarMap Generator", | ||
"contribute_link": "Contribute", | ||
"discord_link": "Discord", | ||
"github_link": "GitHub", | ||
} | ||
title: "MapsNotIncluded", | ||
map_explorer_link: "Map Explorer", | ||
world_trait_finder_link: "World Trait Finder", | ||
seed_viewer_link: "Seed Viewer", | ||
starmap_link: "StarMap Generator", | ||
contribute_link: "Contribute", | ||
discord_link: "Discord", | ||
github_link: "GitHub", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.