Skip to content

Commit

Permalink
refactor: move room property logic to component, away from router
Browse files Browse the repository at this point in the history
Will also handle the not found case in a different way, showing in the UI a not found message rather than erroring out.
  • Loading branch information
valeriansaliou committed Oct 18, 2023
1 parent 159078a commit 8a45f0d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/components/inbox/InboxMessaging.vue
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export default {
immediate: true,

handler(newValue: Room, oldValue: Room) {
if (newValue && (!oldValue || newValue.id != oldValue.id)) {
if (newValue && (!oldValue || newValue.id !== oldValue.id)) {
// Mark as stale
this.isMessageSyncStale = true;

Expand Down
2 changes: 1 addition & 1 deletion src/components/inbox/InboxUserinfoInformation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default {

if (this.profile.information.lastActive) {
const activePrefix =
this.availability != Availability.Unavailable
this.availability !== Availability.Unavailable
? "Active"
: "Last seen";

Expand Down
29 changes: 1 addition & 28 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
createRouter,
createWebHistory
} from "vue-router";
import init, { JID, RoomID } from "@prose-im/prose-sdk-js";
import init, { JID } from "@prose-im/prose-sdk-js";

// PROJECT: VIEWS
import AppBase from "@/views/app/AppBase.vue";
Expand All @@ -29,9 +29,6 @@ import Store from "@/store";
// PROJECT: BROKER
import Broker from "@/broker";

// PROJECT: UTILITIES
import logger from "@/utilities/logger";

/**************************************************************************
* ENUMERATIONS
* ************************************************************************* */
Expand Down Expand Up @@ -110,30 +107,6 @@ class Router {
name: "app.inbox",
component: AppInboxBase,

props: route => {
const room = Store.$muc.getRoomByID(
route.params.roomId as RoomID
);

if (!room) {
const availableRooms = Store.$muc.getAvailableRoomIDs();

let errorMessage = `Room not found '${route.params.roomId}'.`;

if (availableRooms.length == 0) {
errorMessage += " There are no rooms available.";
} else {
errorMessage += ` Available rooms are ${availableRooms.join(
", "
)}`;
}

logger.error(errorMessage);
}

return { room: room };
},

beforeEnter: (to, from, next) => {
Broker.client
.awaitConnection()
Expand Down
21 changes: 11 additions & 10 deletions src/views/app/inbox/AppInboxBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@

<script lang="ts">
// NPM
import { JID, Room } from "@prose-im/prose-sdk-js";
import { PropType } from "vue";
import { JID, Room, RoomID } from "@prose-im/prose-sdk-js";

// PROJECT: STORES
import Store from "@/store";
Expand All @@ -69,16 +68,18 @@ export default {
InboxForm
},

props: {
room: {
type: Object as PropType<Room>,
required: true
}
},

computed: {
jid(): JID {
return new JID(this.$route.params.roomId as string);
return new JID(this.roomId as string);
},

roomId(): RoomID {
return this.$route.params.roomId as RoomID;
},

room(): Room | void {
// TODO: handle case of room not found (show placeholder data)
return Store.$muc.getRoomByID(this.roomId);
},

layout(): typeof Store.$layout {
Expand Down

0 comments on commit 8a45f0d

Please sign in to comment.