Browse Source

chans

master
WalidMoovin 2 years ago
parent
commit
edf30e3353
  1. 40
      front/volume/src/components/Channels.svelte
  2. 13
      front/volume/src/components/Chat.svelte

40
front/volume/src/components/Channels.svelte

@ -7,14 +7,27 @@
password: string; password: string;
messages: Array<chatMessagesType>; messages: Array<chatMessagesType>;
} }
import { onMount } from "svelte";
import { API_URL, store } from "../Auth";
import { dataset_dev } from "svelte/internal";
</script> </script>
<script lang="ts"> <script lang="ts">
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/
export let channels: Array<ChannelsType> = []; export let channels: Array<ChannelsType> = [];
// onMount(async () => {
// const res = await fetch(API_URL + "/channels" + $store.ftId, {
// method: "GET",
// mode: "cors",
// });
// const data = await res.json();
// channels = data;
// });
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/
export let onSelectChannel: (channel: ChannelsType) => void; export let onSelectChannel: (channel: ChannelsType) => void;
const selectChat = (id: string) => { const selectChat = (id: string) => {
const channel = channels.find((c) => c.id === id); const channel = channels.find((c) => c.id === id);
@ -25,7 +38,7 @@
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/
const createChannel = () => { const createChannel = async () => {
const name = prompt("Enter a name for the new channel:"); const name = prompt("Enter a name for the new channel:");
if (name) { if (name) {
const privacy = prompt( const privacy = prompt(
@ -49,17 +62,36 @@
password, password,
messages: [], messages: [],
}; };
channels = [newChannel, ...channels]; // const response = await fetch(API_URL + "/channels" + $store.ftId , {
// method: "POST",
// mode: "cors",
// body: JSON.stringify(newChannel),
// });
// const data = await response.json();
// if (data.ok) {
// channels = [newChannel, ...channels];
// } else {
// alert("Error creating channel");
// }
} }
} }
// TODO: save to database
}; };
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/
const removeChannel = (id: string) => { const removeChannel = async (id: string) => {
let string = prompt("type 'delete' to delete this channel"); let string = prompt("type 'delete' to delete this channel");
if (string === "delete") { if (string === "delete") {
// const response = await fetch(API_URL + "/channels" + $store.ftId + "/" + id, {
// method: "DELETE",
// mode: "cors",
// });
// const data = await response.json();
// if (data.ok) {
// channels = channels.filter((c) => c.id !== id);
// } else {
// alert("Error deleting channel");
// }
channels = channels.filter((c) => c.id !== id); channels = channels.filter((c) => c.id !== id);
} }
// TODO: save to database // TODO: save to database

13
front/volume/src/components/Chat.svelte

@ -79,6 +79,19 @@
// } // }
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/
const blockUser = async () => {
const res = await fetch(API_URL + "/chat/block", {
method: "POST",
mode: "cors",
});
const data = await res.json();
if (data.success) {
alert("User blocked");
} else {
alert("Failed to block user");
}
};
</script> </script>
<div class="overlay"> <div class="overlay">

Loading…
Cancel
Save