forked from t4d-classes/react-redux-typescript_09282020
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add solution to 18, rest client service, and modal
- Loading branch information
1 parent
73a709f
commit c877aca
Showing
11 changed files
with
150 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#modal > div { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
|
||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
|
||
background-color: rgba(150, 150, 150, 0.5); | ||
} | ||
|
||
#modal > div > p { | ||
height: 100px; | ||
width: 200px; | ||
text-align: center; | ||
background-color: navy; | ||
color: white; | ||
border: 1px solid white; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, { ReactNode } from 'react'; | ||
import { createPortal } from 'react-dom'; | ||
|
||
import './ModalDialog.css'; | ||
|
||
export type ModalDialogProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
export function ModalDialog(props: ModalDialogProps) { | ||
return createPortal( | ||
<div> | ||
<p>{props.children}</p> | ||
</div>, | ||
document.querySelector('#modal')!, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {RestClient} from "./RestClient"; | ||
|
||
import { Car } from '../models/car'; | ||
|
||
export class CarsRestClient extends RestClient<Car> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Item, ItemId } from '../models/item'; | ||
|
||
export class RestClient<T extends Item> { | ||
constructor(private baseUrl: string) {} | ||
|
||
async all() { | ||
const res = await fetch(`${this.baseUrl}`); | ||
const items = await res.json(); | ||
return items as T[]; | ||
} | ||
|
||
async append(newItem: Omit<Item, 'id'>) { | ||
const res = await fetch(`${this.baseUrl}`, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(newItem), | ||
}); | ||
|
||
const car = await res.json(); | ||
return car.id; | ||
} | ||
|
||
async replace(item: Item) { | ||
await fetch(`${this.baseUrl}/${encodeURIComponent(item.id)}`, { | ||
method: 'PUT', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(item), | ||
}); | ||
} | ||
|
||
async remove(itemId: ItemId) { | ||
await fetch(`${this.baseUrl}/${encodeURIComponent(itemId)}`, { | ||
method: 'DELETE', | ||
}); | ||
} | ||
} |