-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #562 from gitroomhq/feat/farcaster
Added warpcast
- Loading branch information
Showing
15 changed files
with
4,454 additions
and
2,005 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
152 changes: 152 additions & 0 deletions
152
apps/frontend/src/components/launches/providers/warpcast/subreddit.tsx
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,152 @@ | ||
import { FC, FormEvent, useCallback, useState } from 'react'; | ||
import { useCustomProviderFunction } from '@gitroom/frontend/components/launches/helpers/use.custom.provider.function'; | ||
import { Input } from '@gitroom/react/form/input'; | ||
import { useDebouncedCallback } from 'use-debounce'; | ||
import { useWatch } from 'react-hook-form'; | ||
import { useSettings } from '@gitroom/frontend/components/launches/helpers/use.values'; | ||
|
||
export const Subreddit: FC<{ | ||
onChange: (event: { | ||
target: { | ||
name: string; | ||
value: { | ||
id: string; | ||
subreddit: string; | ||
title: string; | ||
name: string; | ||
url: string; | ||
body: string; | ||
media: any[]; | ||
}; | ||
}; | ||
}) => void; | ||
name: string; | ||
}> = (props) => { | ||
const { onChange, name } = props; | ||
|
||
const state = useSettings(); | ||
const split = name.split('.'); | ||
const [loading, setLoading] = useState(false); | ||
// @ts-ignore | ||
const errors = state?.formState?.errors?.[split?.[0]]?.[split?.[1]]?.value; | ||
|
||
const [results, setResults] = useState([]); | ||
const func = useCustomProviderFunction(); | ||
const value = useWatch({ name }); | ||
const [searchValue, setSearchValue] = useState(''); | ||
|
||
const setResult = (result: { id: string; name: string }) => async () => { | ||
setLoading(true); | ||
setSearchValue(''); | ||
|
||
onChange({ | ||
target: { | ||
name, | ||
value: { | ||
id: String(result.id), | ||
subreddit: result.name, | ||
title: '', | ||
name: '', | ||
url: '', | ||
body: '', | ||
media: [], | ||
}, | ||
}, | ||
}); | ||
|
||
setLoading(false); | ||
}; | ||
|
||
const setTitle = useCallback( | ||
(e: any) => { | ||
onChange({ | ||
target: { | ||
name, | ||
value: { | ||
...value, | ||
title: e.target.value, | ||
}, | ||
}, | ||
}); | ||
}, | ||
[value] | ||
); | ||
|
||
const setURL = useCallback( | ||
(e: any) => { | ||
onChange({ | ||
target: { | ||
name, | ||
value: { | ||
...value, | ||
url: e.target.value, | ||
}, | ||
}, | ||
}); | ||
}, | ||
[value] | ||
); | ||
|
||
const search = useDebouncedCallback( | ||
useCallback(async (e: FormEvent<HTMLInputElement>) => { | ||
// @ts-ignore | ||
setResults([]); | ||
// @ts-ignore | ||
if (!e.target.value) { | ||
return; | ||
} | ||
// @ts-ignore | ||
const results = await func.get('subreddits', { word: e.target.value }); | ||
// @ts-ignore | ||
setResults(results); | ||
}, []), | ||
500 | ||
); | ||
|
||
return ( | ||
<div className="bg-primary p-[20px]"> | ||
{value?.subreddit ? ( | ||
<> | ||
<Input | ||
error={errors?.subreddit?.message} | ||
disableForm={true} | ||
value={value.subreddit} | ||
readOnly={true} | ||
label="Channel" | ||
name="subreddit" | ||
/> | ||
</> | ||
) : ( | ||
<div className="relative"> | ||
<Input | ||
placeholder="Channel" | ||
name="search" | ||
label="Search Channel" | ||
readOnly={loading} | ||
value={searchValue} | ||
error={errors?.message} | ||
disableForm={true} | ||
onInput={async (e) => { | ||
// @ts-ignore | ||
setSearchValue(e.target.value); | ||
await search(e); | ||
}} | ||
/> | ||
{!!results.length && !loading && ( | ||
<div className="z-[400] w-full absolute bg-input -mt-[20px] outline-none border-fifth border cursor-pointer"> | ||
{results.map((r: { id: string; name: string }) => ( | ||
<div | ||
onClick={setResult(r)} | ||
key={r.id} | ||
className="px-[16px] py-[5px] hover:bg-secondary" | ||
> | ||
{r.name} | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; |
65 changes: 65 additions & 0 deletions
65
apps/frontend/src/components/launches/providers/warpcast/warpcast.provider.tsx
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,65 @@ | ||
import { withProvider } from '@gitroom/frontend/components/launches/providers/high.order.provider'; | ||
import { FC, useCallback } from 'react'; | ||
import { useSettings } from '@gitroom/frontend/components/launches/helpers/use.values'; | ||
import { useFieldArray } from 'react-hook-form'; | ||
import { deleteDialog } from '@gitroom/react/helpers/delete.dialog'; | ||
import { Button } from '@gitroom/react/form/button'; | ||
import { Subreddit } from './subreddit'; | ||
|
||
const WrapcastProvider: FC = () => { | ||
const { register, control } = useSettings(); | ||
const { fields, append, remove } = useFieldArray({ | ||
control, // control props comes from useForm (optional: if you are using FormContext) | ||
name: 'subreddit', // unique name for your Field Array | ||
}); | ||
|
||
const addField = useCallback(() => { | ||
append({}); | ||
}, [fields, append]); | ||
|
||
const deleteField = useCallback( | ||
(index: number) => async () => { | ||
if ( | ||
!(await deleteDialog('Are you sure you want to delete this Subreddit?')) | ||
) | ||
return; | ||
remove(index); | ||
}, | ||
[fields, remove] | ||
); | ||
|
||
return ( | ||
<> | ||
<div className="flex flex-col gap-[20px] mb-[20px]"> | ||
{fields.map((field, index) => ( | ||
<div key={field.id} className="flex flex-col relative"> | ||
<div | ||
onClick={deleteField(index)} | ||
className="absolute -left-[10px] justify-center items-center flex -top-[10px] w-[20px] h-[20px] bg-red-600 rounded-full text-textColor" | ||
> | ||
x | ||
</div> | ||
<Subreddit {...register(`subreddit.${index}.value`)} /> | ||
</div> | ||
))} | ||
</div> | ||
<Button onClick={addField}>Add Channel</Button> | ||
</> | ||
); | ||
}; | ||
|
||
export default withProvider( | ||
WrapcastProvider, | ||
undefined, | ||
undefined, | ||
async (list) => { | ||
if ( | ||
list.some((item) => item.some((field) => field.path.indexOf('mp4') > -1)) | ||
) { | ||
return 'Warpcast can only accept images'; | ||
} | ||
|
||
return true; | ||
}, | ||
3000 | ||
); |
81 changes: 81 additions & 0 deletions
81
apps/frontend/src/components/launches/web3/providers/wrapcaster.provider.tsx
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,81 @@ | ||
'use client'; | ||
import '@neynar/react/dist/style.css'; | ||
import React, { FC, useMemo, useState, useCallback, useEffect } from 'react'; | ||
import { Web3ProviderInterface } from '@gitroom/frontend/components/launches/web3/web3.provider.interface'; | ||
import { useVariables } from '@gitroom/react/helpers/variable.context'; | ||
import { TopTitle } from '@gitroom/frontend/components/launches/helpers/top.title.component'; | ||
import { useModals } from '@mantine/modals'; | ||
import { LoadingComponent } from '@gitroom/frontend/components/layout/loading'; | ||
import { NeynarAuthButton, NeynarContextProvider, Theme, useNeynarContext } from '@neynar/react'; | ||
import { INeynarAuthenticatedUser } from '@neynar/react/dist/types/common'; | ||
|
||
export const WrapcasterProvider: FC<Web3ProviderInterface> = (props) => { | ||
const [id, state] = props.nonce.split('||'); | ||
const modal = useModals(); | ||
const [hide, setHide] = useState(false); | ||
|
||
const auth = useCallback((params: { user: INeynarAuthenticatedUser }) => { | ||
setHide(true); | ||
return props.onComplete(Buffer.from(JSON.stringify(params.user)).toString('base64'), state); | ||
}, []); | ||
|
||
return ( | ||
<NeynarContextProvider | ||
settings={{ | ||
clientId: id || '', | ||
defaultTheme: Theme.Dark, | ||
// eventsCallbacks: { | ||
// onAuthSuccess: (params: { user: INeynarAuthenticatedUser }) => { | ||
// auth(params); | ||
// }, | ||
// }, | ||
}} | ||
> | ||
<div className="rounded-[4px] border border-customColor6 bg-sixth px-[16px] pb-[16px] relative w-full"> | ||
<TopTitle title={`Add Wrapcast`} /> | ||
<button | ||
className="outline-none absolute right-[20px] top-[20px] mantine-UnstyledButton-root mantine-ActionIcon-root hover:bg-tableBorder cursor-pointer mantine-Modal-close mantine-1dcetaa" | ||
type="button" | ||
onClick={() => modal.closeAll()} | ||
> | ||
<svg | ||
viewBox="0 0 15 15" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="16" | ||
height="16" | ||
> | ||
<path | ||
d="M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z" | ||
fill="currentColor" | ||
fillRule="evenodd" | ||
clipRule="evenodd" | ||
></path> | ||
</svg> | ||
</button> | ||
<div className="justify-center items-center flex"> | ||
{hide ? ( | ||
<div className="justify-center items-center flex -mt-[90px]"> | ||
<LoadingComponent width={100} height={100} /> | ||
</div> | ||
) : ( | ||
<div className="justify-center items-center flex py-[20px]"> | ||
<Logged onSuccess={auth} /> | ||
<NeynarAuthButton className="right-4 top-4" /> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
</NeynarContextProvider> | ||
); | ||
}; | ||
|
||
export const Logged: FC<{onSuccess: (params: {user: INeynarAuthenticatedUser}) => void}> = (props) => { | ||
const context = useNeynarContext(); | ||
useEffect(() => { | ||
if (context.isAuthenticated && context.user) { | ||
props.onSuccess({ user: context.user }); | ||
} | ||
}, [context.isAuthenticated]); | ||
return null; | ||
} |
Oops, something went wrong.