Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: gray out undo/redo #54

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);