cleanup
This commit is contained in:
parent
4cbdfd56f7
commit
0d17432d0e
@ -1,32 +1,29 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
// Define an array to store the fetched data
|
|
||||||
let fetchedData = [];
|
let fetchedData = [];
|
||||||
|
|
||||||
// Function to fetch data from the API
|
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('https://api.example.com/data'); // Replace with your API endpoint
|
const response = await fetch('https://api.example.com/data');
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to fetch data');
|
throw new Error('Failed to fetch data');
|
||||||
}
|
}
|
||||||
fetchedData = await response.json(); // Parse the JSON response
|
fetchedData = await response.json();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching data:', error.message);
|
console.error('Error fetching data:', error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the fetchData function when the component is mounted
|
|
||||||
onMount(fetchData);
|
onMount(fetchData);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="center-container">
|
<div class="center-container">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<p>hi</p>
|
<p>hi</p>
|
||||||
<!-- Your existing Svelte code here -->
|
|
||||||
|
|
||||||
<!-- Display the fetched data -->
|
|
||||||
<ul>
|
<ul>
|
||||||
{#each fetchedData as item}
|
{#each fetchedData as item}
|
||||||
<li>{item.first} {item.last}</li>
|
<li>{item.first} {item.last}</li>
|
||||||
|
|||||||
@ -3,23 +3,23 @@
|
|||||||
import ApIopertaions from "./APIopertaions.svelte";
|
import ApIopertaions from "./APIopertaions.svelte";
|
||||||
import CRUDoperations from "./CRUDoperations.svelte";
|
import CRUDoperations from "./CRUDoperations.svelte";
|
||||||
|
|
||||||
// Define a variable to track the current route
|
|
||||||
let currentRoute = '';
|
let currentRoute = '';
|
||||||
|
|
||||||
// Function to update the current route based on the URL hash
|
|
||||||
function updateRouteFromHash() {
|
function updateRouteFromHash() {
|
||||||
currentRoute = window.location.hash.slice(1); // Remove '#' from the URL hash
|
currentRoute = window.location.hash.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the updateRouteFromHash function when the component is mounted
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
window.addEventListener('hashchange', updateRouteFromHash); // Listen for hash change events
|
window.addEventListener('hashchange', updateRouteFromHash);
|
||||||
updateRouteFromHash(); // Update the current route initially
|
updateRouteFromHash();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Function to navigate to a different route
|
|
||||||
function navigateTo(route) {
|
function navigateTo(route) {
|
||||||
window.location.hash = route; // Update the URL hash
|
window.location.hash = route;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -57,23 +57,23 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<h1>POC</h1>
|
<h1>Svelte</h1>
|
||||||
<nav>
|
<nav>
|
||||||
<ul>
|
<ul>
|
||||||
<!-- Define navigation links -->
|
|
||||||
<li><a href="#api">API Operations</a></li>
|
<li><a href="#api">API Operations</a></li>
|
||||||
<li><a href="#crud">CRUD Operations</a></li>
|
<li><a href="#crud">CRUD Operations</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<!-- Conditional rendering based on the current route -->
|
|
||||||
{#if currentRoute === 'api'}
|
{#if currentRoute === 'api'}
|
||||||
<ApIopertaions />
|
<ApIopertaions />
|
||||||
{:else if currentRoute === 'crud'}
|
{:else if currentRoute === 'crud'}
|
||||||
<CRUDoperations />
|
<CRUDoperations />
|
||||||
{:else}
|
{:else}
|
||||||
<!-- Handle unknown routes or default content -->
|
|
||||||
<p>Page not found</p>
|
<p>Page not found</p>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
@ -82,37 +82,31 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
width: 500px; /* Increase width for a bigger dialog box */
|
width: 500px;
|
||||||
padding: 40px; /* Increase padding for more spacing inside the dialog box */
|
padding: 40px;
|
||||||
background-color: #ffffff; /* Change background color to white */
|
background-color: #ffffff;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
label {
|
label {
|
||||||
display: block;
|
display: block;
|
||||||
margin-bottom: 16px; /* Increase margin bottom for more spacing between elements */
|
margin-bottom: 16px;
|
||||||
color: #333;
|
color: #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type="text"],
|
|
||||||
select {
|
select {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 12px; /* Increase padding for larger input fields */
|
padding: 12px;
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
margin-bottom: 24px; /* Increase margin bottom for more spacing between elements */
|
margin-bottom: 24px;
|
||||||
font-size: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button-group {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
padding: 12px 24px; /* Increase padding for larger buttons */
|
padding: 12px 24px;
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user