Skip to content

Commit

Permalink
feat: introduce Etherpad.js and implement in /etherpad
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel committed Sep 13, 2023
1 parent 17956c2 commit 4293872
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
5 changes: 5 additions & 0 deletions lib/Etherpad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import getConfig from 'next/config';

const path = getConfig().publicRuntimeConfig.authProviders.etherpad.path || '/etherpad';

export { path };
11 changes: 5 additions & 6 deletions pages/etherpad/[[...roomId]].js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ import CreateAnonymousPad from './actions/CreateAnonymousPad';
import AddExistingPad from './actions/AddExistingPad';
import CreateAuthoredPad from './actions/CreateAuthoredPad';
import CreatePasswordPad from './actions/CreatePasswordPad';
import { path as etherpadPath } from '../../lib/Etherpad';

export default function Etherpad() {
const auth = useAuth();
const matrix = useMatrix();

const matrixClient = auth.getAuthenticationProvider('matrix').getMatrixClient();
const etherpad = auth.getAuthenticationProvider('etherpad');
// we check if there is a custom path name defined and if so remove any forbidden url characters from the string
const path = getConfig().publicRuntimeConfig.authProviders.etherpad.path || '/etherpad';

const { t } = useTranslation('etherpad');
const router = useRouter();
Expand Down Expand Up @@ -149,7 +148,7 @@ export default function Etherpad() {

await syncServerPadsAndSet();

router.push(path);
router.push(etherpadPath);
setIsDeletingPad(false);
};

Expand Down Expand Up @@ -192,16 +191,16 @@ export default function Etherpad() {
<IframeLayout.Sidebar>
{ !matrix.serviceSpaces.etherpad ? (
<>
<h2>{ getConfig().publicRuntimeConfig.authProviders.etherpad.path }</h2>
<h2>{ etherpadPath }</h2>
<LoadingSpinner />
</>
) : (
<>
<ServiceSubmenu
title={<h2>{ getConfig().publicRuntimeConfig.authProviders.etherpad.path }</h2>}
title={<h2>{ etherpadPath }</h2>}
subheadline={t('What would you like to do?')}
items={submenuItems} />
{ getConfig().publicRuntimeConfig.authProviders.etherpad.myPads?.api && !serverPads && <ErrorMessage>{ t('Can\'t connect to the provided {{path}} server. Please try again later.', { path: path }) }</ErrorMessage> }
{ getConfig().publicRuntimeConfig.authProviders.etherpad.myPads?.api && !serverPads && <ErrorMessage>{ t('Can\'t connect to the provided {{path}} server. Please try again later.', { path: etherpadPath }) }</ErrorMessage> }
<ServiceTable>
{ matrix.spaces.get(matrix.serviceSpaces.etherpad).children?.map(writeRoomId => {
return <EtherpadListEntry
Expand Down
3 changes: 2 additions & 1 deletion pages/etherpad/actions/AddExistingPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
import Form from '../../../components/UI/Form';
import ErrorMessage from '../../../components/UI/ErrorMessage';
import LoadingSpinnerInline from '../../../components/UI/LoadingSpinnerInline';
import { path as etherpadPath } from '../../../lib/Etherpad';

export default function AddExistingPad({ callbackDone, createWriteRoom }) {
const router = useRouter();
Expand All @@ -30,7 +31,7 @@ export default function AddExistingPad({ callbackDone, createWriteRoom }) {
setPadLink('');
setIsLoading(false);

router.push(`${getConfig().publicRuntimeConfig.authProviders.etherpad.path}/${roomId}`);
router.push(`${etherpadPath}/${roomId}`);
};

return (
Expand Down
3 changes: 2 additions & 1 deletion pages/etherpad/actions/CreateAnonymousPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import getConfig from 'next/config';

import Form from '../../../components/UI/Form';
import LoadingSpinnerInline from '../../../components/UI/LoadingSpinnerInline';
import { path as etherpadPath } from '../../../lib/Etherpad';

export default function CreateAnonymousPad({ callbackDone, createWriteRoom }) {
const router = useRouter();
Expand All @@ -29,7 +30,7 @@ export default function CreateAnonymousPad({ callbackDone, createWriteRoom }) {
setPadName('');

// Forward the user and show the newly created pad
router.push(`${getConfig().publicRuntimeConfig.authProviders.etherpad.path}/${roomId}`);
router.push(`${etherpadPath}/${roomId}`);
};

return (
Expand Down
3 changes: 2 additions & 1 deletion pages/etherpad/actions/CreateAuthoredPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
import Form from '../../../components/UI/Form';
import LoadingSpinnerInline from '../../../components/UI/LoadingSpinnerInline';
import { useAuth } from '../../../lib/Auth';
import { path as etherpadPath } from '../../../lib/Etherpad';

export default function CreateAuthoredPad({ callbackDone, createWriteRoom }) {
const router = useRouter();
Expand All @@ -27,7 +28,7 @@ export default function CreateAuthoredPad({ callbackDone, createWriteRoom }) {
}
const link = getConfig().publicRuntimeConfig.authProviders.etherpad.baseUrl + '/' + padId;
const roomId = await createWriteRoom(link, padName);
router.push(`${getConfig().publicRuntimeConfig.authProviders.etherpad.path}/${roomId}`);
router.push(`${etherpadPath}/${roomId}`);

callbackDone && callbackDone();
setPadName('');
Expand Down
3 changes: 2 additions & 1 deletion pages/etherpad/actions/CreatePasswordPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
import Form from '../../../components/UI/Form';
import LoadingSpinnerInline from '../../../components/UI/LoadingSpinnerInline';
import { useAuth } from '../../../lib/Auth';
import { path as etherpadPath } from '../../../lib/Etherpad';

export default function CreatePasswordPad({ callbackDone, createWriteRoom }) {
const router = useRouter();
Expand All @@ -24,7 +25,7 @@ export default function CreatePasswordPad({ callbackDone, createWriteRoom }) {
const padId = await etherpad.createPad(padName, 'private', password);
const link = getConfig().publicRuntimeConfig.authProviders.etherpad.baseUrl + '/' + padId;
const roomId = await createWriteRoom(link, padName);
router.push(`${getConfig().publicRuntimeConfig.authProviders.etherpad.path}/${roomId}`);
router.push(`${etherpadPath}/${roomId}`);

callbackDone && callbackDone();
setPadName('');
Expand Down

0 comments on commit 4293872

Please sign in to comment.