Skip to content

Commit acef402

Browse files
committed
Add isInitialized flag to keep chat visible during reconnection
1 parent 51c1f1c commit acef402

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<BApp>
33
<h1>Connection status: {{ irc.connectionStatus }}</h1>
44

5-
<ChatApp v-if="irc.isConnected" />
5+
<ChatApp v-if="irc.isInitialized" />
66
<LoginForm v-else @login="irc.signIn" />
77
</BApp>
88
</template>

src/stores/irc.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export class CustomConnection extends Connection {
1919
}
2020

2121
const useIrcStore = defineStore('irc', () => {
22+
/**
23+
* Tracking if the client has started the connection.
24+
* Keeps the chat view visible until client manually signs out.
25+
*/
26+
const isInitialized = ref(false);
2227
const client = shallowRef<Client | null>(null);
2328
const savedUser = useLocalStorage<Record<'username' | 'uid', string> | null>('chat_user', null);
2429

@@ -97,6 +102,7 @@ const useIrcStore = defineStore('irc', () => {
97102

98103
ircClient.connect();
99104
client.value = markRaw(ircClient);
105+
isInitialized.value = true;
100106
console.log('IRC Client:', ircClient);
101107
}
102108

@@ -123,10 +129,12 @@ const useIrcStore = defineStore('irc', () => {
123129

124130
function signOut() {
125131
savedUser.value = null;
132+
isInitialized.value = false;
126133
quit();
127134
}
128135

129136
return {
137+
isInitialized: readonly(isInitialized),
130138
client: computed(() => (isRegistered.value ? client.value : null)),
131139
isConnected: computed(
132140
() => isRegistered.value && client.value !== null && connectionStatus.value === 'connected',

0 commit comments

Comments
 (0)