From e287fb31daa396eadaa30323cd25d222c239a7b1 Mon Sep 17 00:00:00 2001 From: SGT_Imalas Date: Thu, 7 Nov 2024 23:43:22 +0100 Subject: [PATCH] Regex implementation for Seed Request (#71) --- .../src/components/CoordinateRequestDialog.js | 61 ++++++ frontend/src/components/Navbar.vue | 184 ++++++++---------- frontend/src/components/SeedVerification.js | 0 .../components/coordinate_request_dialog.js | 7 + frontend/src/content/en/components/navbar.js | 17 +- frontend/src/content/en/index.js | 24 +-- frontend/src/content/en/view/home.js | 26 +-- frontend/src/content/en/view/seed_viewer.js | 4 +- .../components/coordinate_request_dialog.js | 7 + .../components/coordinate_request_dialog.js | 7 + frontend/src/main.js | 29 ++- frontend/src/views/SeedViewerView.vue | 21 +- 12 files changed, 225 insertions(+), 162 deletions(-) create mode 100644 frontend/src/components/CoordinateRequestDialog.js create mode 100644 frontend/src/components/SeedVerification.js create mode 100644 frontend/src/content/en/components/coordinate_request_dialog.js create mode 100644 frontend/src/content/zh-CN/components/coordinate_request_dialog.js create mode 100644 frontend/src/content/zh-TW/components/coordinate_request_dialog.js diff --git a/frontend/src/components/CoordinateRequestDialog.js b/frontend/src/components/CoordinateRequestDialog.js new file mode 100644 index 0000000..29dd5e8 --- /dev/null +++ b/frontend/src/components/CoordinateRequestDialog.js @@ -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(); + } + }); +} diff --git a/frontend/src/components/Navbar.vue b/frontend/src/components/Navbar.vue index 736d3ee..9826dc9 100644 --- a/frontend/src/components/Navbar.vue +++ b/frontend/src/components/Navbar.vue @@ -1,44 +1,59 @@ \ No newline at end of file + diff --git a/frontend/src/components/SeedVerification.js b/frontend/src/components/SeedVerification.js new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/content/en/components/coordinate_request_dialog.js b/frontend/src/content/en/components/coordinate_request_dialog.js new file mode 100644 index 0000000..cda1b97 --- /dev/null +++ b/frontend/src/content/en/components/coordinate_request_dialog.js @@ -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", +}; diff --git a/frontend/src/content/en/components/navbar.js b/frontend/src/content/en/components/navbar.js index 9c1908d..1d23885 100644 --- a/frontend/src/content/en/components/navbar.js +++ b/frontend/src/content/en/components/navbar.js @@ -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", -} \ No newline at end of file + 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", +}; diff --git a/frontend/src/content/en/index.js b/frontend/src/content/en/index.js index 5426a23..c00d787 100644 --- a/frontend/src/content/en/index.js +++ b/frontend/src/content/en/index.js @@ -1,13 +1,14 @@ -import notFound from './view/not_found.js' -import about from './view/about.js' -import contribute from './view/contribute.js' -import home from './view/home.js' -import mapExplorerSteps from './view/map_explorer_steps.js' -import mapExplorer from './view/map_explorer.js' -import worldTraitFinder from './view/world_trait_finder.js' -import seedViewer from './view/seed_viewer.js' -import starmapGenerator from './view/starmap_generator.js' -import navbar from './components/navbar.js' +import notFound from "./view/not_found.js"; +import about from "./view/about.js"; +import contribute from "./view/contribute.js"; +import home from "./view/home.js"; +import mapExplorerSteps from "./view/map_explorer_steps.js"; +import mapExplorer from "./view/map_explorer.js"; +import worldTraitFinder from "./view/world_trait_finder.js"; +import seedViewer from "./view/seed_viewer.js"; +import starmapGenerator from "./view/starmap_generator.js"; +import navbar from "./components/navbar.js"; +import coordinateRequestDialog from "./components/coordinate_request_dialog.js"; export default { navbar: navbar, @@ -20,4 +21,5 @@ export default { map_explorer: mapExplorer, world_trait_finder: worldTraitFinder, starmap_generator: starmapGenerator, -} \ No newline at end of file + coordinate_request_dialog: coordinateRequestDialog, +}; diff --git a/frontend/src/content/en/view/home.js b/frontend/src/content/en/view/home.js index 8d463a2..3506f83 100644 --- a/frontend/src/content/en/view/home.js +++ b/frontend/src/content/en/view/home.js @@ -1,13 +1,15 @@ export default { - "title": "Welcome to MapsNotIncluded!", - "description_1": "This website is currently a work in progress, and will eventually contain a variety of tools and resources for Oxygen Not Included. Our map explorer is already live, and with your contributions, we'll be adding even more useful features soon.", - "description_2": "Want to get involved? Head over to our {contributeLink} page. You can also join our community on {discordLink} or submit issues and pull requests via {githubLink}!", - "link_map_explorer": "Map Explorer", - "link_trait_finder": "World Trait Finder", - "link_starmap_generator": "Star Map Generator", - "link": { - "contribute": "Contribute", - "discord": "Discord", - "github": "GitHub", - } -} \ No newline at end of file + title: "Welcome to MapsNotIncluded!", + description_1: + "This website is currently a work in progress, and will eventually contain a variety of tools and resources for Oxygen Not Included. Our map explorer is already live, and with your contributions, we'll be adding even more useful features soon.", + description_2: + "Want to get involved? Head over to our {contributeLink} page. You can also join our community on {discordLink} or submit issues and pull requests via {githubLink}!", + link_map_explorer: "Map Explorer", + link_trait_finder: "World Trait Finder", + link_starmap_generator: "Star Map Generator", + link: { + contribute: "Contribute", + discord: "Discord", + github: "GitHub", + }, +}; diff --git a/frontend/src/content/en/view/seed_viewer.js b/frontend/src/content/en/view/seed_viewer.js index 7acecbe..9321bb8 100644 --- a/frontend/src/content/en/view/seed_viewer.js +++ b/frontend/src/content/en/view/seed_viewer.js @@ -1,6 +1,6 @@ export default { - "title": "Seed Explorer", - "description_1": "Input a seed, and see whether our database has it and you can explore the map!", + "title": "Seed Viewer", + "description_1": "Input a seed to view to explore its map generation. If its not in our database yet, you can request it when logged in.", "description_2": "THIS IS NOT WORKING YET!!!", "seed": "Seed", "submit": "Submit", diff --git a/frontend/src/content/zh-CN/components/coordinate_request_dialog.js b/frontend/src/content/zh-CN/components/coordinate_request_dialog.js new file mode 100644 index 0000000..04dcdcc --- /dev/null +++ b/frontend/src/content/zh-CN/components/coordinate_request_dialog.js @@ -0,0 +1,7 @@ +export default { + request_coordinate_title: "Request new Seed", + request_coordinate_text: "Request a seed thats not in the database yet", + request_coordinate_invalid_syntax: "Not a valid seed!", + request_coordinate_already_in_db: "Seed is already in database!", + request_coordinate_view_seed: "View in Map Explorer", +}; diff --git a/frontend/src/content/zh-TW/components/coordinate_request_dialog.js b/frontend/src/content/zh-TW/components/coordinate_request_dialog.js new file mode 100644 index 0000000..04dcdcc --- /dev/null +++ b/frontend/src/content/zh-TW/components/coordinate_request_dialog.js @@ -0,0 +1,7 @@ +export default { + request_coordinate_title: "Request new Seed", + request_coordinate_text: "Request a seed thats not in the database yet", + request_coordinate_invalid_syntax: "Not a valid seed!", + request_coordinate_already_in_db: "Seed is already in database!", + request_coordinate_view_seed: "View in Map Explorer", +}; diff --git a/frontend/src/main.js b/frontend/src/main.js index 5882d2d..944f362 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -1,24 +1,21 @@ -import { createApp } from 'vue' -import { createPinia } from 'pinia' +import { createApp } from "vue"; +import { createPinia } from "pinia"; -import './assets/variables.scss' -import './assets/custom.css' -import 'bootstrap/scss/bootstrap.scss' -import 'bootstrap/dist/js/bootstrap.min.js' +import "./assets/variables.scss"; +import "./assets/custom.css"; +import "bootstrap/scss/bootstrap.scss"; +import "bootstrap/dist/js/bootstrap.min.js"; -import 'bootstrap-icons/font/bootstrap-icons.css' +import "bootstrap-icons/font/bootstrap-icons.css"; -import App from './App.vue' -import router from './router' -import { createI18n } from 'vue-i18n'; -import { i18nConfig, localeLabels } from './content/index'; +import App from "./App.vue"; +import router from "./router"; +import { createI18n } from "vue-i18n"; +import { i18nConfig, localeLabels } from "./content/index"; const i18n = createI18n(i18nConfig); -const app = createApp(App) - .use(createPinia()) - .use(router) - .use(i18n) +const app = createApp(App).use(createPinia()).use(router).use(i18n); app.config.globalProperties.$localeLabels = localeLabels; -app.mount('#app') \ No newline at end of file +app.mount("#app"); diff --git a/frontend/src/views/SeedViewerView.vue b/frontend/src/views/SeedViewerView.vue index 7d4ce45..ec8e5f2 100644 --- a/frontend/src/views/SeedViewerView.vue +++ b/frontend/src/views/SeedViewerView.vue @@ -1,24 +1,25 @@