page for list of rooms

This commit is contained in:
2026-03-19 00:32:48 +00:00
parent 00d9d4023c
commit 8677176706
7 changed files with 83 additions and 11 deletions

View File

@@ -8,7 +8,8 @@
"name": "frontend",
"version": "0.0.0",
"dependencies": {
"vue": "^3.5.30"
"vue": "^3.5.30",
"vue-cookies": "^1.8.6"
},
"devDependencies": {
"@types/bcrypt": "^6.0.0",
@@ -1243,6 +1244,12 @@
}
}
},
"node_modules/vue-cookies": {
"version": "1.8.6",
"resolved": "https://registry.npmjs.org/vue-cookies/-/vue-cookies-1.8.6.tgz",
"integrity": "sha512-e2kYaHj1Y/zVsBSM3KWlOoVJ5o3l4QZjytNU7xdCgmkw3521CMUerqHekBGZKXXC1oRxYljBeeOK2SCel6cKuw==",
"license": "MIT"
},
"node_modules/vue-tsc": {
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/vue-tsc/-/vue-tsc-3.2.6.tgz",

View File

@@ -9,7 +9,8 @@
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.5.30"
"vue": "^3.5.30",
"vue-cookies": "^1.8.6"
},
"devDependencies": {
"@types/bcrypt": "^6.0.0",

View File

@@ -1,7 +1,19 @@
<script setup lang="ts">
import { onBeforeMount, ref } from 'vue';
import Login from './components/Login.vue';
import HomePage from './components/HomePage.vue';
const page = ref<number>(0);
onBeforeMount(async () => {
const loggedIn = await cookieStore.get("loggedIn");
if (loggedIn?.value == "true") {
page.value = 1;
}
})
</script>
<template>
<Login />
<Login v-if="page == 0" @next-page="page++"/>
<HomePage v-if="page == 1" @add-slot="page++"/>
</template>

View File

@@ -0,0 +1,27 @@
<script setup lang="ts">
import { onBeforeMount, ref } from 'vue';
const rooms = ref();
defineEmits(['addSlot']);
onBeforeMount(async () => {
const res = await fetch("http://localhost:3000/currentRooms", {
method: "GET",
headers: new Headers({'content-type': 'application/json'})
});
rooms.value = await res.json();
});
</script>
<template>
<header>
<h1>What's free in my free?</h1>
<button @click="$emit('addSlot')">Add new slot</button>
</header>
<article>
<h2>Free Rooms:</h2>
<p v-if="rooms.records.length == 0">No free rooms right now</p>
<ul v-for="(slot, index) in rooms.records">
<li :id="index">{{ slot }}</li>
</ul>
</article>
</template>

View File

@@ -3,23 +3,40 @@ import { ref } from 'vue';
const email = ref<string>("");
const pass = ref<string>("");
const text = ref<string>("");
function login(e: SubmitEvent) {
const emit = defineEmits(['nextPage']);
async function login(e: SubmitEvent) {
text.value = "";
e.preventDefault();
fetch("http://localhost:3000/login", {
const res = await fetch("http://localhost:3000/login", {
method: "POST",
body: JSON.stringify({ email: email.value, pass: pass.value }),
headers: new Headers({'content-type': 'application/json'})
});
if (res.ok) {
cookieStore.set("loggedIn", "true");
emit('nextPage');
} else {
text.value = await res.text();
}
}
function signup(e: Event) {
async function signup(e: Event) {
text.value = "";
e.preventDefault();
fetch("http://localhost:3000/createUser", {
const res = await fetch("http://localhost:3000/createUser", {
method: "POST",
body: JSON.stringify({ email: email.value, pass: pass.value, name: email.value.split("@")[0] }),
headers: new Headers({'content-type': 'application/json'})
});
if (res.ok) {
cookieStore.set("loggedIn", "true");
emit('nextPage');
} else {
text.value = await res.text();
}
}
</script>
@@ -32,5 +49,6 @@ function signup(e: Event) {
<input type="password" id="pass" v-model="pass"/> <br>
<button type="submit">Sign in</button> <br>
<button type="button" @click="signup">Sign up</button>
<p>{{ text }}</p>
</form>
</template>

View File

@@ -1,5 +1,6 @@
import { createApp } from 'vue'
import { createApp } from 'vue';
// import './style.css'
import App from './App.vue'
import App from './App.vue';
import VueCookies from 'vue-cookies';
createApp(App).mount('#app')
createApp(App).use(VueCookies).mount('#app');