Fixed websockets in navigation
This commit is contained in:
@@ -65,8 +65,6 @@ export default {
|
||||
MessageDialog,
|
||||
},
|
||||
created() {
|
||||
this.$store.dispatch('loadLoginState');
|
||||
this.$store.dispatch('loadMenu');
|
||||
this.$i18n.locale = this.$store.getters.language;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -54,15 +54,24 @@ export default {
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters(['menu', 'user', 'menuNeedsUpdate']),
|
||||
...mapGetters(['menu', 'user', 'menuNeedsUpdate', 'socket']),
|
||||
},
|
||||
watch: {
|
||||
menuNeedsUpdate(newValue) {
|
||||
if (newValue) {
|
||||
console.log('Menu needs update, loading menu...');
|
||||
this.loadMenu();
|
||||
}
|
||||
},
|
||||
socket(newValue) {
|
||||
if (newValue) {
|
||||
newValue.on('forumschanged', (data) => {
|
||||
this.fetchForums();
|
||||
});
|
||||
newValue.on('friendloginchanged', () => {
|
||||
this.fetchFriends();
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
if (this.user && this.user.id) {
|
||||
@@ -75,10 +84,12 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
if (this.$store.getters.socket) {
|
||||
console.log('connect sockets in navigation')
|
||||
this.$store.getters.socket.on('forumschanged', (data) => {
|
||||
this.fetchForums();
|
||||
});
|
||||
this.$store.getters.socket.on('friendloginchanged', () => {
|
||||
console.log('update friends');
|
||||
this.fetchFriends();
|
||||
});
|
||||
}
|
||||
|
||||
5
frontend/src/i18n/locales/de/falukant.json
Normal file
5
frontend/src/i18n/locales/de/falukant.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"falukant": {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -44,6 +44,18 @@
|
||||
"manageFriends": "Freunde verwalten",
|
||||
"chat": "Chatten",
|
||||
"profile": "Profil"
|
||||
},
|
||||
"m-falukant": {
|
||||
"create": "Erstellen",
|
||||
"overview": "Übersicht",
|
||||
"towns": "Niederlassungen",
|
||||
"directors": "Direktoren",
|
||||
"factory": "Produktion",
|
||||
"family": "Familie",
|
||||
"house": "Haus",
|
||||
"darknet": "Untergrund",
|
||||
"reputation": "Reputation",
|
||||
"moneyhistory": "Geldfluss"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
frontend/src/i18n/locales/en/falukant.json
Normal file
5
frontend/src/i18n/locales/en/falukant.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"falukant": {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,4 @@ app.use(router);
|
||||
app.use(i18n);
|
||||
app.use(vuetify);
|
||||
|
||||
store.dispatch('loadLoginState');
|
||||
|
||||
app.mount('#app');
|
||||
|
||||
@@ -50,19 +50,13 @@ const store = createStore({
|
||||
},
|
||||
actions: {
|
||||
async login({ commit, dispatch }, user) {
|
||||
console.log('login', user);
|
||||
await commit('dologin', user);
|
||||
await dispatch('initializeSocket');
|
||||
const socket = this.getters.socket;
|
||||
if (socket) {
|
||||
console.log('Emitting setUserId:', user.id);
|
||||
socket.emit('setUserId', user.id);
|
||||
console.log('setUserId emitted successfully');
|
||||
} else {
|
||||
console.error('Socket not initialized');
|
||||
}
|
||||
await dispatch('loadMenu');
|
||||
dispatch('startMenuReload');
|
||||
},
|
||||
logout({ commit, state }) {
|
||||
if (state.socket) {
|
||||
@@ -74,23 +68,10 @@ const store = createStore({
|
||||
},
|
||||
initializeSocket({ commit, state }) {
|
||||
if (state.isLoggedIn && state.user) {
|
||||
const socket = io(import.meta.env.VITE_API_BASE_URL); // oder Ihre URL
|
||||
console.log('Socket initialized:', socket);
|
||||
|
||||
socket.on('connect', () => {
|
||||
console.log('Socket connected:', socket.id);
|
||||
});
|
||||
|
||||
socket.on('disconnect', (reason) => {
|
||||
console.log('Socket disconnected:', reason);
|
||||
});
|
||||
|
||||
const socket = io(import.meta.env.VITE_API_BASE_URL);
|
||||
commit('setSocket', socket);
|
||||
}
|
||||
},
|
||||
loadLoginState({ commit }) {
|
||||
commit('loadLoginState');
|
||||
},
|
||||
setLanguage({ commit }, language) {
|
||||
commit('setLanguage', language);
|
||||
},
|
||||
@@ -110,6 +91,7 @@ const store = createStore({
|
||||
language: state => state.language,
|
||||
menu: state => state.menu,
|
||||
socket: state => state.socket,
|
||||
menuNeedsUpdate: state => state.menuNeedsUpdate
|
||||
},
|
||||
modules: {
|
||||
dialogs,
|
||||
|
||||
@@ -13,12 +13,16 @@
|
||||
<div>
|
||||
<input v-model="username" size="20" type="text"
|
||||
:placeholder="$t('home.nologin.login.name')"
|
||||
:title="$t('home.nologin.login.namedescription')">
|
||||
:title="$t('home.nologin.login.namedescription')"
|
||||
@keydown.enter="focusPassword">
|
||||
</div>
|
||||
<div>
|
||||
<input v-model="password" size="20" type="password"
|
||||
:placeholder="$t('home.nologin.login.password')"
|
||||
:title="$t('home.nologin.login.passworddescription')">
|
||||
:title="$t('home.nologin.login.passworddescription')"
|
||||
@keydown.enter="doLogin"
|
||||
ref="passwordInput"
|
||||
>
|
||||
</div>
|
||||
<div>
|
||||
<label><input type="checkbox"><span>Eingeloggt bleiben</span></label>
|
||||
@@ -72,6 +76,9 @@ export default {
|
||||
openPasswordResetDialog() {
|
||||
this.$refs.passwordResetDialog.open();
|
||||
},
|
||||
focusPassword() {
|
||||
this.$refs.passwordInput.focus();
|
||||
},
|
||||
async doLogin() {
|
||||
try {
|
||||
const response = await apiClient.post('/api/auth/login', { username: this.username, password: this.password });
|
||||
|
||||
Reference in New Issue
Block a user