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

feat(quickProfile): improve quickProfile ui/ux #4975

Merged
merged 2 commits into from
Sep 26, 2022
Merged
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
12 changes: 3 additions & 9 deletions components/interactables/QuickProfile/QuickProfile.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@
v-click-outside="close"
>
<div class="top">
<!-- todo - remove no-click after implementing regular profile for all users -->
<button
@click="openProfile"
class="open-profile-button"
:class="{'no-click' : !isMe}"
>
<!-- end todo -->
<button @click="openProfile" class="open-profile-button">
<UiUserState :user="user" :size="40" />
</button>
<TypographyText as="h4"> {{ user.name }} </TypographyText>
<TypographyText as="h4" class="ellipsis"> {{ user.name }} </TypographyText>
</div>
<InteractablesInput
v-if="!isMe"
v-if="conversationId"
v-model.trim="text"
ref="input"
size="xs"
Expand Down
7 changes: 2 additions & 5 deletions components/interactables/QuickProfile/QuickProfile.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
position: fixed;
width: 350px;
padding: 16px;
overflow: hidden;
// background: linear-gradient(
// to bottom,
// @flair-color 0%,
Expand All @@ -22,11 +23,7 @@
gap: 16px;

.open-profile-button {
width: fit-content;

&.no-click {
cursor: default;
}
cursor: default;
}
}
}
Expand Down
47 changes: 23 additions & 24 deletions components/interactables/QuickProfile/QuickProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { User } from '~/libraries/Iridium/users/types'
import { SettingsRoutes } from '~/store/ui/types'
import iridium from '~/libraries/Iridium/IridiumManager'
import { RootState } from '~/types/store/store'
import { Conversation } from '~/libraries/Iridium/chat/types'

export default Vue.extend({
components: {
Expand All @@ -21,16 +22,19 @@ export default Vue.extend({
...mapState({
quickProfile: (state) => (state as RootState).ui.quickProfile,
}),
isMe(): boolean {
return iridium.id === this.user?.did
},
user(): User | undefined {
return this.quickProfile?.user
},
src(): string {
const hash = this.user?.photoHash
return hash ? `${this.$Config.ipfs.gateway}${hash}` : ''
},
conversationId(): Conversation['id'] | undefined {
if (!this.user) {
return
}
return iridium.chat.directConversationIdFromDid(this.user.did)
},
},
mounted() {
const quick = this.$refs.quick as HTMLElement
Expand All @@ -51,51 +55,46 @@ export default Vue.extend({
return
}
const quick = this.$refs.quick as HTMLElement
const clickX = this.quickProfile.position.x
const clickY = this.quickProfile.position.y
const widthOverflow = clickX + quick.clientWidth - window.innerWidth
const heightOverflow = clickY + quick.clientHeight - window.innerHeight
const widthOverflow =
this.quickProfile.position.x + quick.clientWidth - window.innerWidth
const heightOverflow =
this.quickProfile.position.y + quick.clientHeight - window.innerHeight
if (widthOverflow > -8) {
quick.style.left = `${this.quickProfile.position.x - widthOverflow}px`
quick.style.left = `${
this.quickProfile.position.x - widthOverflow - 16
}px`
}
if (heightOverflow > -8) {
quick.style.top = `${this.quickProfile.position.y - heightOverflow}px`
quick.style.top = `${
this.quickProfile.position.y - heightOverflow - 16
}px`
}
},
sendMessage() {
if (!this.user || !this.text.length) {
return
}
const conversationId = iridium.chat.directConversationIdFromDid(
this.user.did,
)
if (!conversationId) {
if (!this.user || !this.text.length || !this.conversationId) {
return
}

if (conversationId !== this.$route.params.id) {
if (this.conversationId !== this.$route.params.id) {
this.$router.push(
this.$device.isMobile
? `/mobile/chat/${conversationId}`
: `/chat/${conversationId}`,
? `/mobile/chat/${this.conversationId}`
: `/chat/${this.conversationId}`,
)
}

iridium.chat.sendMessage({
at: Date.now(),
type: 'text',
body: this.text,
conversationId,
conversationId: this.conversationId,
attachments: [],
payload: {},
})
this.close()
},
openProfile() {
if (!this.user) {
return
}
if (this.isMe) {
if (iridium.id === this.user?.did) {
this.$store.commit('ui/setSettingsRoute', SettingsRoutes.PROFILE)
this.close()
} else {
Expand Down
29 changes: 24 additions & 5 deletions components/views/chat/UserList.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<template>
<div class="user-list hover-scroll">
<TypographyText size="sm" color="body">
<TypographyText size="sm" color="body" class="heading">
{{
$t('pages.chat.members', { count: allParticipantsAlphaSorted.length })
}}
</TypographyText>
<div class="list">
<div
<button
v-for="user in allParticipantsAlphaSorted"
:key="user.did"
class="user"
@click="showQuickProfile($event, user)"
>
<UiUserState :user="user" :conversation-id="conversationId" />
<TypographyText
Expand All @@ -20,21 +21,32 @@
>
{{ user.name }}
</TypographyText>
</div>
</button>
</div>
</div>
</template>

<script lang="ts">
import Vue from 'vue'
import { conversationHooks } from '~/components/compositions/conversations'
import { User } from '~/libraries/Iridium/users/types'

export default Vue.extend({
setup() {
const { conversationId, allParticipantsAlphaSorted } = conversationHooks()

return { conversationId, allParticipantsAlphaSorted }
},
methods: {
showQuickProfile(e: MouseEvent, user: User) {
setTimeout(() => {
this.$store.commit('ui/setQuickProfile', {
user,
position: { x: e.x, y: e.y },
})
}, 0)
},
},
})
</script>

Expand All @@ -44,7 +56,6 @@ export default Vue.extend({
flex-direction: column;
flex-shrink: 0;
gap: 8px;
padding: 16px;
width: 240px;
margin-right: 16px;
overflow-y: auto;
Expand All @@ -53,16 +64,24 @@ export default Vue.extend({
user-select: none;
border-radius: @corner-rounding;

.heading {
padding: 16px 16px 0;
}

.list {
display: flex;
flex-direction: column;
gap: 12px;
}

.user {
display: flex;
gap: 8px;
align-items: center;
padding: 8px 16px;

&:hover {
.background-semitransparent-lighter();
}
}
}
</style>
12 changes: 7 additions & 5 deletions components/views/chat/message/Message.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
<!-- todo - add user options context menu -->
<template v-if="showHeader">
<div class="avatar">
<UiCircle
:type="avatarSrc ? 'image' : 'random'"
:seed="author.did"
:source="avatarSrc"
/>
<button @click="showQuickProfile" tabindex="-1">
<UiCircle
:type="avatarSrc ? 'image' : 'random'"
:seed="author.did"
:source="avatarSrc"
/>
</button>
</div>
<div class="header">
<button @click="showQuickProfile">
Expand Down
3 changes: 3 additions & 0 deletions libraries/Iridium/chat/ChatManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ export default class ChatManager extends Emitter<ConversationMessage> {
* significantly faster than Iridium.hash until about 5,000,000 conversation records
*/
directConversationIdFromDid(friendDid: Friend['did']): string | undefined {
if (friendDid === iridium.id) {
return
}
return Object.values(this.state.conversations).find(
(c) => c.type === 'direct' && c.participants.includes(friendDid),
)?.id
Expand Down