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

Feat: Allow freeform storyboard inputs after all story items shown. #83

Merged
merged 1 commit into from
May 6, 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
19 changes: 17 additions & 2 deletions web/src/app/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface AillyPageState {
instruction: string;
response: Response;
generating: boolean;
content: Content;
}

export interface StoryBook {
Expand Down Expand Up @@ -41,12 +42,25 @@ export type AillyStoreDispatch = Dispatch<{

export function makeAillyStore(dispatch: MutableRefObject<AillyStoreDispatch>) {
const story: StoryBook[] = [ROLES, TONES, BACKGROUND, OUTPUT];
story.forEach((book) => {
if (book.options.at(-1)?.slug != "custom")
book.options.push({ slug: "custom", content: "" });
});
let storyItem = -1;
let nextStoryItem = -1;
let selections: number[][] = [];
let instruction = "";
let response = { content: "" };
let generating = true;
let content: Content = {
name: "dev",
path: "/ailly/dev",
outPath: "/ailly/dev",
prompt: "",
context: {
view: false,
},
};

const reducers = {
updateState(_: AillyPageState): AillyPageState {
Expand All @@ -57,6 +71,7 @@ export function makeAillyStore(dispatch: MutableRefObject<AillyStoreDispatch>) {
storyItem,
response: { ...response },
generating,
content,
};
return newState;
},
Expand Down Expand Up @@ -90,7 +105,7 @@ export function makeAillyStore(dispatch: MutableRefObject<AillyStoreDispatch>) {
this.updateAndGenerate();
},
async generate() {
const content: Content = {
content = {
name: "dev",
outPath: "/ailly/dev",
path: "/ailly/dev",
Expand All @@ -106,7 +121,7 @@ export function makeAillyStore(dispatch: MutableRefObject<AillyStoreDispatch>) {
)
.flat()
.map((content) => ({ content, view: {} })),
view: {},
view: false,
},
};
generating = true;
Expand Down
13 changes: 12 additions & 1 deletion web/src/app/storyboard.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

.option {
--background-mix: 70%;
display: block;
display: flex;
align-items: baseline;
border-radius: var(--size-base);
box-shadow: var(--color-base) 1px 2px 5px 2px;
border: var(--color-base) solid 1.5px;
Expand All @@ -35,6 +36,16 @@
);

animation: fadeIn 1s;

& input[type="radio"] {
margin-right: var(--size-md);
}

& textarea {
width: 100%;
border: 0;
padding: var(--size-base) var(--size-md);
}
}

.option:hover,
Expand Down
75 changes: 60 additions & 15 deletions web/src/app/storyboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ export const Storyboard = (store: ReturnType<typeof useAillyPageStore>) => {
actions.select(block, opt);
}
};
}, []);
}, [timer]);

const editTimer = useRef<ReturnType<typeof globalThis.setTimeout>>();
const onEdit = useMemo(() => {
return (block: number, opt: number) => {
clearTimeout(editTimer.current);
editTimer.current = setTimeout(
() => actions.select(block, opt),
INPUT_DELAY
);
};
}, [editTimer]);

return (
<section>
Expand All @@ -40,20 +51,54 @@ export const Storyboard = (store: ReturnType<typeof useAillyPageStore>) => {
item.select == "single" ? "radio" : "checkbox";
const checked =
state.selections[block]?.includes(opt) ?? false;
return (
<li key={option.slug}>
<label htmlFor={name} className={styles.option}>
<input
type={input}
id={name}
name={item.slug}
defaultChecked={checked}
onClick={() => onChange(block, opt)}
/>{" "}
{option.content}
</label>
</li>
);
if (option.slug === "custom") {
if (state.storyItem >= state.story.length) {
return (
<li key={option.slug}>
<label htmlFor={name} className={styles.option}>
<input
type={input}
id={name}
name={item.slug}
defaultChecked={checked}
onClick={() => onChange(block, opt)}
/>
<textarea
defaultValue={option.content}
placeholder={`Write your own ${item.title}`}
onChange={(e) => {
const { value } = e.target;
if (item.options.at(-1)?.slug !== "custom") {
item.options.push({
slug: "custom",
content: value,
});
} else {
item.options.at(-1)!.content = value;
}
onEdit(block, item.options.length - 1);
}}
></textarea>
</label>
</li>
);
}
} else {
return (
<li key={option.slug}>
<label htmlFor={name} className={styles.option}>
<input
type={input}
id={name}
name={item.slug}
defaultChecked={checked}
onClick={() => onChange(block, opt)}
/>{" "}
{option.content}
</label>
</li>
);
}
})}
</ol>
</li>
Expand Down