Skip to content

Commit dbce445

Browse files
authored
chore: improve RootState typings (#789)
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
1 parent 06910a3 commit dbce445

26 files changed

Lines changed: 84 additions & 83 deletions

File tree

src/api/httpClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ const responseInterceptor = (response: AxiosResponse) => {
6666
// We can reasonably assume that successfull moonraker responses
6767
// determine a user is trusted or authenticated in some way.
6868
if (
69-
store.state.config?.apiUrl &&
70-
response.config.baseURL === store.state.config?.apiUrl &&
69+
store.state.config.apiUrl &&
70+
response.config.baseURL === store.state.config.apiUrl &&
7171
response.config.withAuth
7272
) {
7373
// Set authenticated to true.

src/api/socketActions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const baseEmit = (method: string, options: NotifyOptions) => {
1111
return
1212
}
1313
if (
14-
!store.state.socket?.disconnecting &&
15-
!store.state.socket?.connecting
14+
!store.state.socket.disconnecting &&
15+
!store.state.socket.connecting
1616
) {
1717
Vue.$socket.emit(method, options)
1818
} else {
@@ -330,7 +330,7 @@ export const SocketActions = {
330330
dispatch: 'socket/onConnectionId',
331331
params: {
332332
client_name: Globals.APP_NAME,
333-
version: `${store.state.version?.fluidd.version || '0.0.0'}-${store.state.version?.fluidd.hash || 'unknown'}`.trim(),
333+
version: `${store.state.version.fluidd.version || '0.0.0'}-${store.state.version.fluidd.hash || 'unknown'}`.trim(),
334334
type: 'web',
335335
url: Globals.GITHUB_REPO
336336
}

src/components/widgets/gcode-preview/GcodePreviewCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export default class GcodePreviewCard extends Mixins(StateMixin, FilesMixin) {
252252
@Watch('fileLoaded')
253253
onFileLoaded () {
254254
if (this.fileLoaded &&
255-
this.$store.state.config?.uiSettings.gcodePreview.autoFollowOnFileLoad &&
255+
this.$store.state.config.uiSettings.gcodePreview.autoFollowOnFileLoad &&
256256
this.printerFileLoaded) {
257257
this.$store.commit('gcodePreview/setViewerState', { followProgress: true }, { root: true })
258258
}

src/components/widgets/system/SystemLoadChart.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default class SystemLoadChart extends Vue {
3131
}
3232
3333
get cores () {
34-
return this.$store.state.server?.system_info?.cpu_info?.cpu_count || 1
34+
return this.$store.state.server.system_info?.cpu_info?.cpu_count || 1
3535
}
3636
3737
get options () {

src/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export const appInit = async (apiConfig?: ApiConfig, hostConfig?: HostConfig): P
149149
await store.dispatch('init', { apiConfig, hostConfig, apiConnected })
150150

151151
// Ensure users start on the dash.
152-
if (router.currentRoute.path !== '/' && store.state.auth?.authenticated) router.push('/')
152+
if (router.currentRoute.path !== '/' && store.state.auth.authenticated) router.push('/')
153153

154154
return { apiConfig, hostConfig, apiConnected, apiAuthenticated }
155155
}

src/mixins/files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ export default class FilesMixin extends Vue {
253253
: '/' + filepath
254254
const fileState = this.$store.state.files.uploads.find((u: FilesUpload) => u.filepath === filepath)
255255
// consola.error('about to process...', fileState)
256-
if (!fileState.cancelled) {
256+
if (fileState && !fileState?.cancelled) {
257257
try {
258258
this.cancelTokenSource = Axios.CancelToken.source()
259259
await this.uploadFile(file, path, root, andPrint, {

src/plugins/i18n.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Vue.use(VueI18n)
1111
*/
1212
export const getStartingLocale = () => {
1313
const browserLocale = getBrowserLocale({ countryCodeOnly: true })
14-
const supportedLocales = store.state.config?.hostConfig.locales
14+
const supportedLocales = store.state.config.hostConfig.locales
1515
if (
1616
supportedLocales &&
1717
browserLocale &&

src/plugins/socketClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class WebSocketClient {
4040
// We have a connection again, so set the socket properties
4141
// appropriately.
4242
if (
43-
!this.store.state.socket?.disconnecting && // We arent about to disonnect and..
43+
!this.store.state.socket.disconnecting && // We arent about to disonnect and..
4444
!this.store.state.files.download // We're not in the middle of a download.
4545
) {
4646
this.store.commit('socket/setSocketOpen', true)
@@ -49,7 +49,7 @@ export class WebSocketClient {
4949

5050
this.pingTimeout = setTimeout(() => {
5151
if (
52-
!this.store.state.socket?.disconnecting && // We arent about to disonnect and..
52+
!this.store.state.socket.disconnecting && // We arent about to disonnect and..
5353
!this.store.state.files.download // We're not in the middle of a download.
5454
) {
5555
// In the event our socket stops responding, set the socket properties

src/router/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Vue.use(VueRouter)
2424
const ifAuthenticated = (to: Route, from: Route, next: NavigationGuardNext<Vue>) => {
2525
if (
2626
store.getters['auth/getAuthenticated'] ||
27-
!store.state.socket?.apiConnected
27+
!store.state.socket.apiConnected
2828
) {
2929
next()
3030
return

src/store/auth/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const actions: ActionTree<AuthState, RootState> = {
4343
// No known API?
4444
// This is likely a new setup with no known instances yet. Set auth to true
4545
// and move on until we know more.
46-
if (rootState.config?.apiUrl === '') {
46+
if (rootState.config.apiUrl === '') {
4747
commit('setAuthenticated', true)
4848
return
4949
}

0 commit comments

Comments
 (0)