Skip to content

Commit

Permalink
Fix formats
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Jan 15, 2024
1 parent b39c83f commit f3e072f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 69 deletions.
2 changes: 1 addition & 1 deletion examples/preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"preact": "^10.18.1"
},
"version": "0.7.2"
}
}
64 changes: 32 additions & 32 deletions examples/preact/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,24 @@ interface TodoListItemProps {

function TodoListItem({ item, setList }: TodoListItemProps): JSX.Element {
return (
<div
className={`todo-item ${item.done ? 'complete' : 'pending'}`}
>
<div className="todo-item-content">
{item.message}
</div>
<div className={`todo-item ${item.done ? 'complete' : 'pending'}`}>
<div className="todo-item-content">{item.message}</div>
<div className="todo-item-actions">
<button
type="button"
className={`todo-item-toggle ${item.done ? 'complete' : 'pending'}`}
onClick={(): void => {
setList((list) => list.map((value) => {
if (value === item) {
return {
...value,
done: !item.done,
};
}
return value;
}));
setList(list =>
list.map(value => {
if (value === item) {
return {
...value,
done: !item.done,
};
}
return value;
}),
);
}}
>
{item.done ? 'Completed' : 'Pending'}
Expand All @@ -43,7 +41,7 @@ function TodoListItem({ item, setList }: TodoListItemProps): JSX.Element {
type="button"
className="todo-item-delete"
onClick={(): void => {
setList((list) => list.filter((value) => value.id !== item.id));
setList(list => list.filter(value => value.id !== item.id));
}}
>
Delete
Expand All @@ -59,7 +57,11 @@ interface TodoListFormProps {
setList: (action: (list: TodoItem[]) => TodoItem[]) => void;
}

function TodoListForm({ setList, index, setIndex }: TodoListFormProps): JSX.Element {
function TodoListForm({
setList,
index,
setIndex,
}: TodoListFormProps): JSX.Element {
const [message, setMessage] = useState('');

return (
Expand All @@ -68,11 +70,14 @@ function TodoListForm({ setList, index, setIndex }: TodoListFormProps): JSX.Elem
onSubmit={(e): void => {
e.preventDefault();

setList((list) => [...list, {
done: false,
message,
id: index,
}]);
setList(list => [
...list,
{
done: false,
message,
id: index,
},
]);
setIndex(index + 1);
setMessage('');
}}
Expand All @@ -84,10 +89,7 @@ function TodoListForm({ setList, index, setIndex }: TodoListFormProps): JSX.Elem
setMessage((e.target as HTMLInputElement).value);
}}
/>
<button
type="submit"
disabled={message === ''}
>
<button type="submit" disabled={message === ''}>
Add
</button>
</form>
Expand All @@ -99,13 +101,11 @@ function TodoList(): JSX.Element {
const [index, setIndex] = useState(0);
return (
<>
<TodoListForm
setList={setList}
index={index}
setIndex={setIndex}
/>
<TodoListForm setList={setList} index={index} setIndex={setIndex} />
<div className="todo-list">
{list.map((item) => <TodoListItem key={item.id} item={item} setList={setList} />)}
{list.map(item => (
<TodoListItem key={item.id} item={item} setList={setList} />
))}
</div>
</>
);
Expand Down
6 changes: 3 additions & 3 deletions examples/preact/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'vite'
import preact from "@preact/preset-vite";
import { defineConfig } from 'vite';
import preact from '@preact/preset-vite';
import forgettiPlugin from 'vite-plugin-forgetti';

export default defineConfig({
Expand All @@ -13,6 +13,6 @@ export default defineConfig({
include: 'src/**/*.{ts,js,tsx,jsx}',
exclude: 'node_modules/**/*.{ts,js,tsx,jsx}',
},
})
}),
],
});
2 changes: 1 addition & 1 deletion examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
"react-dom": "^18.2.0"
},
"version": "0.7.2"
}
}
65 changes: 33 additions & 32 deletions examples/react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSX } from 'react';
import { useState } from 'react';
import './main.css';

Expand All @@ -14,26 +15,24 @@ interface TodoListItemProps {

function TodoListItem({ item, setList }: TodoListItemProps): JSX.Element {
return (
<div
className={`todo-item ${item.done ? 'complete' : 'pending'}`}
>
<div className="todo-item-content">
{item.message}
</div>
<div className={`todo-item ${item.done ? 'complete' : 'pending'}`}>
<div className="todo-item-content">{item.message}</div>
<div className="todo-item-actions">
<button
type="button"
className={`todo-item-toggle ${item.done ? 'complete' : 'pending'}`}
onClick={(): void => {
setList((list) => list.map((value) => {
if (value === item) {
return {
...value,
done: !item.done,
};
}
return value;
}));
setList(list =>
list.map(value => {
if (value === item) {
return {
...value,
done: !item.done,
};
}
return value;
}),
);
}}
>
{item.done ? 'Completed' : 'Pending'}
Expand All @@ -42,7 +41,7 @@ function TodoListItem({ item, setList }: TodoListItemProps): JSX.Element {
type="button"
className="todo-item-delete"
onClick={(): void => {
setList((list) => list.filter((value) => value.id !== item.id));
setList(list => list.filter(value => value.id !== item.id));
}}
>
Delete
Expand All @@ -58,7 +57,11 @@ interface TodoListFormProps {
setList: (action: (list: TodoItem[]) => TodoItem[]) => void;
}

function TodoListForm({ setList, index, setIndex }: TodoListFormProps): JSX.Element {
function TodoListForm({
setList,
index,
setIndex,
}: TodoListFormProps): JSX.Element {
const [message, setMessage] = useState('');

return (
Expand All @@ -67,11 +70,14 @@ function TodoListForm({ setList, index, setIndex }: TodoListFormProps): JSX.Elem
onSubmit={(e): void => {
e.preventDefault();

setList((list) => [...list, {
done: false,
message,
id: index,
}]);
setList(list => [
...list,
{
done: false,
message,
id: index,
},
]);
setIndex(index + 1);
setMessage('');
}}
Expand All @@ -83,10 +89,7 @@ function TodoListForm({ setList, index, setIndex }: TodoListFormProps): JSX.Elem
setMessage((e.target as HTMLInputElement).value);
}}
/>
<button
type="submit"
disabled={message === ''}
>
<button type="submit" disabled={message === ''}>
Add
</button>
</form>
Expand All @@ -98,13 +101,11 @@ function TodoList(): JSX.Element {
const [index, setIndex] = useState(0);
return (
<>
<TodoListForm
setList={setList}
index={index}
setIndex={setIndex}
/>
<TodoListForm setList={setList} index={index} setIndex={setIndex} />
<div className="todo-list">
{list.map((item) => <TodoListItem key={item.id} item={item} setList={setList} />)}
{list.map(item => (
<TodoListItem key={item.id} item={item} setList={setList} />
))}
</div>
</>
);
Expand Down

0 comments on commit f3e072f

Please sign in to comment.