Skip to content

Commit

Permalink
Don't hard reload when clicking "My IP Address"
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistTheNeil committed Feb 20, 2024
1 parent b44b16a commit c6d1195
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 1 addition & 2 deletions frontend/src/components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<nav class="navbar navbar-light bg-light mb-5">
<div class="container">
<a class="navbar-brand" href="https://github.com/TwistTheNeil/rest-geoip">About</a>
<!-- replace href to something vue router capable -->
<a class="nav-link" aria-current="page" href="/">My IP Address</a>
<button type="button" class="btn btn-outline-primary btn-sm" @click="$emit('queryReset')">My IP Address</button>
</div>
</nav>
</template>
10 changes: 7 additions & 3 deletions frontend/src/components/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</template>

<script setup lang='ts'>
import { ref } from 'vue';
import { ref, watch } from 'vue';
import type { Ref } from 'vue';
import SearchIcon from '@/components/icons/SearchIcon.vue';
Expand All @@ -28,8 +28,12 @@
]);
const maxmindStore = useMaxmindDataStore();
const { data } = storeToRefs(maxmindStore);
const queryString: Ref<string | null> = ref(data?.value?.IP || '');
const queryString: Ref<string> = ref('');
watch(data, () => {
if (queryString.value !== data.value.IP) {
queryString.value = '';
}
});
</script>
8 changes: 7 additions & 1 deletion frontend/src/layouts/DefaultLayout.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div>
<OverviewProgressbar />
<NavBar />
<NavBar @query-reset="resetIPAddressDetails" />

<div class="container justify-content-center align-items-center">
<SearchBar @query-request="fetchIPAddressDetails" />
Expand All @@ -23,6 +23,12 @@
const overviewProgressbarStore = useOverviewProgressbarStore();
const maxmindDataStore = useMaxmindDataStore();
const resetIPAddressDetails = async () => {
overviewProgressbarStore.update(30);
await maxmindDataStore.$reset();
overviewProgressbarStore.update(100);
};
const fetchIPAddressDetails = async (ipAddress: string) => {
if (!isIP(ipAddress)) {
return;
Expand Down

0 comments on commit c6d1195

Please sign in to comment.