Skip to content

Commit

Permalink
Merge pull request #562 from gitroomhq/feat/farcaster
Browse files Browse the repository at this point in the history
Added warpcast
  • Loading branch information
nevo-david authored Jan 18, 2025
2 parents 2b8e0bc + 4fb674a commit 1611f00
Show file tree
Hide file tree
Showing 15 changed files with 4,454 additions and 2,005 deletions.
Binary file added apps/frontend/public/icons/platforms/wrapcast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions apps/frontend/src/components/launches/add.provider.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useVariables } from '@gitroom/react/helpers/variable.context';
import { useToaster } from '@gitroom/react/toaster/toaster';
import { object, string } from 'yup';
import { yupResolver } from '@hookform/resolvers/yup';
import { web3List } from '@gitroom/frontend/components/launches/web3/web3.list';

const resolver = classValidatorResolver(ApiKeyDto);

Expand Down Expand Up @@ -307,6 +308,7 @@ export const AddProviderComponent: FC<{
name: string;
toolTip?: string;
isExternal: boolean;
isWeb3: boolean;
customFields?: Array<{
key: string;
label: string;
Expand All @@ -327,6 +329,7 @@ export const AddProviderComponent: FC<{
(
identifier: string,
isExternal: boolean,
isWeb3: boolean,
customFields?: Array<{
key: string;
label: string;
Expand All @@ -336,6 +339,32 @@ export const AddProviderComponent: FC<{
}>
) =>
async () => {
const openWeb3 = async () => {
const { component: Web3Providers } = web3List.find(
(item) => item.identifier === identifier
)!;

const { url } = await (
await fetch(`/integrations/social/${identifier}`)
).json();

modal.openModal({
title: '',
withCloseButton: false,
classNames: {
modal: 'bg-transparent text-textColor',
},
children: (
<Web3Providers
onComplete={(code, newState) => {
window.location.href = `/integrations/social/${identifier}?code=${code}&state=${newState}`;
}}
nonce={url}
/>
),
});
return;
};
const gotoIntegration = async (externalUrl?: string) => {
const { url, err } = await (
await fetch(
Expand All @@ -352,6 +381,11 @@ export const AddProviderComponent: FC<{
window.location.href = url;
};

if (isWeb3) {
openWeb3();
return;
}

if (isExternal) {
modal.closeAll();

Expand Down Expand Up @@ -443,6 +477,7 @@ export const AddProviderComponent: FC<{
onClick={getSocialLink(
item.identifier,
item.isExternal,
item.isWeb3,
item.customFields
)}
{...(!!item.toolTip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import SlackProvider from '@gitroom/frontend/components/launches/providers/slack
import MastodonProvider from '@gitroom/frontend/components/launches/providers/mastodon/mastodon.provider';
import BlueskyProvider from '@gitroom/frontend/components/launches/providers/bluesky/bluesky.provider';
import LemmyProvider from '@gitroom/frontend/components/launches/providers/lemmy/lemmy.provider';
import WarpcastProvider from '@gitroom/frontend/components/launches/providers/warpcast/warpcast.provider';

export const Providers = [
{identifier: 'devto', component: DevtoProvider},
Expand All @@ -40,6 +41,7 @@ export const Providers = [
{identifier: 'mastodon', component: MastodonProvider},
{identifier: 'bluesky', component: BlueskyProvider},
{identifier: 'lemmy', component: LemmyProvider},
{identifier: 'wrapcast', component: WarpcastProvider},
];


Expand Down
152 changes: 152 additions & 0 deletions apps/frontend/src/components/launches/providers/warpcast/subreddit.tsx
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>
);
};
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
);
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;
}
Loading

0 comments on commit 1611f00

Please sign in to comment.