Skip to content

Commit 2af0b6e

Browse files
committed
Convertir to typescript
1 parent 3b726d6 commit 2af0b6e

22 files changed

+483
-395
lines changed
File renamed without changes.

components/pages/Feed.jsx renamed to components/pages/Feed.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@ import {
1515
import Notifications from './Notifications';
1616
import { useState } from 'react';
1717
import { notificationsOutline } from 'ionicons/icons';
18-
import { getHomeItems } from '../../store/selectors';
18+
import { selectHomeItems } from '../../store/selectors';
1919
import Store from '../../store';
2020

21-
const FeedCard = ({ title, type, text, author, authorAvatar, image }) => (
21+
type FeedCardProps = {
22+
title: string;
23+
type: string;
24+
text: string;
25+
author: string;
26+
authorAvatar: string;
27+
image: string;
28+
}
29+
30+
const FeedCard = ({ title, type, text, author, authorAvatar, image }: FeedCardProps) => (
2231
<Card className="my-4 mx-auto">
2332
<div className="h-32 w-full relative">
2433
<img className="rounded-t-xl object-cover min-w-full min-h-full max-w-full max-h-full" src={image} alt="" />
@@ -38,7 +47,7 @@ const FeedCard = ({ title, type, text, author, authorAvatar, image }) => (
3847
);
3948

4049
const Feed = () => {
41-
const homeItems = Store.useState(getHomeItems);
50+
const homeItems = Store.useState(selectHomeItems);
4251
const [showNotifications, setShowNotifications] = useState(false);
4352

4453
return (

components/pages/ListDetail.jsx renamed to components/pages/ListDetail.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ import { useParams } from 'react-router-dom';
1616
import Store from '../../store';
1717
import * as actions from '../../store/actions';
1818
import * as selectors from '../../store/selectors';
19+
import { ListItem, TodoListItem } from '../../mock';
1920

20-
const ListItems = ({ list }) => {
21+
type ListDetailParams = {
22+
listId: string;
23+
};
24+
25+
const ListItems = ({ list }: {list: TodoListItem}) => {
2126
return (
2227
<IonList>
2328
{(list?.items || []).map((item, key) => (
@@ -27,16 +32,16 @@ const ListItems = ({ list }) => {
2732
);
2833
};
2934

30-
const ListItemEntry = ({ list, item }) => (
35+
const ListItemEntry = ({ list, item }: {list: TodoListItem, item: ListItem}) => (
3136
<IonItem onClick={() => actions.setDone(list, item, !item.done)}>
3237
<IonLabel>{item.name}</IonLabel>
3338
<IonCheckbox checked={item.done || false} slot="end" />
3439
</IonItem>
3540
);
3641

37-
const ListDetail = ({ match }) => {
38-
const lists = Store.useState(selectors.getLists);
39-
const params = useParams();
42+
const ListDetail = () => {
43+
const lists = Store.useState(selectors.selectLists);
44+
const params = useParams<ListDetailParams>();
4045
const { listId } = params;
4146
const loadedList = lists.find(l => l.id === listId);
4247

@@ -47,11 +52,11 @@ const ListDetail = ({ match }) => {
4752
<IonButtons slot="start">
4853
<IonBackButton defaultHref="/tabs/lists" />
4954
</IonButtons>
50-
<IonTitle>{loadedList.name}</IonTitle>
55+
<IonTitle>{loadedList?.name}</IonTitle>
5156
</IonToolbar>
5257
</IonHeader>
5358
<IonContent>
54-
<ListItems list={loadedList} />
59+
{loadedList && <ListItems list={loadedList} />}
5560
</IonContent>
5661
</IonPage>
5762
);

components/pages/Lists.jsx renamed to components/pages/Lists.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { TodoListItem } from '../../mock';
12
import Store from '../../store';
23
import * as selectors from '../../store/selectors';
34

@@ -12,14 +13,14 @@ import {
1213
IonList,
1314
} from '@ionic/react';
1415

15-
const ListEntry = ({ list, ...props }) => (
16+
const ListEntry = ({ list }: {list: TodoListItem}) => (
1617
<IonItem routerLink={`/tabs/lists/${list.id}`} className="list-entry">
1718
<IonLabel>{list.name}</IonLabel>
1819
</IonItem>
1920
);
2021

21-
const AllLists = ({ onSelect }) => {
22-
const lists = Store.useState(selectors.getLists);
22+
const AllLists = () => {
23+
const lists = Store.useState(selectors.selectLists);
2324

2425
return (
2526
<>

components/pages/Notifications.jsx renamed to components/pages/Notifications.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import {
1212
IonLabel,
1313
} from '@ionic/react';
1414
import Store from '../../store';
15-
import { getNotifications } from '../../store/selectors';
15+
import { selectNotifications } from '../../store/selectors';
1616

1717
import { close } from 'ionicons/icons';
18+
import { NotificationItem } from '../../mock';
1819

19-
const NotificationItem = ({ notification }) => (
20+
const NotificationItem = ({ notification }: {notification: NotificationItem}) => (
2021
<IonItem>
2122
<IonLabel>{notification.title}</IonLabel>
2223
<IonNote slot="end">{notification.when}</IonNote>
@@ -26,8 +27,8 @@ const NotificationItem = ({ notification }) => (
2627
</IonItem>
2728
);
2829

29-
const Notifications = ({ open, onDidDismiss }) => {
30-
const notifications = Store.useState(getNotifications);
30+
const Notifications = ({ open, onDidDismiss }: {open: boolean, onDidDismiss: () => void}) => {
31+
const notifications = Store.useState(selectNotifications);
3132

3233
return (
3334
<IonModal isOpen={open} onDidDismiss={onDidDismiss}>

components/pages/Settings.jsx renamed to components/pages/Settings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import * as selectors from '../../store/selectors';
1515
import { setSettings } from '../../store/actions';
1616

1717
const Settings = () => {
18-
const settings = Store.useState(selectors.getSettings);
18+
const settings = Store.useState(selectors.selectSettings);
1919

2020
return (
2121
<IonPage>
File renamed without changes.

components/ui/Card.jsx renamed to components/ui/Card.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import classNames from 'classnames';
22

3-
const Card = ({ children, className, ...props }) => (
4-
<div {...props} className={classNames('max-w-xl', className)}>
3+
const Card = ({ children, className }: {children: React.ReactElement[], className: string}) => (
4+
<div className={classNames('max-w-xl', className)}>
55
<div className="bg-white shadow-md rounded-b-xl dark:bg-black">{children}</div>
66
</div>
77
);

mock/index.js renamed to mock/index.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ export const images = [
44
'/img/c3.avif',
55
];
66

7-
export const homeItems = [
7+
export type HomeItem = {
8+
id: number;
9+
title: string;
10+
type: string;
11+
text: string;
12+
author: string;
13+
authorAvatar: string;
14+
image: string;
15+
};
16+
17+
export const homeItems: HomeItem[] = [
818
{
19+
id: 1,
920
title: 'Exploring Maui',
1021
type: 'Blog',
1122
text: 'We just got back from a trip to Maui, and we had a great time...',
@@ -14,6 +25,7 @@ export const homeItems = [
1425
image: images[0],
1526
},
1627
{
28+
id: 2,
1729
title: 'Arctic Adventures',
1830
type: 'Blog',
1931
text:
@@ -23,6 +35,7 @@ export const homeItems = [
2335
image: images[1],
2436
},
2537
{
38+
id: 3,
2639
title: 'Frolicking in the Faroe Islands',
2740
type: 'Blog',
2841
text:
@@ -33,15 +46,32 @@ export const homeItems = [
3346
},
3447
];
3548

36-
export const notifications = [
37-
{ title: 'New friend request', when: '6 hr' },
38-
{ title: 'Please change your password', when: '1 day' },
39-
{ title: 'You have a new message', when: '2 weeks' },
40-
{ title: 'Welcome to the app!', when: '1 month' },
49+
export type NotificationItem = {
50+
id: number;
51+
title: string;
52+
when: string;
53+
};
54+
55+
export const notifications: NotificationItem[] = [
56+
{ id: 1, title: 'New friend request', when: '6 hr' },
57+
{ id: 2, title: 'Please change your password', when: '1 day' },
58+
{ id: 3, title: 'You have a new message', when: '2 weeks' },
59+
{ id: 4, title: 'Welcome to the app!', when: '1 month' },
4160
];
4261

62+
export type ListItem = {
63+
name: string;
64+
done?: boolean;
65+
}
66+
67+
export type TodoListItem = {
68+
name: string;
69+
id: string;
70+
items?: ListItem[];
71+
}
72+
4373
// Some fake lists
44-
export const lists = [
74+
export const lists: TodoListItem[] = [
4575
{
4676
name: 'Groceries',
4777
id: 'groceries',
@@ -60,3 +90,11 @@ export const lists = [
6090
{ name: 'Work', id: 'work', items: [{ name: 'TPS Report' }, { name: 'Set up email' }] },
6191
{ name: 'Reminders', id: 'reminders' },
6292
];
93+
94+
export type Settings = {
95+
enableNotifications: boolean;
96+
}
97+
98+
export const settings: Settings = {
99+
enableNotifications: true,
100+
}

next-env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

0 commit comments

Comments
 (0)