WalidMoovin
2 years ago
4 changed files with 108 additions and 92 deletions
@ -1,52 +1,73 @@ |
|||
<script lang="ts" context="module"> |
|||
<script lang="ts" context="module"> |
|||
import type { chatMessagesType } from "./Chat2.svelte"; |
|||
export interface ChannelsType { |
|||
id: string; |
|||
name: string; |
|||
id: string; |
|||
name: string; |
|||
messages: Array<chatMessagesType>; |
|||
} |
|||
</script> |
|||
</script> |
|||
|
|||
<script lang="ts"> |
|||
<script lang="ts"> |
|||
export let channels: Array<ChannelsType> = []; |
|||
export let enter = (id: string) => {}; |
|||
</script> |
|||
export let onSelectChannel: (channel: ChannelsType) => void; |
|||
const selectChat = (id: string) => { |
|||
const channel = channels.find(c => c.id === id); |
|||
if (channel) { |
|||
onSelectChannel(channel); |
|||
} |
|||
} |
|||
const createChannel = () => { |
|||
const name = prompt("Enter a name for the new channel:"); |
|||
if (name) { |
|||
const newChannel: ChannelsType = { |
|||
id: Math.random().toString(), |
|||
name, |
|||
messages: [] |
|||
}; |
|||
channels = [newChannel, ...channels]; |
|||
} |
|||
// TODO: save to database |
|||
}; |
|||
</script> |
|||
|
|||
<div class="overlay"> |
|||
<div class="overlay"> |
|||
<div class="channels" on:click|stopPropagation on:keydown|stopPropagation> |
|||
<div> |
|||
<div> |
|||
{#if channels.length > 0} |
|||
<h2>Channels</h2> |
|||
{#each channels.slice(0, 10) as _channels} |
|||
<h2>Channels</h2> |
|||
{#each channels.slice(0, 10) as _channels} |
|||
<li> |
|||
<span>{_channels.name}</span> |
|||
<button on:click={() => enter(_channels.id)}>Enter</button> |
|||
<span>{_channels.name}</span> |
|||
<button on:click={() => selectChat(_channels.id)}>Enter</button> |
|||
</li> |
|||
{/each} |
|||
{/each} |
|||
{:else} |
|||
<p>No channels available</p> |
|||
<p>No channels available</p> |
|||
{/if} |
|||
</div> |
|||
<button on:click={createChannel}>Create Channel</button> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
|
|||
<style> |
|||
<style> |
|||
.overlay { |
|||
position: fixed; |
|||
top: 0; |
|||
left: 0; |
|||
width: 100%; |
|||
height: 100%; |
|||
background-color: rgba(0, 0, 0, 0.5); |
|||
z-index: 9998; |
|||
display: flex; |
|||
justify-content: center; |
|||
align-items: center; |
|||
position: fixed; |
|||
top: 0; |
|||
left: 0; |
|||
width: 100%; |
|||
height: 100%; |
|||
background-color: rgba(0, 0, 0, 0.5); |
|||
z-index: 9998; |
|||
display: flex; |
|||
justify-content: center; |
|||
align-items: center; |
|||
} |
|||
|
|||
.channels { |
|||
background-color: #fff; |
|||
border: 1px solid #ccc; |
|||
border-radius: 5px; |
|||
padding: 1rem; |
|||
width: 300px; |
|||
background-color: #fff; |
|||
border: 1px solid #ccc; |
|||
border-radius: 5px; |
|||
padding: 1rem; |
|||
width: 300px; |
|||
} |
|||
</style> |
|||
</style> |
|||
|
Loading…
Reference in new issue