Skip to content

Commit

Permalink
Move hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Nov 26, 2023
1 parent 166dd79 commit fde81c1
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 36 deletions.
4 changes: 2 additions & 2 deletions apps/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { ChannelView } from "./views/channel";
import { SettingsView } from "./views/settings";
import { ErrorView } from "./views/error";
import { NavBar } from "./components/nav-bar";
import { useClickthrough } from "./use-clickthrough";
import { useDisableWebFeatures } from "./use-disable-context-menu";
import { useClickthrough } from "./hooks/use-clickthrough";
import { useDisableWebFeatures } from "./hooks/use-disable-context-menu";
import { useEffect } from "react";
import { invoke } from "@tauri-apps/api";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import { listen } from "@tauri-apps/api/event";
import overlayedConfig from "./config";
import overlayedConfig from "../config";
import { invoke } from "@tauri-apps/api";

export const useClickthrough = () => {
Expand Down
43 changes: 43 additions & 0 deletions apps/desktop/src/hooks/use-platform-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useEffect, useState } from "react";

import { getTauriVersion, getVersion } from "@tauri-apps/api/app";
import { appConfigDir } from "@tauri-apps/api/path";
import { platform as getPlatform, version as getKernalVersion, arch as getArch } from "@tauri-apps/api/os";

export const usePlatformInfo = () => {
const [platformInfo, setPlatformInfo] = useState({
appVersion: "",
tauriVersion: "",
os: "",
kernalVersion: "",
arch: "",
configDir: "",
});

useEffect(() => {
const allPromises = [getTauriVersion(), getVersion(), getPlatform(), getKernalVersion(), getArch(), appConfigDir()];

// get all the dataz
Promise.allSettled(allPromises).then(results => {
const [tauriVersion = "", appVersion = "", os = "", kernalVersion = "", arch = "", configDir = ""] = results.map(
result => {
if (result.status === "fulfilled") {
return result.value;
}
return "";
}
);

setPlatformInfo({
tauriVersion,
appVersion,
os,
kernalVersion,
arch,
configDir,
});
});
}, []);

return platformInfo;
};
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion apps/desktop/src/views/error.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Link } from "react-router-dom";
import { Button } from "@/components/ui/button";
import { useSetWindowSize } from "../use-set-size";
import { useSetWindowSize } from "../hooks/use-set-size";
import { useAppStore } from "../store";

export const ErrorView = () => {
Expand Down
34 changes: 2 additions & 32 deletions apps/desktop/src/views/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,17 @@ import {
import { useEffect, useState } from "react";
import { invoke } from "@tauri-apps/api";
import { Link } from "@/components/ui/link";
import { usePlatformInfo } from "@/hooks/use-platform-info";

export const SettingsView = () => {
const navigate = useNavigate();
const { me, setMe } = useAppStore();
const [showLogoutDialog, setShowLogoutDialog] = useState(false);
const [showQuitDialog, setShowQuitDialog] = useState(false);
const [tokenExpires, setTokenExpires] = useState<string | null>(null);

const [platformInfo, setPlatformInfo] = useState({
appVersion: "",
tauriVersion: "",
os: "",
kernalVersion: "",
arch: "",
configDir: "",
});
const platformInfo = usePlatformInfo();

useEffect(() => {
const allPromises = [getTauriVersion(), getVersion(), getPlatform(), getKernalVersion(), getArch(), appConfigDir()];

// get all the dataz
Promise.allSettled(allPromises).then(results => {
const [tauriVersion = "", appVersion = "", os = "", kernalVersion = "", arch = "", configDir = ""] = results.map(
result => {
if (result.status === "fulfilled") {
return result.value;
}
return "";
}
);

setPlatformInfo({
tauriVersion,
appVersion,
os,
kernalVersion,
arch,
configDir,
});
});

const token = localStorage.getItem("discord_expires_at");
if (token) {
setTokenExpires(token);
Expand Down

0 comments on commit fde81c1

Please sign in to comment.