Skip to content

Commit

Permalink
Allow to change name of game space from the header
Browse files Browse the repository at this point in the history
  • Loading branch information
Zequez committed Nov 3, 2024
1 parent fd8ac44 commit e9faa19
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
13 changes: 11 additions & 2 deletions ui/src/GameSpace/GameSpace.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,20 @@
function handleAddToPocket() {
addToPocket(gameSpace);
}
function handleNameChange(name: string) {
gameSpace.change({ type: 'set-name', name });
}
</script>

{#if $state}
{#if !asAsset}
<LayoutBar title={$state.name + ($permissions.isArchived ? ' (view only)' : '')} />
<LayoutBar
onChangeTitle={handleNameChange}
canChangeTitle={$permissions.canEditSpace}
title={$state.name}
sub={$permissions.isArchived ? ' (view only)' : ''}
/>
{/if}
<div class="h-full flex flex-col">
{#if !$permissions.isArchived}
Expand Down Expand Up @@ -142,7 +151,7 @@
<SpaceConfigurator
creator={$state.creator}
name={$state.name}
onNameChange={(name) => gameSpace.change({ type: 'set-name', name })}
onNameChange={handleNameChange}
canEdit={$permissions.canEditSpace}
/>
{/if}
Expand Down
27 changes: 26 additions & 1 deletion ui/src/Layout/LayoutBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { type Board } from '~/lib/store';
import { route, goBack } from '~/lib/routes';
import { tooltip } from '~/shared/tooltip';
import { cx } from '~/lib/util';
import AboutDialog from './AboutDialog.svelte';
import AvatarDialog from './AvatarDialog.svelte';
Expand All @@ -21,6 +22,9 @@
export let activeBoard: Board = null;
export let title = 'Board Gamez';
export let canChangeTitle: boolean = false;
export let onChangeTitle = (name: string) => {};
export let sub: string = null;
let aboutDialog;
let editAvatarDialog;
Expand All @@ -32,6 +36,16 @@
const editAvatar = () => {
editAvatarDialog.open();
};
function handleTitleBlur(ev: { currentTarget: HTMLHeadingElement }) {
onChangeTitle(ev.currentTarget.innerText);
}
function handleTitleKeydown(ev: KeyboardEvent & { currentTarget: HTMLHeadingElement }) {
if (ev.key === 'Enter') {
ev.currentTarget.blur();
}
}
</script>

<AboutDialog bind:this={aboutDialog} />
Expand All @@ -46,9 +60,20 @@
<ArrowLeftIcon />
</button>
{/if}
<h1 class="font-bold text-2xl" style="text-shadow: 0 1px 0 rgba(0,0,0,.5)">
<h1
class={cx('font-bold text-2xl px2 py1 rounded-md outline-main-500', {
'hocus:(bg-gray-100 text-black/80 text-shadow-none!)': canChangeTitle,
})}
on:keydown={handleTitleKeydown}
style="text-shadow: 0 1px 0 rgba(0,0,0,.5)"
contenteditable={canChangeTitle}
on:blur={handleTitleBlur}
>
{title}
</h1>
{#if sub}
<span class="opacity-50">{sub}</span>
{/if}

<div class="flex-grow"></div>

Expand Down
3 changes: 3 additions & 0 deletions ui/src/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { WeaveUrl } from '@theweave/api';
import classnames from 'classnames';
import { readable } from 'svelte/store';
import type { Readable } from 'svelte/store';

Expand Down Expand Up @@ -65,3 +66,5 @@ export function waitUntilAvailable<T>(readable: Readable<T | null>): Promise<T>
}, 5000);
});
}

export const cx = classnames;

0 comments on commit e9faa19

Please sign in to comment.