feat: ability to change the order of signers in create screen #61

Merged
s merged 3 commits from issue-33 into main 2024-05-20 08:30:16 +00:00
Showing only changes of commit 4a71582b43 - Show all commits

View File

@ -89,13 +89,21 @@ export const CreatePage = () => {
const addUser = (pubkey: string) => { const addUser = (pubkey: string) => {
setUsers((prev) => { setUsers((prev) => {
const signers = prev.filter((user) => user.role === UserRole.signer)
const viewers = prev.filter((user) => user.role === UserRole.viewer)
const existingUserIndex = prev.findIndex( const existingUserIndex = prev.findIndex(
(user) => user.pubkey === pubkey (user) => user.pubkey === pubkey
) )
// add new // add new
if (existingUserIndex === -1) if (existingUserIndex === -1) {
return [...prev, { pubkey, role: userRole }] if (userRole === UserRole.signer) {
return [...signers, { pubkey, role: userRole }, ...viewers]
} else {
return [...signers, ...viewers, { pubkey, role: userRole }]
}
}
const existingUser = prev[existingUserIndex] const existingUser = prev[existingUserIndex]
@ -108,7 +116,11 @@ export const CreatePage = () => {
updatedUser.role = userRole updatedUser.role = userRole
updatedUsers[existingUserIndex] = updatedUser updatedUsers[existingUserIndex] = updatedUser
return updatedUsers // signers should be placed at the start of the array
return [
...updatedUsers.filter((user) => user.role === UserRole.signer),
...updatedUsers.filter((user) => user.role === UserRole.viewer)
]
}) })
} }
@ -527,6 +539,7 @@ const DisplayUser = ({
.filter((user) => user.role === UserRole.signer) .filter((user) => user.role === UserRole.signer)
.map((user, index) => ( .map((user, index) => (
<SignerRow <SignerRow
key={`signer-${index}`}
userMeta={metadata[user.pubkey]} userMeta={metadata[user.pubkey]}
user={user} user={user}
index={index} index={index}