Skip to content

Commit b39ae80

Browse files
authored
Merge pull request #117 from buggregator/hotfix/ws-connection
Fixes problem with subscribing WS events
2 parents 5570eb8 + f93033a commit b39ae80

File tree

9 files changed

+72
-41
lines changed

9 files changed

+72
-41
lines changed

.docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ WORKDIR /app
1212

1313
ARG APP_VERSION=1.0.0
1414
ENV NODE_OPTIONS=--openssl-legacy-provider
15+
ENV VITE_APP_MODE=production
1516

1617
RUN sed -i "s/\"version\": \".*\"/\"version\": \"${APP_VERSION}\"/" package.json
1718

assets/mixins.scss

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
}
88

99
@mixin layout-head {
10-
@apply justify-between bg-white dark:bg-gray-800;
10+
@apply justify-between;
11+
@apply backdrop-blur-sm bg-gradient-to-b from-white/80 to-white/20 dark:from-gray-800/80 dark:to-gray-800/20;
12+
//@apply backdrop-blur dark:backdrop-brightness-150 dark:bg-black/30 bg-white/30;
1113
@apply absolute left-0 right-0 z-50;
1214
@apply h-9 sm:h-10 md:h-14;
13-
@apply border-b border-gray-200 dark:border-gray-700;
1415
@apply px-2 md:px-4;
1516

1617
html.navbar-fixed & {
@@ -19,7 +20,7 @@
1920
}
2021

2122
@mixin layout-body {
22-
@apply flex flex-col flex-1 pt-12;
23+
@apply flex flex-col flex-1 pt-10 md:pt-14;
2324
}
2425

2526
@mixin text-muted {

src/shared/lib/io/logger.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import type { LoggerParams } from "./types";
22

3-
export const logger = (params: LoggerParams) => {
3+
const isProduction: boolean = import.meta.env.VITE_APP_MODE as string === 'production'
4+
5+
export const logger = (params: LoggerParams): void => {
6+
if (isProduction) {
7+
return
8+
}
9+
410
console.info(`[ApiConnection logger]:Centrifuge "${params[0]}" called with params: "${JSON.stringify(params[1])}"`)
511
}

src/shared/lib/use-api-transport/use-api-transport.ts

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import { useCentrifuge, useEventsRequests } from "../io";
44
import { useConnectionStore } from "~/stores/connections";
55
import { useEventStore } from "~/stores/events";
66

7-
const CHECK_CONNECTION_INTERVAL = 10000
7+
const CHECK_CONNECTION_INTERVAL: number = 10000
8+
let isEventsEmitted: boolean = false
9+
810
export const useApiTransport = () => {
9-
const { centrifuge } = useCentrifuge()
11+
const {centrifuge} = useCentrifuge()
1012
const eventsStore = useEventStore()
1113
const connectionStore = useConnectionStore()
1214
const {
@@ -21,37 +23,44 @@ export const useApiTransport = () => {
2123

2224
const getWSConnection = () => connectionStore.isConnectedWS
2325
const checkWSConnectionFail = (onConnectionLost: () => void) => {
24-
if(!getWSConnection()) {
26+
if (!getWSConnection()) {
2527
onConnectionLost()
2628
}
2729
setTimeout(() => {
2830
checkWSConnectionFail(onConnectionLost)
2931
}, CHECK_CONNECTION_INTERVAL)
3032
}
3133

32-
centrifuge.on('connected', () => {
33-
connectionStore.addWSConnection()
34-
});
34+
const subscribeToEvents = (): void => {
35+
centrifuge.on('connected', () => {
36+
connectionStore.addWSConnection()
37+
});
3538

36-
centrifuge.on('disconnected', () => {
37-
connectionStore.removeWSConnection()
38-
});
39+
centrifuge.on('disconnected', () => {
40+
connectionStore.removeWSConnection()
41+
});
3942

40-
centrifuge.on('error', () => {
41-
connectionStore.removeWSConnection()
42-
})
43+
centrifuge.on('error', () => {
44+
connectionStore.removeWSConnection()
45+
})
4346

44-
centrifuge.on('message', () => {
45-
connectionStore.addWSConnection()
46-
})
47+
centrifuge.on('message', () => {
48+
connectionStore.addWSConnection()
49+
})
4750

48-
centrifuge.on('publication', (ctx) => {
49-
// We need to handle only events from the channel 'events' with event name 'event.received'
50-
if (ctx.channel === 'events' && ctx.data?.event === 'event.received') {
51-
const event = ctx?.data?.data || null
52-
eventsStore.addList([ event ]);
53-
}
54-
});
51+
centrifuge.on('publication', (ctx) => {
52+
// We need to handle only events from the channel 'events' with event name 'event.received'
53+
if (ctx.channel === 'events' && ctx.data?.event === 'event.received') {
54+
const event = ctx?.data?.data || null
55+
eventsStore.addList([event]);
56+
}
57+
});
58+
}
59+
60+
if (!isEventsEmitted) {
61+
subscribeToEvents()
62+
isEventsEmitted = true
63+
}
5564

5665
checkWSConnectionFail(async () => {
5766
const events = await getAll();
@@ -85,7 +94,7 @@ export const useApiTransport = () => {
8594
}
8695

8796
if (getWSConnection()) {
88-
return centrifuge.rpc(`delete:api/events`, { uuids })
97+
return centrifuge.rpc(`delete:api/events`, {uuids})
8998
}
9099

91100
return deleteList(uuids);

src/shared/ui/preview-card/preview-card-header.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ const isVisibleTags = computed(() => props.tags.length > 0);
8383
</div>
8484

8585
<div v-if="isVisibleControls" class="preview-card-header__buttons">
86-
<div class="preview-card-header__buttons-expand">
86+
<div v-if="isOpen" class="preview-card-header__buttons-expand">
8787
<button
8888
class="preview-card-header__button preview-card-header__button--copy"
8989
title="Copy event as PNG image to clipboard"
9090
@click="copyEvent"
9191
>
92-
<IconSvg name="copy" class="preview-card-header__button-icon" />
92+
<IconSvg name="copy" class="preview-card-header__button-icon"/>
9393
</button>
9494

9595
<div class="preview-card-header__buttons-expand-list">
@@ -143,7 +143,7 @@ const isVisibleTags = computed(() => props.tags.length > 0);
143143
}"
144144
@click="lockEvent"
145145
>
146-
<IconSvg name="lock" class="preview-card-header__button-icon" />
146+
<IconSvg name="lock" class="preview-card-header__button-icon"/>
147147
</button>
148148

149149
<button
@@ -152,7 +152,7 @@ const isVisibleTags = computed(() => props.tags.length > 0);
152152
:disabled="isLocked"
153153
@click="deleteEvent"
154154
>
155-
<IconSvg name="times" class="preview-card-header__button-icon" />
155+
<IconSvg name="times" class="preview-card-header__button-icon"/>
156156
</button>
157157
</div>
158158
</div>

src/shared/ui/preview-card/preview-card.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ const normalizedOrigin = computed(() => {
4343
4444
const eventUrl = computed(() => `${REST_API_URL}/api/event/${props.event.id}`);
4545
46-
const toggleView = () => {
46+
const toggleView = (e: MouseEvent) => {
4747
isCollapsed.value = !isCollapsed.value;
48+
e.preventDefault();
4849
};
4950
5051
const changeVisibleControls = (value = true) => {
@@ -176,6 +177,7 @@ onBeforeUnmount(() => {
176177
@copy="copyCode"
177178
@download="downloadEvent"
178179
@lock="toggleEventLock"
180+
@dblclick="toggleView"
179181
/>
180182

181183
<div
@@ -207,7 +209,7 @@ onBeforeUnmount(() => {
207209
}
208210
209211
.preview-card--collapsed {
210-
@apply shadow-bottom;
212+
// @apply shadow-bottom;
211213
}
212214
213215
.preview-card__header {

src/widgets/ui/layout-sidebar/layout-sidebar.vue

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,30 +96,39 @@ const connectionText = computed(
9696
<style lang="scss" scoped>
9797
.layout-sidebar {
9898
@apply bg-gray-200 dark:bg-gray-800;
99-
@apply w-9 sm:w-10 md:w-14;
99+
@apply w-9 sm:w-12 md:w-16;
100100
@apply flex flex-col justify-between;
101101
}
102102
103103
.layout-sidebar__nav {
104104
@apply flex-col flex overflow-auto;
105-
@apply divide-y divide-gray-300 dark:divide-gray-600;
106-
@apply border-b border-gray-300 dark:border-gray-600;
105+
@apply divide-y divide-gray-300 dark:divide-gray-600 md:divide-none;
106+
@apply border-b border-gray-300 dark:border-gray-600 md:border-none;
107+
@apply overflow-hidden;
107108
}
108109
109110
.layout-sidebar__link {
110-
@apply text-blue-500 block hover:bg-blue-500 hover:text-white relative;
111-
@apply h-9 sm:h-10 md:h-14;
111+
@apply block relative;
112+
@apply text-blue-500 hover:text-white;
113+
@apply hover:bg-gray-700;
112114
@apply flex items-center justify-center;
115+
@apply md:my-2 md:mx-1 lg:m-2 md:rounded-lg;
113116
114117
&.router-link-active {
115118
@apply bg-blue-700 text-blue-200;
116119
}
117120
}
118121
119122
.layout-sidebar__link-icon {
123+
@apply flex items-center justify-center;
120124
@apply fill-current;
121125
@apply mx-auto;
122-
@apply w-3 h-3 md:w-5 md:h-5 lg:w-6 lg:h-6;
126+
@apply h-5 md:h-6;
127+
@apply m-2.5 md:m-3;
128+
129+
& > svg {
130+
@apply h-auto;
131+
}
123132
}
124133
125134
.layout-sidebar__connection {

src/widgets/ui/page-header/page-header.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const clearEvents = () => {
3838
</button>
3939
</div>
4040

41-
<IconSvg class="page-header__lock-icon" name="lock" />
41+
<!-- <IconSvg class="page-header__lock-icon" name="lock" />-->
4242
</header>
4343
</template>
4444

stores/settings.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ const checkThemeActive = () => {
2727

2828
const checkHeaderFixed = () => {
2929
if (process.client) {
30-
const isFixed = window?.localStorage.getItem(LOCAL_STORAGE_KEYS.NAVBAR) === "true"
30+
const storedValue: string = window?.localStorage.getItem(LOCAL_STORAGE_KEYS.NAVBAR) || "true";
31+
32+
33+
const isFixed: boolean = storedValue === "true"
3134

3235
if (isFixed) {
3336
document?.documentElement?.classList?.add("navbar-fixed");

0 commit comments

Comments
 (0)