Skip to content

Commit

Permalink
Frontend logs (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzania authored Oct 5, 2023
1 parent 544cd94 commit 94930df
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pub async fn all_locations(
instance_id: i64,
app_state: State<'_, AppState>,
) -> Result<Vec<LocationInfo>, String> {
debug!("Retrieving all locations");
debug!("Retrieving all locations.");
let locations = Location::find_by_instance_id(&app_state.get_pool(), instance_id)
.await
.map_err(|err| err.to_string())?;
Expand Down Expand Up @@ -345,7 +345,7 @@ pub async fn update_instance(
}
}
transaction.commit().await.map_err(|err| err.to_string())?;
info!("Updated instance with id: {}.", instance_id);
debug!("Updated instance with id: {}.", instance_id);
Ok(())
} else {
Err("Instance not found".into())
Expand Down
3 changes: 2 additions & 1 deletion src/pages/client/components/LocationsList/LocationsList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { listen, UnlistenFn } from '@tauri-apps/api/event';
import { useEffect } from 'react';
import { debug } from 'tauri-plugin-log-api';
import { debug, error } from 'tauri-plugin-log-api';

import { clientApi } from '../../clientAPI/clientApi';
import { useClientStore } from '../../hooks/useClientStore';
Expand All @@ -23,6 +23,7 @@ export const LocationsList = ({ layoutType }: Props) => {
queryKey: [clientQueryKeys.getLocations, selectedInstance as number],
queryFn: () => getLocations({ instanceId: selectedInstance as number }),
enabled: !!selectedInstance,
onError: (e) => error(`Error retrieving locations: ${String(e)}`),
});

// listen to connection changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './style.scss';

import classNames from 'classnames';
import { useState } from 'react';
import { error } from 'tauri-plugin-log-api';

import { useI18nContext } from '../../../../../../i18n/i18n-react';
import SvgIconCheckmarkSmall from '../../../../../../shared/components/svg/IconCheckmarkSmall';
Expand Down Expand Up @@ -44,6 +45,7 @@ export const LocationCardConnectButton = ({ location }: Props) => {
} catch (e) {
setIsLoading(false);
toaster.error(LL.common.messages.error());
error(`Error handling interface: ${e}`);
console.error(e);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './style.scss';

import { useQuery } from '@tanstack/react-query';
import { useMemo, useState } from 'react';
import { error } from 'tauri-plugin-log-api';

import { Card } from '../../../../../../shared/defguard-ui/components/Layout/Card/Card';
import { CardTabs } from '../../../../../../shared/defguard-ui/components/Layout/CardTabs/CardTabs';
Expand Down Expand Up @@ -34,17 +35,26 @@ export const LocationsDetailView = ({ locations }: Props) => {
queryKey: [clientQueryKeys.getLocationStats, activeLocationId as number],
queryFn: () => getLocationStats({ locationId: activeLocationId as number }),
enabled: !!activeLocationId,
onError: (e) => {
error(`Error retrieving location stats: ${e}`);
},
});

const { data: connectionHistory } = useQuery({
queryKey: [clientQueryKeys.getConnectionHistory, activeLocationId as number],
queryFn: () => getConnectionHistory({ locationId: activeLocationId as number }),
enabled: !!activeLocationId,
onError: (e) => {
error(`Error retrieving connection history: ${e}`);
},
});
const { data: lastConnection } = useQuery({
queryKey: [clientQueryKeys.getConnections, activeLocationId as number],
queryFn: () => getLastConnection({ locationId: activeLocationId as number }),
enabled: !!activeLocationId,
onError: (e) => {
error(`Error retrieving last connection: ${e}`);
},
});

const tabs = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './style.scss';

import { useQuery } from '@tanstack/react-query';
import classNames from 'classnames';
import { error } from 'tauri-plugin-log-api';

import { useI18nContext } from '../../../../../../i18n/i18n-react';
import { Card } from '../../../../../../shared/defguard-ui/components/Layout/Card/Card';
Expand Down Expand Up @@ -47,11 +48,17 @@ const GridItem = ({ location }: GridItemProps) => {
queryKey: [clientQueryKeys.getConnections, location.id as number],
queryFn: () => getLastConnection({ locationId: location.id as number }),
enabled: !!location.id,
onError: (e) => {
error(`Error retrieving last connection: ${String(e)}`);
},
});
const { data: locationStats } = useQuery({
queryKey: [clientQueryKeys.getLocationStats, location.id as number],
queryFn: () => getLocationStats({ locationId: location.id as number }),
enabled: !!location.id,
onError: (e) => {
error(`Error retrieving location stats: ${String(e)}`);
},
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { invoke } from '@tauri-apps/api/tauri';
import { isUndefined } from 'lodash-es';
import { useMemo, useState } from 'react';
import { SubmitHandler, useForm } from 'react-hook-form';
import { error } from 'tauri-plugin-log-api';
import { z } from 'zod';

import { useI18nContext } from '../../../../../../i18n/i18n-react';
Expand Down Expand Up @@ -57,13 +58,16 @@ export const DekstopSetup = () => {
onError: (e) => {
toaster.error(LL.common.messages.error());
console.error(e);
error(String(e));
},
});

const { isLoading: loadingCreateDevice, mutateAsync: createDeviceMutation } =
useMutation({
mutationFn: createDevice,
onError: () => {},
onError: (e) => {
error(String(e));
},
});

const schema = useMemo(
Expand Down Expand Up @@ -104,6 +108,7 @@ export const DekstopSetup = () => {
.catch((e) => {
setIsLoading(false);
console.error(e);
error(e);
});
});
};
Expand Down

0 comments on commit 94930df

Please sign in to comment.