This repository has been archived by the owner on Feb 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8226c55
commit e93f095
Showing
8 changed files
with
190 additions
and
95 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
import { Iot } from 'aws-sdk' | ||
|
||
export const updateThingAttributes = ({ | ||
iot, | ||
thingName, | ||
}: { | ||
iot: Iot | ||
thingName: string | ||
}) => async (attributes: { [key: string]: string }): Promise<void> => { | ||
await iot | ||
.updateThing({ | ||
thingName, | ||
attributePayload: { | ||
attributes: attributes, | ||
merge: true, | ||
}, | ||
}) | ||
.promise() | ||
} |
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,24 @@ | ||
import { S3 } from 'aws-sdk' | ||
import { v4 } from 'uuid' | ||
|
||
export const uploadAvatar = ({ | ||
s3, | ||
bucketName, | ||
}: { | ||
s3: S3 | ||
bucketName: string | ||
}) => async ({ avatar }: { avatar: Blob }): Promise<{ url: string }> => { | ||
const id = v4() | ||
const url = `https://${bucketName}.s3.amazonaws.com/${id}.jpg` | ||
await s3 | ||
.putObject({ | ||
Bucket: `${bucketName}`, | ||
Key: `${id}.jpg`, | ||
ContentType: avatar.type, | ||
ContentLength: avatar.size, | ||
Body: avatar, | ||
}) | ||
.promise() | ||
|
||
return { url } | ||
} |
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,29 @@ | ||
.editable { | ||
width: 100%; | ||
&.error { | ||
animation: shake 0.82s cubic-bezier(.36,.07,.19,.97) both; | ||
transform: translate3d(0, 0, 0); | ||
backface-visibility: hidden; | ||
perspective: 1000px; | ||
border-color: red; | ||
} | ||
} | ||
|
||
|
||
@keyframes shake { | ||
10%, 90% { | ||
transform: translate3d(-1px, 0, 0); | ||
} | ||
|
||
20%, 80% { | ||
transform: translate3d(2px, 0, 0); | ||
} | ||
|
||
30%, 50%, 70% { | ||
transform: translate3d(-4px, 0, 0); | ||
} | ||
|
||
40%, 60% { | ||
transform: translate3d(4px, 0, 0); | ||
} | ||
} |
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,48 @@ | ||
import React, { useState } from 'react' | ||
import classNames from 'classnames' | ||
|
||
import './Editable.scss' | ||
|
||
export const Editable = ({ | ||
text: originalText, | ||
onChange, | ||
}: { | ||
text: string | ||
onChange: (updatedText: string) => void | ||
}) => { | ||
const [editing, setEditing] = useState(false) | ||
const [input, updateInput] = useState(originalText) | ||
const [text, updateText] = useState(originalText) | ||
if (editing) { | ||
return ( | ||
<input | ||
className={classNames('editable', { error: !input.length })} | ||
type="text" | ||
value={input} | ||
autoFocus | ||
onBlur={() => { | ||
if (!input.length) { | ||
return | ||
} | ||
setEditing(false) | ||
if (input !== text) { | ||
updateText(input) | ||
onChange(input) | ||
} | ||
}} | ||
onChange={({ target: { value } }) => { | ||
updateInput(value) | ||
}} | ||
/> | ||
) | ||
} | ||
return ( | ||
<span | ||
onClick={() => { | ||
setEditing(true) | ||
}} | ||
> | ||
{text} | ||
</span> | ||
) | ||
} |