Skip to content

Commit

Permalink
style: gray out undo/redo (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverben authored May 7, 2024
1 parent e5b0c4e commit eb8789f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/lib/components/core/header/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import Select from "$components/ui/Select.svelte";
import { FileHandle } from "$domain/handles";
import { robots } from "$domain/robots";
import { Screen, Theme, screen, selected, theme } from "$state/app.svelte";
import { audio, restore, willRestore, workspace } from "$state/blockly.svelte";
import {
audio,
canRedo,
canUndo,
restore,
willRestore,
workspace,
} from "$state/blockly.svelte";
import { popups } from "$state/popup.svelte";
import {
Mode,
Expand Down Expand Up @@ -405,8 +412,8 @@ function runPython() {

<div class="comp">
{#if $screen === Screen.WORKSPACE && $mode === Mode.BLOCKS}
<Button mode={"outlined"} icon={faUndo} onclick={undo} />
<Button mode={"outlined"} icon={faRedo} onclick={redo} />
<Button mode={"outlined"} icon={faUndo} onclick={undo} disabled={!$canUndo} />
<Button mode={"outlined"} icon={faRedo} onclick={redo} disabled={!$canRedo} />
{/if}
</div>

Expand Down
8 changes: 8 additions & 0 deletions src/lib/components/ui/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface Props {
icon?: IconDefinition | string;
onclick?: () => void;
context?: Snippet<[Writable<boolean>]>;
disabled?: boolean;
mode: "primary" | "secondary" | "outlined" | "accent";
bold?: boolean;
}
Expand All @@ -20,6 +21,7 @@ const {
context,
bold,
icon,
disabled,
}: Props = $props();
let btn: HTMLButtonElement = $state();
Expand All @@ -39,6 +41,7 @@ function onContext() {
<button
bind:this={btn}
{onclick}
{disabled}
type="button"
class="btn"
class:primary={mode === "primary"}
Expand Down Expand Up @@ -93,4 +96,9 @@ function onContext() {
font-weight: bolder;
font-size: 1.1em;
}
.btn[disabled] {
filter: opacity(.5);
cursor: unset;
}
</style>
11 changes: 10 additions & 1 deletion src/lib/components/workspace/blocks/Blocks.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
import { setLocale, setupWorkspace } from "$domain/blockly/blockly";
import { dark, light } from "$domain/blockly/theme";
import { Theme, theme } from "$state/app.svelte";
import { restore, willRestore, workspace } from "$state/blockly.svelte";
import {
canRedo,
canUndo,
restore,
willRestore,
workspace,
} from "$state/blockly.svelte";
import { code, robot } from "$state/workspace.svelte";
import { arduino } from "@leaphy-robotics/leaphy-blocks";
import { Events, WorkspaceSvg, serialization } from "blockly";
Expand Down Expand Up @@ -36,6 +42,9 @@ onMount(() => {
);
updateSizing();
$workspace.addChangeListener((event) => {
canUndo.set(get(workspace).getUndoStack().length > 0);
canRedo.set(get(workspace).getRedoStack().length > 0);
code.set(arduino.workspaceToCode($workspace));
updateSizing();
Expand Down
3 changes: 3 additions & 0 deletions src/lib/state/blockly.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ export const audio = writable<boolean>(
audio.subscribe((audio) => {
localStorage.setItem("audio", JSON.stringify(audio));
});

export const canUndo = writable<boolean>(false);
export const canRedo = writable<boolean>(false);

0 comments on commit eb8789f

Please sign in to comment.