-
Notifications
You must be signed in to change notification settings - Fork 6
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
9e65a34
commit 9915e39
Showing
10 changed files
with
227 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { Box, Button, Card, CardActions, CardContent, Divider, Link, Stack, Typography } from '@mui/material' | ||
import { Ticker, useTickerApi } from '../../api/Ticker' | ||
import useAuth from '../useAuth' | ||
import { FC, useCallback, useState } from 'react' | ||
import { useQueryClient } from '@tanstack/react-query' | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import { faBluesky } from '@fortawesome/free-brands-svg-icons' | ||
import { faGear, faPause, faPlay, faTrash } from '@fortawesome/free-solid-svg-icons' | ||
import BlueskyModalForm from './BlueskyModalForm' | ||
|
||
interface Props { | ||
ticker: Ticker | ||
} | ||
|
||
const BlueskyCard: FC<Props> = ({ ticker }) => { | ||
const { token } = useAuth() | ||
const { deleteTickerBluesky, putTickerBluesky } = useTickerApi(token) | ||
const [open, setOpen] = useState<boolean>(false) | ||
|
||
const queryClient = useQueryClient() | ||
|
||
const bluesky = ticker.bluesky | ||
|
||
const handleDisconnect = useCallback(() => { | ||
deleteTickerBluesky(ticker).finally(() => { | ||
queryClient.invalidateQueries({ queryKey: ['ticker', ticker.id] }) | ||
}) | ||
}, [deleteTickerBluesky, queryClient, ticker]) | ||
|
||
const handleToggle = useCallback(() => { | ||
putTickerBluesky({ active: !bluesky.active }, ticker).finally(() => { | ||
queryClient.invalidateQueries({ queryKey: ['ticker', ticker.id] }) | ||
}) | ||
}, [bluesky.active, putTickerBluesky, queryClient, ticker]) | ||
|
||
const profileLink = ( | ||
<Link href={'https://bsky.app/profile/' + bluesky.handle} rel="noreferrer" target="_blank"> | ||
{bluesky.handle} | ||
</Link> | ||
) | ||
|
||
return ( | ||
<Card> | ||
<CardContent> | ||
<Stack alignItems="center" direction="row" justifyContent="space-between"> | ||
<Typography component="h5" variant="h5"> | ||
<FontAwesomeIcon icon={faBluesky} /> Bluesky | ||
</Typography> | ||
<Button onClick={() => setOpen(true)} size="small" startIcon={<FontAwesomeIcon icon={faGear} />}> | ||
Configure | ||
</Button> | ||
</Stack> | ||
</CardContent> | ||
<Divider variant="middle" /> | ||
<CardContent> | ||
{bluesky.connected ? ( | ||
<Box> | ||
<Typography variant="body2">You are connected with Bluesky.</Typography> | ||
<Typography variant="body2">Your Profile: {profileLink}</Typography> | ||
</Box> | ||
) : ( | ||
<Box> | ||
<Typography variant="body2"> | ||
You are not connected with Bluesky. New messages will not be published to your account and old messages can not be deleted anymore. | ||
</Typography> | ||
</Box> | ||
)} | ||
</CardContent> | ||
{bluesky.connected ? ( | ||
<CardActions> | ||
{bluesky.active ? ( | ||
<Button onClick={handleToggle} size="small" startIcon={<FontAwesomeIcon icon={faPause} />}> | ||
Disable | ||
</Button> | ||
) : ( | ||
<Button onClick={handleToggle} size="small" startIcon={<FontAwesomeIcon icon={faPlay} />}> | ||
Enable | ||
</Button> | ||
)} | ||
<Button onClick={handleDisconnect} size="small" startIcon={<FontAwesomeIcon icon={faTrash} />}> | ||
Disconnect | ||
</Button> | ||
</CardActions> | ||
) : null} | ||
<BlueskyModalForm open={open} onClose={() => setOpen(false)} ticker={ticker} /> | ||
</Card> | ||
) | ||
} | ||
|
||
export default BlueskyCard |
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,73 @@ | ||
import { FC } from 'react' | ||
import { Ticker, TickerBlueskyFormData, useTickerApi } from '../../api/Ticker' | ||
import useAuth from '../useAuth' | ||
import { useForm } from 'react-hook-form' | ||
import { useQueryClient } from '@tanstack/react-query' | ||
import { Alert, Checkbox, FormControlLabel, FormGroup, Grid, TextField, Typography } from '@mui/material' | ||
|
||
interface Props { | ||
callback: () => void | ||
ticker: Ticker | ||
} | ||
|
||
const BlueskyForm: FC<Props> = ({ callback, ticker }) => { | ||
const bluesky = ticker.bluesky | ||
const { token } = useAuth() | ||
const { putTickerBluesky } = useTickerApi(token) | ||
const { | ||
formState: { errors }, | ||
handleSubmit, | ||
register, | ||
setError, | ||
} = useForm<TickerBlueskyFormData>({ | ||
defaultValues: { | ||
active: bluesky.active, | ||
handle: bluesky.handle, | ||
appKey: bluesky.appKey, | ||
}, | ||
}) | ||
const queryClient = useQueryClient() | ||
|
||
const onSubmit = handleSubmit(data => { | ||
putTickerBluesky(data, ticker).then(response => { | ||
if (response.status == 'error') { | ||
setError('root.authenticationFailed', { message: 'Authentication failed' }) | ||
} else { | ||
queryClient.invalidateQueries({ queryKey: ['ticker', ticker.id] }) | ||
callback() | ||
} | ||
}) | ||
}) | ||
|
||
return ( | ||
<form id="configureBluesky" onSubmit={onSubmit}> | ||
<Grid columnSpacing={{ xs: 1, sm: 2, md: 3 }} container rowSpacing={1}> | ||
<Grid item xs={12}> | ||
<Typography>You need to create a application password in Bluesky.</Typography> | ||
</Grid> | ||
{errors.root?.authenticationFailed && ( | ||
<Grid item xs={12}> | ||
<Alert severity="error">{errors.root.authenticationFailed.message}</Alert> | ||
</Grid> | ||
)} | ||
<Grid item xs={12}> | ||
<FormGroup> | ||
<FormControlLabel control={<Checkbox {...register('active')} defaultChecked={ticker.bluesky.active} />} label="Active" /> | ||
</FormGroup> | ||
</Grid> | ||
<Grid item xs={12}> | ||
<FormGroup> | ||
<TextField {...register('handle')} defaultValue={ticker.bluesky.handle} label="Handle" placeholder="handle.bsky.social" required /> | ||
</FormGroup> | ||
</Grid> | ||
<Grid item xs={12}> | ||
<FormGroup> | ||
<TextField {...register('appKey')} defaultValue={ticker.bluesky.appKey} label="Application Password" required type="password" /> | ||
</FormGroup> | ||
</Grid> | ||
</Grid> | ||
</form> | ||
) | ||
} | ||
|
||
export default BlueskyForm |
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,20 @@ | ||
import { FC } from 'react' | ||
import { Ticker } from '../../api/Ticker' | ||
import Modal from '../common/Modal' | ||
import BlueskyForm from './BlueskyForm' | ||
|
||
interface Props { | ||
onClose: () => void | ||
open: boolean | ||
ticker: Ticker | ||
} | ||
|
||
const BlueskyModalForm: FC<Props> = ({ onClose, open, ticker }) => { | ||
return ( | ||
<Modal maxWidth="sm" onClose={onClose} open={open} submitForm="configureBluesky" title="Configure Bluesky"> | ||
<BlueskyForm callback={onClose} ticker={ticker} /> | ||
</Modal> | ||
) | ||
} | ||
|
||
export default BlueskyModalForm |
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