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

Edit room name within explore #177

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 46 additions & 0 deletions pages/explore/manage-room/ChangeRoomName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { toast } from 'sonner';

import { useAuth } from '@/lib/Auth';
import ConfirmCancelButtons from '@/components/UI/ConfirmCancelButtons';
import { Input } from '@/components/UI/shadcn/Input';

const ChangeRoomName = ({ roomName, roomId }) => {
const matrixClient = useAuth().getAuthenticationProvider('matrix').getMatrixClient();
const [newRoomName, setNewRoomName] = useState('');
const [isChangingName, setIsChangingName] = useState(false);
const { t } = useTranslation('explore');

const handleSubmit = async (e) => {
e.preventDefault();
setIsChangingName(true);

try {
await matrixClient.setRoomName(roomId, newRoomName);
toast.success(
t('room name successfully changed to {{newRoomName}}. Please reload the page to see the changes.', { newRoomName }),
);
} catch (error) {
toast.error(error.data?.error);
} finally {
setIsChangingName(false);
}
};

return (
<>
<form className="[&>*+*]:mt-4" onSubmit={handleSubmit} onReset={() => setNewRoomName(roomName)}>
<Input
type="text"
disabled={isChangingName}
value={newRoomName || roomName}
onChange={(e) => setNewRoomName(e.target.value)}
/>
<ConfirmCancelButtons disabled={roomName === newRoomName} />
</form>
</>
);
};

export default ChangeRoomName;
8 changes: 8 additions & 0 deletions pages/explore/manage-room/ExploreMatrixActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ChangeAvatar from './ChangeAvatar';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/UI/shadcn/Tabs';
import ChangeJoinRule from './ChangeJoinRule';
import { useAuth } from '@/lib/Auth';
import ChangeRoomName from './ChangeRoomName';

/**
* This component provides actions for managing contexts and items within a matrix room.
Expand Down Expand Up @@ -77,6 +78,13 @@ const ExploreMatrixActions = ({ currentId, parentId, myPowerLevel }) => {
<ChangeAvatar roomId={currentId} />
</div>
)}

{room.currentState.hasSufficientPowerLevelFor('m.room.title', myPowerLevel) && (
<div className="[&>*+*]:mt-4">
<h3>{t('Name')}</h3>
<ChangeRoomName roomId={currentId} roomName={room.name} />
</div>
)}
</>
</TabsContent>

Expand Down