Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Plugin Logic to the Talawa Mobile Web App #976

Merged
merged 35 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
326c166
Add/ test for OrgPost.tsx
SiddheshKukade Feb 21, 2023
401b830
Merge branch 'develop' of https://github.com/SiddheshKukade/talawa-ad…
SiddheshKukade Apr 13, 2023
242d84c
fix: org post back to default
SiddheshKukade Apr 13, 2023
1d39563
Merge branch 'PalisadoesFoundation:develop' into develop
SiddheshKukade May 2, 2023
64110c9
Merge branch 'PalisadoesFoundation:develop' into develop
SiddheshKukade Jun 16, 2023
618edfc
Merge branch 'PalisadoesFoundation:develop' into develop
SiddheshKukade Jul 30, 2023
e4ee0a9
Added Dialog 2
SiddheshKukade Aug 4, 2023
38ce087
Updated Dialog UI
SiddheshKukade Aug 8, 2023
626d594
Removed Extra code
SiddheshKukade Aug 8, 2023
023c3ba
Updated Plugin store
SiddheshKukade Aug 8, 2023
24133fb
fix: warnings and solves #951 & #948
SiddheshKukade Aug 8, 2023
0dbc5c5
fix: warnings and solves #951 & #948
SiddheshKukade Aug 8, 2023
6856a13
fix: warnings and solves #951 & #948
SiddheshKukade Aug 8, 2023
8bb727f
Merge branch 'develop' into develop
SiddheshKukade Aug 19, 2023
419be97
Fix: UI Redesign
SiddheshKukade Aug 25, 2023
21427a3
fix: merge
SiddheshKukade Aug 25, 2023
5ed7867
fix
SiddheshKukade Aug 25, 2023
634bb94
Merge branch 'develop' into develop
SiddheshKukade Aug 30, 2023
6149b8b
Update AddOnStore.tsx
SiddheshKukade Aug 30, 2023
0661247
Fixed Merge Errors
SiddheshKukade Aug 30, 2023
4577c1d
Add test: for OrgEntry
SiddheshKukade Aug 30, 2023
2338ef3
Test 3
SiddheshKukade Aug 30, 2023
49fed8b
fix test 4
SiddheshKukade Aug 30, 2023
97dd714
Merge branch 'PalisadoesFoundation:develop' into develop
SiddheshKukade Sep 10, 2023
2496c02
Merge branch 'PalisadoesFoundation:develop' into develop
SiddheshKukade Sep 21, 2023
a8a73a9
chores: version changes
SiddheshKukade Sep 21, 2023
cdbe00d
Merge branch 'develop' of https://github.com/SiddheshKukade/talawa-ad…
SiddheshKukade Sep 21, 2023
3adab15
Add: Initial Websocket setup on talawa mobile web
SiddheshKukade Sep 21, 2023
e44817c
Add: plugin logic
SiddheshKukade Sep 23, 2023
b76db4d
Add: plugin logic
SiddheshKukade Sep 23, 2023
fca3778
removed extra
SiddheshKukade Sep 23, 2023
8d8bb56
removed extra
SiddheshKukade Sep 23, 2023
7c8a2dd
Added: Tests
SiddheshKukade Sep 24, 2023
e1fe027
Merge branch 'develop' into develop
SiddheshKukade Oct 8, 2023
00360d6
fix
SiddheshKukade Oct 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"flag-icons": "^6.6.6",
"graphql": "^15.5.1",
"graphql-tag": "^2.12.6",
"graphql-ws": "^5.14.0",
"i18next": "^21.8.14",
"i18next-browser-languagedetector": "^6.1.4",
"i18next-http-backend": "^1.4.1",
Expand Down
2 changes: 2 additions & 0 deletions src/Constant/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export const AUTH_TOKEN = '';
export const BACKEND_URL = process.env.REACT_APP_TALAWA_URL;
export const RECAPTCHA_SITE_KEY = process.env.REACT_APP_RECAPTCHA_SITE_KEY;
export const REACT_APP_USE_RECAPTCHA = process.env.REACT_APP_USE_RECAPTCHA;
export const REACT_APP_BACKEND_WEBSOCKET_URL: string =
process.env.REACT_APP_BACKEND_WEBSOCKET_URL || '';
11 changes: 11 additions & 0 deletions src/GraphQl/Mutations/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,14 @@ export const UNLIKE_COMMENT = gql`
}
}
`;
//Plugin WebSocket listner
export const PLUGIN_SUBSCRIPTION = gql`
subscription onPluginUpdate {
onPluginUpdate {
pluginName
_id
pluginDesc
uninstalledOrgs
}
}
`;
122 changes: 92 additions & 30 deletions src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@
import PermIdentityIcon from '@mui/icons-material/PermIdentity';
import LanguageIcon from '@mui/icons-material/Language';
import { useTranslation } from 'react-i18next';
import { useQuery } from '@apollo/client';
import { useQuery, useSubscription } from '@apollo/client';
import { USER_ORGANIZATION_CONNECTION } from 'GraphQl/Queries/Queries';
import getOrganizationId from 'utils/getOrganizationId';
import type { DropDirection } from 'react-bootstrap/esm/DropdownContext';
import { Link, useHistory } from 'react-router-dom';

