various bug fixes

This commit is contained in:
Zoe
2023-04-21 01:25:27 -05:00
parent 3ea8167569
commit 4890d657b5
12 changed files with 137 additions and 41 deletions

View File

@@ -20,7 +20,8 @@
"parseMessageBody": true, "parseMessageBody": true,
"storeToRefs": true, "storeToRefs": true,
"useNuxtApp": true, "useNuxtApp": true,
"NodeJS": true "NodeJS": true,
"useHeadSafe": true
}, },
"parser": "vue-eslint-parser", "parser": "vue-eslint-parser",
"parserOptions": { "parserOptions": {

View File

@@ -274,7 +274,7 @@ export default {
} }
} else { } else {
if (i !== this.server.messages.length - 1 || this.server.messages[i + 1]?.creator.id === message.creator.id) { if (i !== this.server.messages.length - 1 || this.server.messages[i + 1]?.creator.id === message.creator.id) {
return 'mt-0 mb-0 py-0.5'; return 'mt-0 mb-0 !py-0.5';
} else { } else {
return 'mt-0 pt-0.5 pb-1'; return 'mt-0 pt-0.5 pb-1';
} }

View File

@@ -134,7 +134,8 @@
<button <button
v-for="channel in server.channels" v-for="channel in server.channels"
:key="channel.id" :key="channel.id"
class="flex text-center bg-inherit hover:backdrop-brightness-[1.35] px-2 py-1.5 w-full transition-all rounded drop-shadow-sm gap-1/5 cursor-pointer items-center" :class="(activeChannel.id === channel.id) ? 'backdrop-brightness-[1.35]' : 'hover:backdrop-brightness-[1.35]'"
class="flex text-center bg-inherit px-2 py-1.5 w-full transition-all rounded drop-shadow-sm gap-1/5 cursor-pointer items-center"
@click="openChannel(channel.id)" @click="openChannel(channel.id)"
> >
<span class="h-fit"> <span class="h-fit">
@@ -330,10 +331,14 @@ import { useGlobalStore } from '~/stores/store';
import { IChannel, IRole } from '~/types'; import { IChannel, IRole } from '~/types';
export default { export default {
setup() {
console.log('sidebar', useGlobalStore().activeServer.channels);
},
data() { data() {
return { return {
server: storeToRefs(useGlobalStore()).activeServer, server: storeToRefs(useGlobalStore()).activeServer,
serverType: storeToRefs(useGlobalStore()).activeServerType, serverType: storeToRefs(useGlobalStore()).activeServerType,
activeChannel: storeToRefs(useGlobalStore()).activeChannel,
user: storeToRefs(useGlobalStore()).user, user: storeToRefs(useGlobalStore()).user,
dms: storeToRefs(useGlobalStore()).dms, dms: storeToRefs(useGlobalStore()).dms,
createChannelModelOpen: false, createChannelModelOpen: false,

View File

@@ -1,5 +1,4 @@
<template> <template>
<Suspense>
<div class="flex h-screen max-h-screen text-white"> <div class="flex h-screen max-h-screen text-white">
<Nav /> <Nav />
<Sidebar /> <Sidebar />
@@ -7,10 +6,6 @@
<slot /> <slot />
</div> </div>
</div> </div>
<template #fallback>
Loading...
</template>
</Suspense>
</template> </template>
<script lang="ts"> <script lang="ts">
@@ -21,8 +16,7 @@ import { io } from 'socket.io-client';
export default { export default {
async setup() { async setup() {
const globalStore = useGlobalStore(); const globalStore = useGlobalStore();
const sessionToken = useCookie('sessionToken'); if (globalStore.user.id === undefined) {
if (globalStore.user.id === undefined && sessionToken.value) {
const route = useRoute(); const route = useRoute();
const headers = useRequestHeaders(['cookie']) as Record<string, string>; const headers = useRequestHeaders(['cookie']) as Record<string, string>;
const [user, { dms, servers }] = await Promise.all([ const [user, { dms, servers }] = await Promise.all([
@@ -37,7 +31,13 @@ export default {
globalStore.setServers(servers); globalStore.setServers(servers);
globalStore.setDms(dms); globalStore.setDms(dms);
if (route.params.id && typeof route.params.id === 'string') { if (route.params.id && typeof route.params.id === 'string') {
if (!globalStore.getServerByChannelId(route.params.id)) {
navigateTo('/');
return;
}
globalStore.setActiveServer(route.path.includes('@me') ? 'dms' : 'servers', route.params.id); globalStore.setActiveServer(route.path.includes('@me') ? 'dms' : 'servers', route.params.id);
} else {
globalStore.setActiveServerType(route.path.includes('@me') ? 'dms' : 'servers');
} }
} }
}, },

View File

@@ -1,7 +1,7 @@
// https://v3.nuxtjs.org/api/configuration/nuxt.config // https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({ export default defineNuxtConfig({
ssr: true, ssr: false,
app: { app: {
head: { head: {
meta: [ meta: [

View File

@@ -43,6 +43,12 @@ export default {
e.body = parseMessageBody(e.body, useGlobalStore().activeChannel); e.body = parseMessageBody(e.body, useGlobalStore().activeChannel);
}); });
const friend = server.dmParticipants?.find((e) => e.id !== useGlobalStore().user.id)?.username;
useHeadSafe({
title: `@${friend} - Blop`
});
return { return {
server server
}; };

View File

@@ -1,16 +1,9 @@
<!-- eslint-disable vue/no-multiple-template-root --> <!-- eslint-disable vue/no-multiple-template-root -->
<template> <template>
<MessagePane /> <MessagePane />
<div <div class="fixed mr-3" :style="`top: ${emojiPickerData.top}px; right: ${emojiPickerData.right}px`">
class="fixed mr-3"
:style="`top: ${emojiPickerData.top}px; right: ${emojiPickerData.right}px`"
>
<Transition> <Transition>
<Popup <Popup :opened="emojiPickerData.opened" :openedBy="emojiPickerData.type" @pickedEmoji="pickedEmoji($event)" />
:opened="emojiPickerData.opened"
:openedBy="emojiPickerData.type"
@pickedEmoji="pickedEmoji($event)"
/>
</Transition> </Transition>
</div> </div>
</template> </template>
@@ -27,14 +20,15 @@ definePageMeta({
export default { export default {
async setup() { async setup() {
const route = useRoute(); const route = useRoute();
if (useGlobalStore().servers.find((e) => { return e.channels.some((e) => e.id === route.params.id); } ) == undefined) navigateTo('/');
const headers = useRequestHeaders(['cookie']) as Record<string, string>; const headers = useRequestHeaders(['cookie']) as Record<string, string>;
const server: IChannel = await $fetch(`/api/channels/${route.params.id}`, { headers }); const [server, realServer] = await Promise.all([
await $fetch(`/api/channels/${route.params.id}`, { headers }) as IChannel,
await $fetch(`/api/channels/${route.params.id}/guild`, { headers }) as IServer,
]);
// if (!useGlobalStore().servers.find((e) => e.id == server.serverId)?.participants) {
const realServer: IServer = await $fetch(`/api/guilds/${server.serverId}`, { headers });
if (!realServer) throw new Error('realServer not found, this means that the channel is serverless but not a dm????'); if (!realServer) throw new Error('realServer not found, this means that the channel is serverless but not a dm????');
useGlobalStore().addServer(realServer); useGlobalStore().addServer(realServer);
// }
if (typeof route.params.id !== 'string') throw new Error('route.params.id must be a string, but got an array presumably?'); if (typeof route.params.id !== 'string') throw new Error('route.params.id must be a string, but got an array presumably?');
useGlobalStore().setActiveServer('servers', route.params.id); useGlobalStore().setActiveServer('servers', route.params.id);
@@ -45,6 +39,10 @@ export default {
e.body = parseMessageBody(e.body, useGlobalStore().activeChannel); e.body = parseMessageBody(e.body, useGlobalStore().activeChannel);
}); });
useHeadSafe({
title: `#${server.name} | ${realServer.name} - Blop`
});
return { return {
server, server,
}; };
@@ -67,7 +65,7 @@ export default {
}, },
async updated() { async updated() {
const route = useRoute(); const route = useRoute();
if (typeof route.params.id !== 'string') throw new Error('route.params.id must be a string, but got an array presumiably?'); if (typeof route.params.id !== 'string') throw new Error('route.params.id must be a string, but got an array presumably?');
if (useGlobalStore().activeChannel.id !== this.server.id) { if (useGlobalStore().activeChannel.id !== this.server.id) {
useGlobalStore().closeEmojiPicker(); useGlobalStore().closeEmojiPicker();
useGlobalStore().setActiveServer('servers', route.params.id); useGlobalStore().setActiveServer('servers', route.params.id);

View File

@@ -1,5 +1,3 @@
<template> <template>
<div> <div>lorem ipsum</div>
<Popup />
</div>
</template> </template>

View File

@@ -0,0 +1,73 @@
import { IServer } from '~/types';
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
export default defineEventHandler(async (event) => {
if (!event.context.user.authenticated) {
throw createError({
statusCode: 401,
statusMessage: 'You must be logged in to view a channel.',
});
}
if (!event.context.params?.id) {
throw createError({
statusCode: 400,
statusMessage: 'A channelId is required',
});
}
const server = await prisma.server.findFirst({
where: {
channels: {
some: { id: event.context.params.id }
}
},
select: {
id: true,
name: true,
participants: {
select: {
id: true,
username: true
}
},
channels: {
select: {
id: true,
DM: true,
name: true,
}
},
roles: {
select: {
id: true,
name: true,
administrator: true,
owner: true,
users: {
select: {
id: true
}
}
}
}
}
}) as IServer | null;
if (!server) {
throw createError({
statusCode: 404,
statusMessage: `Channel with id "${event.context.params.id}" not found`,
});
}
if (!server.participants.find((participant) => participant.id === event.context.user.id)) {
throw createError({
statusCode: 403,
statusMessage: `Can't find participant with id "${event.context.params.id}" in guild with id "${event.context.params.id}"`,
});
}
return server;
});

View File

@@ -60,5 +60,12 @@ export default defineEventHandler(async (event) => {
}); });
} }
if (!server.participants.find((participant) => participant.id === event.context.user.id)) {
throw createError({
statusCode: 403,
statusMessage: `Can't find participant with id "${event.context.params.id}" in guild with id "${event.context.params.id}"`,
});
}
return server; return server;
}); });

View File

@@ -40,6 +40,9 @@ export const useGlobalStore = defineStore('global', {
setActiveChannel(channel: IChannel) { setActiveChannel(channel: IChannel) {
this.activeChannel = channel; this.activeChannel = channel;
}, },
setActiveServerType(type: 'dms' | 'servers') {
this.activeServerType = type;
},
updateServer(channelId: string, server: IServer) { updateServer(channelId: string, server: IServer) {
const serverIndex = this.servers.findIndex(s => s.channels.some((c) => c.id === channelId)); const serverIndex = this.servers.findIndex(s => s.channels.some((c) => c.id === channelId));
this.servers[serverIndex] = server; this.servers[serverIndex] = server;
@@ -70,6 +73,12 @@ export const useGlobalStore = defineStore('global', {
} }
this.servers.push(server); this.servers.push(server);
}, },
getServerByChannelId(channelId: string) {
let channel: IChannel | IServer | undefined = this.dms.find((e) => e.id === channelId);
if (channel) return channel;
channel = this.servers.find((e) => e.channels.some((c) => c.id === channelId));
return channel;
},
setDms(dms: Array<IChannel>) { setDms(dms: Array<IChannel>) {
this.dms = dms; this.dms = dms;
}, },

View File

@@ -1 +0,0 @@
{"version":"5.0.2"}