Skip to content

Commit 61dfdf4

Browse files
feat: implement base for team name and avatar loading (use fixtures for now)
1 parent 8101479 commit 61dfdf4

File tree

9 files changed

+130
-72
lines changed

9 files changed

+130
-72
lines changed
Binary file not shown.
Binary file not shown.

src/assemblies/app/AppSidebar.vue

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ div(
2020
)
2121
sidebar-header(
2222
@add-contact="onAddContact"
23+
:jid="selfJID"
2324
:translucent="runtimeTranslucent"
2425
:class=`[
2526
"a-app-sidebar__header",

src/broker/delegate.ts

+12
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ class BrokerDelegate implements ProseClientDelegate {
128128
logger.info("Account information changed");
129129

130130
await Store.$account.loadInformation(true);
131+
132+
// TODO: REMOVE THIS ONE! USED FOR DEBUG ONLY, WE NEED A PROPER DELEGATE \
133+
// EVENT!!
134+
this.teamInfoChanged();
135+
}
136+
137+
async teamInfoChanged(): Promise<void> {
138+
// TODO: this delegate event does NOT YET exist, it WILL BE implemented.
139+
140+
logger.info("Team information changed");
141+
142+
await Store.$account.loadTeam(true);
131143
}
132144

133145
async messagesAppended(

src/components/base/BaseServerLogo.vue

+18-52
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@
99
********************************************************************** -->
1010

1111
<template lang="pug">
12-
div(
13-
:class=`[
14-
"c-base-server-logo",
15-
"c-base-server-logo--shadow-" + shadow
16-
]`
17-
:style=`{
18-
backgroundImage: backgroundImage,
19-
height: size,
20-
width: size
21-
}`
12+
base-avatar(
13+
:jid="jid"
14+
:name="name"
15+
:size="size"
16+
:shadow="shadow"
17+
class="c-base-server-logo"
18+
circle
2219
)
2320
</template>
2421

@@ -27,13 +24,22 @@ div(
2724
********************************************************************** -->
2825

2926
<script lang="ts">
27+
// NPM
28+
import { PropType } from "vue";
29+
import { JID } from "@prose-im/prose-sdk-js";
30+
3031
export default {
3132
name: "BaseServerLogo",
3233

3334
props: {
34-
domain: {
35+
jid: {
36+
type: Object as PropType<JID>,
37+
default: null
38+
},
39+
40+
name: {
3541
type: String,
36-
required: true
42+
default: null
3743
},
3844

3945
size: {
@@ -49,46 +55,6 @@ export default {
4955
return ["none", "normal"].includes(x);
5056
}
5157
}
52-
},
53-
54-
computed: {
55-
logoImageUrl(): string {
56-
// TODO: acquire from cache using provided domain, this is only a \
57-
// temporary fixture
58-
const handle = this.domain.replaceAll(".", "-");
59-
60-
return [
61-
"/images/components/base/BaseServerLogo",
62-
`logo-${handle}.png`
63-
].join("/");
64-
},
65-
66-
backgroundImage(): string {
67-
return `url("${this.logoImageUrl}")`;
68-
}
6958
}
7059
};
7160
</script>
72-
73-
<!-- **********************************************************************
74-
STYLE
75-
********************************************************************** -->
76-
77-
<style lang="scss">
78-
$c: ".c-base-server-logo";
79-
80-
#{$c} {
81-
background-color: rgb(var(--color-base-grey-light));
82-
background-position: center;
83-
background-size: cover;
84-
background-repeat: no-repeat;
85-
display: inline-block;
86-
border-radius: 100%;
87-
88-
// --> SHADOWS <--
89-
90-
&--shadow-normal {
91-
box-shadow: 0 2px 4px 0 rgba(var(--color-shadow-primary), 0.08);
92-
}
93-
}
94-
</style>

src/components/sidebar/SidebarContext.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
)
4242

4343
template(
44-
v-if="this.session.connected"
44+
v-if="session.connected"
4545
v-slot:presence
4646
)
4747
base-presence(
@@ -409,7 +409,7 @@ export default {
409409

410410
properties: {
411411
type: "server",
412-
name: this.teamName,
412+
name: this.teamNameOrDomain,
413413
address: this.teamDomain
414414
}
415415
},
@@ -421,7 +421,7 @@ export default {
421421
children: [
422422
{
423423
type: PopoverItemType.Button,
424-
label: this.teamName,
424+
label: this.teamNameOrDomain,
425425
click: this.onActionsPopoverSwitchTeamClick
426426
}
427427
]
@@ -443,8 +443,8 @@ export default {
443443
return this.jid.domain;
444444
},
445445

446-
teamName(): string {
447-
return `@${this.teamDomain}`;
446+
teamNameOrDomain(): string {
447+
return Store.$account.getTeamName() || this.teamDomain;
448448
},
449449

450450
localAvailability(): ReturnType<

src/components/sidebar/SidebarContextAccount.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
base-server-logo(
2121
v-else-if="type === 'server'"
22-
:domain="address"
22+
:jid="addressJID"
23+
:name="name"
2324
size="30px"
2425
class="c-sidebar-context-account__avatar"
2526
)

src/components/sidebar/SidebarHeader.vue

+23-13
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ div(
2727
)
2828
base-server-logo(
2929
@click="onIdentityLogoClick"
30-
class="c-sidebar-header__identity-logo"
31-
domain="prose.org"
30+
:jid="teamDomainJID"
31+
:name="teamName"
3232
size="30px"
33+
class="c-sidebar-header__identity-logo"
3334
)
3435

3536
base-popover-list(
@@ -62,6 +63,13 @@ div(
6263
********************************************************************** -->
6364

6465
<script lang="ts">
66+
// NPM
67+
import { PropType } from "vue";
68+
import { JID } from "@prose-im/prose-sdk-js";
69+
70+
// PROJECT: STORES
71+
import Store from "@/store";
72+
6573
// PROJECT: COMPONENTS
6674
import {
6775
Item as PopoverItem,
@@ -78,6 +86,11 @@ export default {
7886
name: "SidebarHeader",
7987

8088
props: {
89+
jid: {
90+
type: Object as PropType<JID>,
91+
required: true
92+
},
93+
8194
translucent: {
8295
type: Boolean,
8396
default: false
@@ -111,17 +124,6 @@ export default {
111124
type: PopoverItemType.Button,
112125
label: "Create a channel",
113126
click: this.onIdentityPopoverCreateChannelClick
114-
},
115-
116-
{
117-
type: PopoverItemType.Divider
118-
},
119-
120-
{
121-
type: PopoverItemType.Button,
122-
label: "Manage server",
123-
emphasis: true,
124-
disabled: true
125127
}
126128
];
127129
},
@@ -131,6 +133,14 @@ export default {
131133
"ctrl+n": this.onHotkeyControlN,
132134
"command+n": this.onHotkeyControlN
133135
};
136+
},
137+
138+
teamDomainJID(): JID {
139+
return new JID(this.jid.domain);
140+
},
141+
142+
teamName(): string {
143+
return Store.$account.getTeamName();
134144
}
135145
},
136146

src/store/tables/account.ts

+69-1
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,20 @@ interface Account {
4343
name: string;
4444
availability: Availability;
4545
};
46+
47+
team: {
48+
name: string;
49+
accent: string;
50+
};
4651
}
4752

4853
/**************************************************************************
4954
* CONSTANTS
5055
* ************************************************************************* */
5156

5257
const LOCAL_STATES = {
53-
informationLoaded: false
58+
informationLoaded: false,
59+
teamLoaded: false
5460
};
5561

5662
const INFORMATION_AVAILABILITY_DEFAULT = Availability.Available;
@@ -78,6 +84,11 @@ const $account = defineStore("account", {
7884
jid: "",
7985
name: "",
8086
availability: INFORMATION_AVAILABILITY_DEFAULT
87+
},
88+
89+
team: {
90+
name: "",
91+
accent: ""
8192
}
8293
};
8394
},
@@ -114,6 +125,18 @@ const $account = defineStore("account", {
114125
return (): Availability => {
115126
return this.information.availability;
116127
};
128+
},
129+
130+
getTeamName: function () {
131+
return (): string => {
132+
return this.team.name;
133+
};
134+
},
135+
136+
getTeamAccent: function () {
137+
return (): string => {
138+
return this.team.accent;
139+
};
117140
}
118141
},
119142

@@ -188,6 +211,10 @@ const $account = defineStore("account", {
188211
state.information.jid = "";
189212
state.information.name = "";
190213
state.information.availability = INFORMATION_AVAILABILITY_DEFAULT;
214+
215+
// Clear team
216+
state.team.name = "";
217+
state.team.accent = "";
191218
});
192219
},
193220

@@ -235,6 +262,35 @@ const $account = defineStore("account", {
235262
}
236263
},
237264

265+
async loadTeam(reload = false): Promise<void> {
266+
// Load team? (or reload)
267+
if (LOCAL_STATES.teamLoaded === false || reload === true) {
268+
// Load team information
269+
// TODO: load, remove those fixtures!
270+
const teamInfo = await Promise.resolve({
271+
domain: "prose.org.local",
272+
name: "Prose Dev",
273+
accent: "#1f1e25",
274+
avatar: undefined
275+
});
276+
277+
if (teamInfo) {
278+
// Update stored team information
279+
this.setTeamName(teamInfo.name);
280+
this.setTeamAccent(teamInfo.accent);
281+
282+
// Update team avatar
283+
// Notice: this is a cross-store operation, for convenience.
284+
if (teamInfo.avatar !== undefined) {
285+
Store.$avatar.refresh(teamInfo.domain, teamInfo.avatar);
286+
}
287+
}
288+
289+
// Mark as loaded
290+
LOCAL_STATES.teamLoaded = true;
291+
}
292+
},
293+
238294
setCredentialsPassword(password: string): void {
239295
this.$patch(() => {
240296
this.credentials.password = password;
@@ -257,6 +313,18 @@ const $account = defineStore("account", {
257313
this.$patch(() => {
258314
this.information.availability = availability;
259315
});
316+
},
317+
318+
setTeamName(name: string): void {
319+
this.$patch(() => {
320+
this.team.name = name;
321+
});
322+
},
323+
324+
setTeamAccent(accent: string): void {
325+
this.$patch(() => {
326+
this.team.accent = accent;
327+
});
260328
}
261329
}
262330
});

0 commit comments

Comments
 (0)