-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d10198d
commit d638a69
Showing
28 changed files
with
611 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script lang="ts"> | ||
import { flip } from 'svelte/animate'; | ||
import { fade, blur, fly, slide, scale, draw } from 'svelte/transition'; | ||
import { _ } from 'svelte-i18n'; | ||
import User from './user.svelte'; | ||
import type { User } from '../../stores/remote-room'; | ||
import { myNameStore } from '../../stores/my-name'; | ||
import { myId } from '../../stores/my-id'; | ||
export let users: User[]; | ||
</script> | ||
|
||
<div class="users uk-flex-center uk-flex uk-margin-top uk-text-center uk-flex-middle"> | ||
<User user={({ name: $myNameStore, id: myId })} me={true} bind:myName={$myNameStore} /> | ||
{#each users as user (user.id)} | ||
{#if $myNameStore !== user} | ||
<User user={user} me={false} /> | ||
{/if} | ||
{/each} | ||
</div> | ||
|
||
<style lang="scss"> | ||
.users { | ||
overflow-y: scroll; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<script lang="ts"> | ||
import { _ } from 'svelte-i18n'; | ||
import { XORWow } from 'random-seedable'; | ||
import type { User } from '../../stores/bound-user'; | ||
export let user: User; | ||
export let myName: string; | ||
export let me: boolean; | ||
const maxLength = 10; | ||
const updateName = function () { | ||
myName = prompt($_('users.nameEditPromt', { values: { maxLength }}), myName); | ||
}; | ||
const code = function (str: string): number { | ||
return [...str].reduce((a, x) => a + x.charCodeAt(0), 0); | ||
}; | ||
function pseudoRandom(seed) { | ||
return function() { | ||
seed = seed * 16807 % 2147483647; | ||
return seed; | ||
} | ||
} | ||
const stringToColor = function (str: string): string { | ||
const rand = pseudoRandom(code(str + user.id.slice(1))); | ||
const randColor = () => (rand() % 100 + 64).toString(16).padStart(2, '0'); | ||
return `#${randColor()}${randColor()}${randColor()}70`; | ||
}; | ||
const emojiRegex = /^\p{Emoji}$/u; | ||
const isEmoji = function (text: string): boolean { | ||
return emojiRegex.test(text); | ||
}; | ||
</script> | ||
|
||
<div | ||
class="user uk-text-center uk-flex uk-flex-column uk-flex-center uk-flex-middle uk-flex-middle uk-margin-right" | ||
style:background-color={stringToColor(user.name)} | ||
> | ||
<div class="uk-text-emphasis uk-margin-small-top" class:uk-text-large={user.name.length === 1 || isEmoji(user.name)}> | ||
{ user.name.slice(0, maxLength) } | ||
</div> | ||
<span class="uk-text-muted uk-text-small"> | ||
{#if me} | ||
<u on:click={updateName} class="pointer">{ $_('users.nameEdit') }</u> | ||
{:else} | ||
online | ||
{/if} | ||
</span> | ||
</div> | ||
|
||
<style lang="scss"> | ||
.user { | ||
height: 4rem; | ||
width: 4rem; | ||
min-height: 4rem; | ||
min-width: 4rem; | ||
border-radius: 1.5rem; | ||
border: 1px solid #7d7d7d; | ||
text-wrap: wrap; | ||
padding: 0.5rem; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
type Destructor = () => void; | ||
|
||
export class Destructable { | ||
private readonly destructors: Destructor[] = []; | ||
|
||
protected onDestruct (destructor: Destructor) { | ||
this.destructors.push(destructor); | ||
} | ||
|
||
protected registerDependency (destructable: Destructable) { | ||
this.onDestruct(() => destructable.destruct()); | ||
} | ||
|
||
destruct () { | ||
while (this.destructors.length) { | ||
const destructor = this.destructors.pop(); | ||
destructor && destructor(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.