feat: initialize project with Docker, PostgreSQL, Redis, and Vue.js frontend
- Added docker-compose.yml for PostgreSQL and Redis services with health checks. - Created frontend directory with initial Vue.js setup including package.json, vite.config.ts, and TypeScript configuration. - Implemented main application structure with App.vue and HomePage.vue components. - Added message fetching and posting functionality in HomePage.vue. - Included necessary styles and scripts for Ionic framework integration. - Developed a dev-stack script to manage Docker containers and run backend/frontend servers.
This commit is contained in:
9
frontend/src/App.vue
Normal file
9
frontend/src/App.vue
Normal file
@@ -0,0 +1,9 @@
|
||||
<template>
|
||||
<ion-app>
|
||||
<ion-router-outlet />
|
||||
</ion-app>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { IonApp, IonRouterOutlet } from "@ionic/vue";
|
||||
</script>
|
||||
35
frontend/src/main.ts
Normal file
35
frontend/src/main.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { createApp } from "vue";
|
||||
import { IonicVue } from "@ionic/vue";
|
||||
import { createRouter, createWebHistory } from "@ionic/vue-router";
|
||||
import type { RouteRecordRaw } from "vue-router";
|
||||
import App from "./App.vue";
|
||||
import HomePage from "./views/HomePage.vue";
|
||||
|
||||
/* Ionic core CSS */
|
||||
import "@ionic/vue/css/core.css";
|
||||
import "@ionic/vue/css/normalize.css";
|
||||
import "@ionic/vue/css/structure.css";
|
||||
import "@ionic/vue/css/typography.css";
|
||||
|
||||
/* Optional utilities */
|
||||
import "@ionic/vue/css/padding.css";
|
||||
import "@ionic/vue/css/float-elements.css";
|
||||
import "@ionic/vue/css/text-alignment.css";
|
||||
import "@ionic/vue/css/text-transformation.css";
|
||||
import "@ionic/vue/css/flex-utils.css";
|
||||
import "@ionic/vue/css/display.css";
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{ path: "/", component: HomePage },
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes,
|
||||
});
|
||||
|
||||
const app = createApp(App).use(IonicVue).use(router);
|
||||
|
||||
router.isReady().then(() => {
|
||||
app.mount("#app");
|
||||
});
|
||||
174
frontend/src/views/HomePage.vue
Normal file
174
frontend/src/views/HomePage.vue
Normal file
@@ -0,0 +1,174 @@
|
||||
<template>
|
||||
<ion-page>
|
||||
<ion-header :translucent="true">
|
||||
<ion-toolbar>
|
||||
<ion-title>XIP 📡</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
|
||||
<ion-content :fullscreen="true">
|
||||
<ion-header collapse="condense">
|
||||
<ion-toolbar>
|
||||
<ion-title size="large">XIP</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
|
||||
<!-- Composer -->
|
||||
<div class="composer">
|
||||
<ion-textarea
|
||||
v-model="newContent"
|
||||
:maxlength="267"
|
||||
:counter="true"
|
||||
:auto-grow="true"
|
||||
placeholder="Exprime-toi... (267 caractères max)"
|
||||
fill="outline"
|
||||
/>
|
||||
<ion-button
|
||||
expand="block"
|
||||
class="send-btn"
|
||||
:disabled="!newContent.trim() || sending"
|
||||
@click="postMessage"
|
||||
>
|
||||
{{ sending ? "Envoi..." : "Envoyer" }}
|
||||
</ion-button>
|
||||
</div>
|
||||
|
||||
<!-- Feed -->
|
||||
<ion-list v-if="messages.length > 0">
|
||||
<template v-for="msg in messages" :key="msg.id">
|
||||
<ion-item lines="full">
|
||||
<ion-label class="ion-text-wrap">
|
||||
<p class="meta">{{ msg.authorIp }} · {{ formatDate(msg.createdAt) }}</p>
|
||||
<h2>{{ msg.content }}</h2>
|
||||
<p v-if="msg.replies.length > 0" class="replies-count">
|
||||
{{ msg.replies.length }} réponse(s)
|
||||
</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
|
||||
<!-- Replies -->
|
||||
<ion-item
|
||||
v-for="reply in msg.replies"
|
||||
:key="reply.id"
|
||||
lines="none"
|
||||
class="reply-item"
|
||||
>
|
||||
<ion-label class="ion-text-wrap">
|
||||
<p class="meta">↳ {{ reply.authorIp }} · {{ formatDate(reply.createdAt) }}</p>
|
||||
<p>{{ reply.content }}</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
</template>
|
||||
</ion-list>
|
||||
|
||||
<div v-else-if="!loading" class="empty-state">
|
||||
<p>Aucun message pour l'instant.</p>
|
||||
</div>
|
||||
</ion-content>
|
||||
</ion-page>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from "vue";
|
||||
import {
|
||||
IonPage,
|
||||
IonHeader,
|
||||
IonToolbar,
|
||||
IonTitle,
|
||||
IonContent,
|
||||
IonList,
|
||||
IonItem,
|
||||
IonLabel,
|
||||
IonTextarea,
|
||||
IonButton,
|
||||
} from "@ionic/vue";
|
||||
|
||||
interface Message {
|
||||
id: string;
|
||||
content: string;
|
||||
authorIp: string;
|
||||
createdAt: string;
|
||||
replies: Omit<Message, "replies">[];
|
||||
}
|
||||
|
||||
const API_URL = import.meta.env.VITE_API_URL ?? "http://localhost:3000";
|
||||
|
||||
const messages = ref<Message[]>([]);
|
||||
const newContent = ref("");
|
||||
const loading = ref(false);
|
||||
const sending = ref(false);
|
||||
|
||||
async function fetchMessages(): Promise<void> {
|
||||
loading.value = true;
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/api/messages`);
|
||||
if (!res.ok) throw new Error("Failed to fetch messages");
|
||||
messages.value = (await res.json()) as Message[];
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function postMessage(): Promise<void> {
|
||||
if (!newContent.value.trim()) return;
|
||||
sending.value = true;
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/api/messages`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ content: newContent.value.trim() }),
|
||||
});
|
||||
if (!res.ok) throw new Error("Failed to post message");
|
||||
newContent.value = "";
|
||||
await fetchMessages();
|
||||
} finally {
|
||||
sending.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(date: string): string {
|
||||
return new Date(date).toLocaleString("fr-FR", {
|
||||
day: "2-digit",
|
||||
month: "2-digit",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(fetchMessages);
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.composer {
|
||||
padding: 16px;
|
||||
border-bottom: 1px solid var(--ion-color-light-shade);
|
||||
}
|
||||
|
||||
.send-btn {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.meta {
|
||||
font-size: 0.75rem;
|
||||
color: var(--ion-color-medium);
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.replies-count {
|
||||
font-size: 0.75rem;
|
||||
color: var(--ion-color-primary);
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.reply-item {
|
||||
--padding-start: 32px;
|
||||
background-color: var(--ion-color-light);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 48px 16px;
|
||||
color: var(--ion-color-medium);
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user