Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add force recheck network connectivity button #679

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/components/Layout/TopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import QueueModal from '@/components/Dialogs/QueueModal';
import Button from '@/components/Input/Button';
import ShokoIcon from '@/components/ShokoIcon';
import toast from '@/components/Toast';
import { useGetSettingsQuery } from '@/core/rtkQuery/splitV3Api/settingsApi';
import { useCheckNetworkConnectivityMutation, useGetSettingsQuery } from '@/core/rtkQuery/splitV3Api/settingsApi';
import { useGetCurrentUserQuery } from '@/core/rtkQuery/splitV3Api/userApi';
import { useGetWebuiUpdateCheckQuery, usePostWebuiUpdateMutation } from '@/core/rtkQuery/splitV3Api/webuiApi';
import { setLayoutEditMode, setQueueModalOpen } from '@/core/slices/mainpage';
Expand Down Expand Up @@ -93,6 +93,8 @@ function TopNav() {
});
const [webuiUpdateTrigger, webuiUpdateResult] = usePostWebuiUpdateMutation();

const [checkNetworkConnectivity, checkNetworkConnectivityResult] = useCheckNetworkConnectivityMutation();

const currentUser = useGetCurrentUserQuery();

const [showUtilitiesMenu, setShowUtilitiesMenu] = useState(false);
Expand Down Expand Up @@ -266,14 +268,32 @@ function TopNav() {
</div>
)}
{isOffline && (
<div className="flex cursor-pointer items-center gap-x-2.5 font-semibold">
<Icon path={mdiInformationOutline} size={1} className="text-topnav-icon-warning" />
No Internet Connection.
</div>
<Button
className="flex items-center gap-x-2 font-semibold"
onClick={() => checkNetworkConnectivity()}
>
{checkNetworkConnectivityResult.isLoading
? (
<Icon
path={mdiLoading}
size={1}
className="text-panel-text-primary"
spin
/>
)
: (
<Icon
path={mdiInformationOutline}
size={1}
className="text-topnav-icon-warning"
/>
)}
No Internet Connection
</Button>
)}
<AniDBBanDetectionItem type="HTTP" banStatus={banStatus.http} />
<AniDBBanDetectionItem type="UDP" banStatus={banStatus.udp} />
<div className="flex gap-x-5">
<div className="flex items-center gap-x-5">
<ExternalLinkMenuItem url="https://discord.gg/vpeHDsg" icon={siDiscord.path} />
<ExternalLinkMenuItem url="https://docs.shokoanime.com" icon={mdiHelpCircleOutline} />
<ExternalLinkMenuItem url="https://github.com/ShokoAnime" icon={mdiGithub} />
Expand Down
9 changes: 9 additions & 0 deletions src/core/rtkQuery/splitV3Api/settingsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,19 @@ const settingsApi = splitV3Api.injectEndpoints({
responseHandler: 'text',
}),
}),

// Forcefully re-checks the current network connectivity, then returns the updated details for the server.
checkNetworkConnectivity: build.mutation<void, void>({
query: () => ({
url: 'Settings/Connectivity',
method: 'POST',
}),
}),
}),
});

export const {
useCheckNetworkConnectivityMutation,
useGetSettingsQuery,
usePatchSettingsMutation,
usePostAniDBTestLoginMutation,
Expand Down