import { PLUGIN_SUBSCRIPTION } from 'GraphQl/Mutations/mutations';
interface InterfaceNavbarProps {
currentPage: string | null;
}

type Plugin = {
pluginName: string;

alias: string;
link: string;
translated: string;
view: boolean;
};
function organizationNavbar(props: InterfaceNavbarProps): JSX.Element {
const { t } = useTranslation('translation', {
keyPrefix: 'userNavbar',
Expand Down Expand Up @@ -54,11 +62,76 @@
}, [data]);

const homeLink = `/user/organization/id=${organizationId}`;
const peopleLink = `/user/people/id=${organizationId}`;
const eventsLink = `/user/events/id=${organizationId}`;
const chatLink = `/user/chat/id=${organizationId}`;
const donationLink = `/user/donate/id=${organizationId}`;
let plugins: Plugin[] = [
{
pluginName: 'People',
alias: 'people',
link: `/user/people/id=${organizationId}`,
translated: t('people'),
view: true,
},
{
pluginName: 'Events',
alias: 'events',
link: `/user/events/id=${organizationId}`,
translated: t('events'),
view: true,
},
{
pluginName: 'Donation',
alias: 'donate',
link: `/user/donate/id=${organizationId}`,
translated: t('donate'),
view: true,
},
{
pluginName: 'Chats',
alias: 'chat',
link: `/user/chat/id=${organizationId}`,
translated: t('chat'),
view: true,
},
];
if (localStorage.getItem('talawaPlugins')) {
const talawaPlugins: string = localStorage.getItem('talawaPlugins') || '{}';
plugins = JSON.parse(talawaPlugins);

Check warning on line 97 in src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx#L97

Added line #L97 was not covered by tests
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { data: updatedPluginData, loading: _loadingSub } = useSubscription(
PLUGIN_SUBSCRIPTION
// { variables: { } }
);
function getPluginIndex(pluginName: string, pluginsArray: Plugin[]): number {
for (let i = 0; i < pluginsArray.length; i++) {

Check warning on line 105 in src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx#L104-L105

Added lines #L104 - L105 were not covered by tests
if (pluginsArray[i].pluginName === pluginName) {
return i; // Return the index of the matching object

Check warning on line 107 in src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx#L107

Added line #L107 was not covered by tests
}
}
return -1; // Return -1 if not found

Check warning on line 110 in src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx#L110

Added line #L110 was not covered by tests
}

if (updatedPluginData != undefined) {
console.log('Update received');
console.log(updatedPluginData.onPluginUpdate.pluginName);

Check warning on line 115 in src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx#L114-L115

Added lines #L114 - L115 were not covered by tests

const pluginName = updatedPluginData.onPluginUpdate.pluginName;
const uninstalledOrgs = updatedPluginData.onPluginUpdate.uninstalledOrgs;
const pluginIndexToRemove = getPluginIndex(pluginName, plugins);

Check warning on line 119 in src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx#L117-L119

Added lines #L117 - L119 were not covered by tests
if (uninstalledOrgs.includes(organizationId)) {
if (pluginIndexToRemove != -1) {
plugins[pluginIndexToRemove].view = false;
localStorage.setItem('talawaPlugins', JSON.stringify(plugins));
console.log(`Plugin ${pluginName} has been removed.`);
} else {
console.log(`Plugin ${pluginName} is not present.`);

Check warning on line 126 in src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx#L122-L126

Added lines #L122 - L126 were not covered by tests
}
} else {

Check warning on line 128 in src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx#L128

Added line #L128 was not covered by tests
if (pluginIndexToRemove != -1) {
plugins[pluginIndexToRemove].view = true;
localStorage.setItem('talawaPlugins', JSON.stringify(plugins));

Check warning on line 131 in src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx#L130-L131

Added lines #L130 - L131 were not covered by tests
}
}
}
return (
<Navbar expand={'md'} variant="dark" className={`${styles.colorPrimary}`}>
<Container fluid>
Expand Down Expand Up @@ -88,30 +161,19 @@
>
{t('home')}
</Nav.Link>
<Nav.Link
active={props.currentPage === 'events'}
onClick={(): void => history.push(eventsLink)}
>
{t('events')}
</Nav.Link>
<Nav.Link
active={props.currentPage === 'people'}
onClick={(): void => history.push(peopleLink)}
>
{t('people')}
</Nav.Link>
<Nav.Link
active={props.currentPage === 'chat'}
onClick={(): void => history.push(chatLink)}
>
{t('chat')}
</Nav.Link>
<Nav.Link
active={props.currentPage === 'donate'}
onClick={(): void => history.push(donationLink)}
>
{t('donate')}
</Nav.Link>

{plugins.map(
(plugin, idx) =>
plugin.view && (
<Nav.Link
active={props.currentPage == plugin.alias}
onClick={(): void => history.push(plugin.link)}

Check warning on line 170 in src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/UserPortal/OrganizationNavbar/OrganizationNavbar.tsx#L170

Added line #L170 was not covered by tests
key={idx}
>
{plugin.translated}
</Nav.Link>
)
)}
</Nav>
<Navbar.Collapse className="justify-content-end">
<Dropdown data-testid="languageDropdown" drop={dropDirection}>
Expand Down
35 changes: 31 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import {
ApolloClient,
ApolloProvider,
InMemoryCache,
ApolloLink,
HttpLink,
split,
} from '@apollo/client';
import { getMainDefinition } from '@apollo/client/utilities';
import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
import { createClient } from 'graphql-ws';
import { onError } from '@apollo/link-error';
import './assets/css/app.css';
import 'bootstrap/dist/js/bootstrap.min.js';
Expand All @@ -23,7 +26,10 @@ import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import App from './App';
import { store } from './state/store';
import './utils/i18n';
import { BACKEND_URL } from 'Constant/constant';
import {
BACKEND_URL,
REACT_APP_BACKEND_WEBSOCKET_URL,
} from 'Constant/constant';

onError(({ graphQLErrors }) => {
if (graphQLErrors) graphQLErrors.map(({ message }) => console.log(message));
Expand All @@ -36,11 +42,32 @@ const httpLink = new HttpLink({
},
});

// if didnt work use /subscriptions
const wsLink = new GraphQLWsLink(
createClient({
url: REACT_APP_BACKEND_WEBSOCKET_URL,
})
);
// The split function takes three parameters:
//
// * A function that's called for each operation to execute
// * The Link to use for an operation if the function returns a "truthy" value
// * The Link to use for an operation if the function returns a "falsy" value
const splitLink = split(
({ query }) => {
const definition = getMainDefinition(query);
return (
definition.kind === 'OperationDefinition' &&
definition.operation === 'subscription'
);
},
wsLink,
httpLink
);
const client: ApolloClient<NormalizedCacheObject> = new ApolloClient({
cache: new InMemoryCache(),
link: ApolloLink.from([httpLink]),
link: splitLink,
});

const fallbackLoader = <div className="loader"></div>;

ReactDOM.render(
Expand Down
2 changes: 1 addition & 1 deletion src/screens/UserPortal/Organizations/Organizations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ interface InterfaceOrganizationCardProps {
image: string;
description: string;
}

export default function organizations(): JSX.Element {
const { t } = useTranslation('translation', {
keyPrefix: 'userOrganizations',
Expand Down Expand Up @@ -160,6 +159,7 @@ export default function organizations(): JSX.Element {
</Dropdown.Menu>
</Dropdown>
</div>

<div
className={`d-flex flex-column justify-content-between ${styles.content}`}
>
Expand Down
Loading