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 { |
export interface ChannelsType { |
||||
id: string; |
id: string; |
||||
name: string; |
name: string; |
||||
|
messages: Array<chatMessagesType>; |
||||
} |
} |
||||
</script> |
</script> |
||||
|
|
||||
<script lang="ts"> |
<script lang="ts"> |
||||
export let channels: Array<ChannelsType> = []; |
export let channels: Array<ChannelsType> = []; |
||||
export let enter = (id: string) => {}; |
export let onSelectChannel: (channel: ChannelsType) => void; |
||||
</script> |
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 class="channels" on:click|stopPropagation on:keydown|stopPropagation> |
||||
<div> |
<div> |
||||
{#if channels.length > 0} |
{#if channels.length > 0} |
||||
<h2>Channels</h2> |
<h2>Channels</h2> |
||||
{#each channels.slice(0, 10) as _channels} |
{#each channels.slice(0, 10) as _channels} |
||||
<li> |
<li> |
||||
<span>{_channels.name}</span> |
<span>{_channels.name}</span> |
||||
<button on:click={() => enter(_channels.id)}>Enter</button> |
<button on:click={() => selectChat(_channels.id)}>Enter</button> |
||||
</li> |
</li> |
||||
{/each} |
{/each} |
||||
{:else} |
{:else} |
||||
<p>No channels available</p> |
<p>No channels available</p> |
||||
{/if} |
{/if} |
||||
</div> |
<button on:click={createChannel}>Create Channel</button> |
||||
|
</div> |
||||
</div> |
</div> |
||||
</div> |
</div> |
||||
|
|
||||
<style> |
<style> |
||||
.overlay { |
.overlay { |
||||
position: fixed; |
position: fixed; |
||||
top: 0; |
top: 0; |
||||
left: 0; |
left: 0; |
||||
width: 100%; |
width: 100%; |
||||
height: 100%; |
height: 100%; |
||||
background-color: rgba(0, 0, 0, 0.5); |
background-color: rgba(0, 0, 0, 0.5); |
||||
z-index: 9998; |
z-index: 9998; |
||||
display: flex; |
display: flex; |
||||
justify-content: center; |
justify-content: center; |
||||
align-items: center; |
align-items: center; |
||||
} |
} |
||||
|
|
||||
.channels { |
.channels { |
||||
background-color: #fff; |
background-color: #fff; |
||||
border: 1px solid #ccc; |
border: 1px solid #ccc; |
||||
border-radius: 5px; |
border-radius: 5px; |
||||
padding: 1rem; |
padding: 1rem; |
||||
width: 300px; |
width: 300px; |
||||
} |
} |
||||
</style> |
</style> |
||||
|
Loading…
Reference in new issue