Skip to content

Commit

Permalink
optimize inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
kubk committed Nov 17, 2023
1 parent 6028ab5 commit 42c9883
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export const useMacTabNavigationFix = () => {
// Shift + Tab was pressed
// @ts-expect-error
inputs[currentIndex - 1].focus();
} else if (!event.shiftKey && currentIndex >= 0 && currentIndex < inputs.length - 1) {
} else if (
!event.shiftKey &&
currentIndex >= 0 &&
currentIndex < inputs.length - 1
) {
// Only Tab was pressed
// @ts-expect-error
inputs[currentIndex + 1].focus();
Expand Down
6 changes: 3 additions & 3 deletions src/screens/deck-form/card-form-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export const CardFormView = observer((props: Props) => {
>
<h3 className={css({ textAlign: "center" })}>Add card</h3>
<Label text={"Front"} isRequired>
<Input {...cardForm.front.props} rows={5} type={"textarea"} />
<Input field={cardForm.front} rows={5} type={"textarea"} />
</Label>

<Label text={"Back"} isRequired>
<Input {...cardForm.back.props} rows={5} type={"textarea"} />
<Input field={cardForm.back} rows={5} type={"textarea"} />
</Label>

<Label text={"Example / Note"}>
<Input {...cardForm.example.props} rows={3} type={"textarea"} />
<Input field={cardForm.example} rows={3} type={"textarea"} />
</Label>
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions src/screens/deck-form/deck-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useMount } from "../../lib/react/use-mount.ts";
import { useBackButton } from "../../lib/telegram/use-back-button.tsx";
import { useTelegramProgress } from "../../lib/telegram/use-telegram-progress.tsx";
import { assert } from "../../lib/typescript/assert.ts";
import { useMacTabNavigationFix } from "../useMacTabNavigationFix.tsx";
import { useMacTabNavigationFix } from "../../lib/keyboard/useMacTabNavigationFix.tsx";

export const DeckForm = observer(() => {
const deckFormStore = useDeckFormStore();
Expand Down Expand Up @@ -49,12 +49,12 @@ export const DeckForm = observer(() => {
{screen.deckId ? "Edit deck" : "Add deck"}
</h3>
<Label text={"Title"} isRequired>
<Input {...deckFormStore.form.title.props} />
<Input field={deckFormStore.form.title} />
</Label>

<Label text={"Description"}>
<Input
{...deckFormStore.form.description.props}
field={deckFormStore.form.description}
rows={5}
type={"textarea"}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/deck-form/quick-add-card-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useMainButton } from "../../lib/telegram/use-main-button.tsx";
import { useBackButton } from "../../lib/telegram/use-back-button.tsx";
import { QuickAddCardFormStore } from "../../store/quick-add-card-form-store.ts";
import { useTelegramProgress } from "../../lib/telegram/use-telegram-progress.tsx";
import { useMacTabNavigationFix } from "../useMacTabNavigationFix.tsx";
import { useMacTabNavigationFix } from "../../lib/keyboard/useMacTabNavigationFix.tsx";

export const QuickAddCardForm = observer(() => {
const [quickAddCardStore] = useState(() => new QuickAddCardFormStore());
Expand Down
2 changes: 1 addition & 1 deletion src/screens/shared/version-warning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { css } from "@emotion/css";
import { theme } from "../../ui/theme.tsx";

export const VersionWarning = () => {
if (WebApp.isVersionAtLeast('6.1')) {
if (WebApp.isVersionAtLeast("6.1")) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/screens/user-settings/settings-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const SettingsRow = observer((props: Props) => {
backgroundColor: theme.secondaryBgColor,
borderRadius: theme.borderRadius,
height: 48,
boxSizing: 'border-box',
boxSizing: "border-box",
padding: 12,
display: "flex",
justifyContent: "space-between",
Expand Down
10 changes: 6 additions & 4 deletions src/screens/user-settings/user-settings-main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { theme } from "../../ui/theme.tsx";
import { Select } from "../../ui/select.tsx";
import { Hint } from "../../ui/hint.tsx";
import { css } from "@emotion/css";
import { useBackButton } from "../../lib/telegram/use-back-button.tsx";
import { screenStore } from "../../store/screen-store.ts";

export const timeRanges = generateTimeRange();

Expand All @@ -28,6 +30,9 @@ export const UserSettingsMain = observer(() => {
() => userSettingsStore.isSaveVisible,
);

useBackButton(() => {
screenStore.go({ type: "main" });
});
useTelegramProgress(() => userSettingsStore.isSending);

if (deckListStore.myInfo?.state !== "fulfilled") {
Expand Down Expand Up @@ -83,10 +88,7 @@ export const UserSettingsMain = observer(() => {
</SettingsRow>
)}

<Hint>
⭐ Daily reminders help you keep up with your reviews, making it
easier for you to remember the information
</Hint>
<Hint>⭐ Daily reminders will help you remember to repeat cards</Hint>
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/store/deck-form-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ vi.mock("./screen-store", () => {
screenStore: {
screen: {
type: "deckForm",
deckFormId: 1,
deckId: 1,
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/store/deck-form-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const createDeckTitleField = (value: string) => {
);
};

const createCardSideField = (value: string) => {
export const createCardSideField = (value: string) => {
return new TextField(value, validators.required());
};

Expand Down
10 changes: 7 additions & 3 deletions src/store/quick-add-card-form-store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { CardFormType, createDeckTitleField } from "./deck-form-store.ts";
import {
CardFormType,
createCardSideField,
createDeckTitleField,

Check failure on line 4 in src/store/quick-add-card-form-store.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'createDeckTitleField' is defined but never used
} from "./deck-form-store.ts";
import { action, makeAutoObservable } from "mobx";
import {
formTouchAll,
Expand All @@ -16,8 +20,8 @@ import { deckListStore } from "./deck-list-store.ts";

export class QuickAddCardFormStore {
form: CardFormType = {
back: createDeckTitleField(""),
front: createDeckTitleField(""),
back: createCardSideField(""),
front: createCardSideField(""),
example: new TextField(""),
};
isSending = false;
Expand Down
17 changes: 8 additions & 9 deletions src/ui/input.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { ChangeEvent } from "react";
import { css } from "@emotion/css";
import { theme } from "./theme.tsx";
import { TextField } from "../lib/mobx-form/mobx-form.ts";
import { observer } from "mobx-react-lite";

interface Props {
value: string;
placeholder?: string;
onChange: (value: string) => void;
type?: "input" | "textarea";
isTouched?: boolean;
onBlur: () => void;
error?: string;
field: TextField<string>;
rows?: number;
}

export const Input = (props: Props) => {
const { onChange, value, placeholder, type, rows, isTouched, error, onBlur } =
props;
export const Input = observer((props: Props) => {
const { field, placeholder, type, rows } = props;
const { onChange, value, isTouched, error, onBlur } = field.props;

const handleInputChange = (
event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
) => {
Expand Down Expand Up @@ -58,4 +57,4 @@ export const Input = (props: Props) => {
) : null}
</div>
);
};
});

0 comments on commit 42c9883

Please sign in to comment.