This commit is contained in:
Henry Jameson 2026-09-03 16:55:41 +03:00
commit 9fe60eb860
9 changed files with 56 additions and 31 deletions

View file

@ -57,7 +57,7 @@ export const useDraftsStore = defineStore('drafts', {
await deleteDraftFromStorage([id])
},
async loadDrafts() {
const currentData = await getStorageData()
const currentData = (await getStorageData()) ?? {}
this.drafts = new Map(Object.entries(currentData))
},
async addOrSaveDraft(draft) {
@ -67,9 +67,9 @@ export const useDraftsStore = defineStore('drafts', {
await saveDraftToStorage(draftWithId)
return id
},
async abandonAllDrafts(store) {
async abandonAllDrafts() {
const ids = [...this.drafts.keys()]
ids.forEach((id) => this.abandonDraft(id))
ids.forEach((id) => this.drafts.delete(id))
await deleteDraftFromStorage(ids)
},
},

View file

@ -15,7 +15,7 @@ export const useFollowRequestsStore = defineStore('followRequests', {
},
actions: {
startFetching() {
if (this.fetcher) throw 'Fetcher already exists!'
if (this.fetcher) throw new Error('Fetcher already exists!')
this.fetcher = followRequestFetcher({
credentials: useOAuthStore().token,
@ -24,8 +24,9 @@ export const useFollowRequestsStore = defineStore('followRequests', {
this.fetcher.startFetching()
},
stopFetching() {
if (!this.fetcher) throw "Fetcher doesn't exists!"
this.fetcher.stopFetching(), (this.fetcher = null)
if (!this.fetcher) throw new Error("Fetcher doesn't exists!")
this.fetcher.stopFetching()
this.fetcher = null
},
setFollowRequests(requests) {
this.requests = new Map(requests.map((user) => [user.id, user]))

View file

@ -1,5 +1,8 @@
import { defineStore } from 'pinia'
import { useShoutStore } from 'src/stores/shout.js'
import { useUsersStore } from 'src/stores/users.js'
const defaultState = {
postFormats: [],
mailerEnabled: false,
@ -38,6 +41,13 @@ export const useInstanceCapabilitiesStore = defineStore(
}
this[capability] = value
if (
capability === 'shoutAvailable' &&
useUsersStore().currentUser?.token
) {
useShoutStore().initializeSocket()
}
},
},
},

View file

@ -10,7 +10,6 @@ export const useShoutStore = defineStore('shout', {
messages: [],
channel: { state: '' },
joined: false,
token: null,
socket: null,
}),
getters: {
@ -20,7 +19,7 @@ export const useShoutStore = defineStore('shout', {
initializeSocket() {
if (this.token === null) return
if (!useInstanceCapabilitiesStore().shoutAvailable) return
if (this.socket !== null) throw new Error('Shout socket already exist!')
if (this.socket !== null) return
this.socket = new Socket('/socket', { params: { token: this.token } })
this.socket.connect()