diff --git a/resources/scripts/app/Subnet.vue b/resources/scripts/app/Subnet.vue index d92c33e..18b19b7 100644 --- a/resources/scripts/app/Subnet.vue +++ b/resources/scripts/app/Subnet.vue @@ -15,32 +15,33 @@ const results = ref( {} ); /** * Load subnet data based on input */ -const getSubnetData = () => { - // Enable loading icon - isLoading.value = true; +const getSubnetData = async () => { + try { + // Enable loading state + isLoading.value = true; - // Create post data - const postData = new FormData(); - postData.append( 'subnet', subnet.value ); + // Prepare request payload + const postData = new FormData(); + postData.append( 'subnet', subnet.value ); - // Send request - axios.post( '/api/subnet', postData ).then( (response) => { + // Send request and handle response + const response = await axios.post( '/api/subnet', postData ); const { data } = response; - // Load new block - isLoading.value = false; - hasResults.value = true; + // Update results and UI state results.value = data.result; - } ).catch( (error) => { - isLoading.value = false; - - // Show error message - const errorMessage = error.response.data.message || 'Something went wrong.'; + hasResults.value = true; + } catch (error) { + // Extract and show error message + const errorMessage = error.response?.data?.message || 'Something went wrong.'; $toast.error(errorMessage, { position: 'top', duration: 1500, }); - } ); + } finally { + // Reset loading state + isLoading.value = false; + } } /** diff --git a/resources/scripts/main.ts b/resources/scripts/main.ts index 10f906a..cf90463 100644 --- a/resources/scripts/main.ts +++ b/resources/scripts/main.ts @@ -4,7 +4,7 @@ import ToastPlugin from 'vue-toast-notification'; import 'vue-toast-notification/dist/theme-default.css'; // Import components -import Subnet from '@app/Subnet.vue'; +import Subnet from '@scripts/app/Subnet.vue'; // Initialize vue app function initializeApp(element: string, component: any): void { diff --git a/src/Http/Response.php b/src/Http/Response.php index 493b88a..99d4fcb 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -2,9 +2,9 @@ namespace Core\Http; -use Core\View\JsonRender; use Core\View\Render; use Core\View\Render\HtmlRender; +use Core\View\Render\JsonRender; class Response { diff --git a/src/View/JsonRender.php b/src/View/Render/JsonRender.php similarity index 83% rename from src/View/JsonRender.php rename to src/View/Render/JsonRender.php index 31d3462..3dc68b5 100644 --- a/src/View/JsonRender.php +++ b/src/View/Render/JsonRender.php @@ -1,6 +1,8 @@