Skip to content

Commit

Permalink
Update geoip & improve settings
Browse files Browse the repository at this point in the history
Update settings sidebar
  • Loading branch information
lucemans committed Dec 18, 2024
1 parent 1499802 commit 318bccc
Show file tree
Hide file tree
Showing 19 changed files with 486 additions and 174 deletions.
10 changes: 5 additions & 5 deletions web/src/api/geoip.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { useQuery, UseQueryOptions } from '@tanstack/react-query';

import { getHttp } from './core';

type GeoIpResponse = {
ip_address: string;
latitude: number;
Expand All @@ -21,9 +19,11 @@ type GeoIpResponse = {

export const getGeoIp = (ip: string): UseQueryOptions<GeoIpResponse> => ({
queryKey: ['geoip', ip],
queryFn: getHttp('/api/geoip', {
auth: 'include',
}),
queryFn: async () => {
const response = await fetch(`https://api.geoip.rs/?ip=${ip}`);

return (await response.json()) as GeoIpResponse;
},
});

export function useGeoIp(ip: string) {
Expand Down
73 changes: 32 additions & 41 deletions web/src/components/settings/BuildDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,40 @@ export const BuildDetails = () => {
instanceSettings.build_info.git_hash;

return (
<div className="space-y-2">
<h2 className="h2">Build Details</h2>
<div className="card space-y-2">
{instanceVersion?.update_available ? (
<div className="card bg-primary-foreground">
<div className="font-bold">Update available</div>
<div className="">
You are running{' '}
<code className="code">
{instanceVersion?.version}
</code>{' '}
but{' '}
<code className="code">
{instanceVersion?.latest}
</code>{' '}
is available!
</div>
</div>
) : (
<div>You are on the latest</div>
)}
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<div>
<a href={github_link} className="link" target="_blank">
<span>v3xlabs/v3x-property/engine@</span>
<span>
sha-{instanceSettings?.build_info.git_hash}
</span>
</a>
</div>
<div className="gap-2 flex flex-row">
<span>Running on</span>
<span>{instanceSettings?.build_info.target}</span>
</div>
<div className="gap-2 flex flex-row">
<span>Version</span>
<span>v{instanceSettings?.build_info.version}</span>
</div>
<div className="gap-2 flex flex-row">
<span>Timestamp</span>
<span>{instanceSettings?.build_info.timestamp}</span>
<div className="card space-y-2">
{instanceVersion?.update_available ? (
<div className="card bg-primary-foreground">
<div className="font-bold">Update available</div>
<div className="">
You are running{' '}
<code className="code">{instanceVersion?.version}</code>{' '}
but{' '}
<code className="code">{instanceVersion?.latest}</code>{' '}
is available!
</div>
</div>
) : (
<div>You are on the latest</div>
)}
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<div>
<a href={github_link} className="link" target="_blank">
<span>v3xlabs/v3x-property/engine@</span>
<span>sha-{instanceSettings?.build_info.git_hash}</span>
</a>
</div>
<div className="gap-2 flex flex-row">
<span>Running on</span>
<span>{instanceSettings?.build_info.target}</span>
</div>
<div className="gap-2 flex flex-row">
<span>Version</span>
<span>v{instanceSettings?.build_info.version}</span>
</div>
<div className="gap-2 flex flex-row">
<span>Timestamp</span>
<span>{instanceSettings?.build_info.timestamp}</span>
</div>
</div>
</div>
);
Expand Down
5 changes: 2 additions & 3 deletions web/src/components/settings/IntelligenceDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ export const IntelligenceDetails = () => {
}

return (
<div className="space-y-2">
<h2 className="h2">Intelligence</h2>
<>
<div className="card space-y-3">
<div className="flex items-center gap-2">
<FaBrain />
Expand Down Expand Up @@ -129,6 +128,6 @@ export const IntelligenceDetails = () => {
</div>
</>
)}
</div>
</>
);
};
29 changes: 13 additions & 16 deletions web/src/components/settings/SearchDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,19 @@ export const SearchDetails = () => {
});

return (
<div className="space-y-2">
<h2 className="h2">Search</h2>
<div className="space-y-2.5 card">
<div className="flex flex-row gap-2 items-center">
<SiMeilisearch />
<h3 className="font-bold">Meilisearch</h3>
</div>
<p>
Meilisearch is the search engine that allows you to search
for items in the database.
</p>
<div className="flex gap-2">
<Button onClick={() => indexAllItems()} variant="primary">
Index All Items
</Button>
</div>
<div className="space-y-2.5 card">
<div className="flex flex-row gap-2 items-center">
<SiMeilisearch />
<h3 className="font-bold">Meilisearch</h3>
</div>
<p>
Meilisearch is the search engine that allows you to search for
items in the database.
</p>
<div className="flex gap-2">
<Button onClick={() => indexAllItems()} variant="primary">
Index All Items
</Button>
</div>
</div>
);
Expand Down
82 changes: 39 additions & 43 deletions web/src/components/settings/StorageDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,50 @@ export const StorageDetails = () => {
}

return (
<div className="space-y-2">
<h2 className="h2">Storage</h2>
<div className="card flex flex-col justify-between md:flex-row gap-4">
<div className="w-full space-y-2">
<h2 className="font-bold">S3-Compatible Object Storage</h2>
<p>Your media is stored in S3-compatible object storage.</p>
<ul className="grid grid-cols-1 md:grid-cols-2 gap-4">
{(
<div className="card flex flex-col justify-between md:flex-row gap-4">
<div className="w-full space-y-2">
<h2 className="font-bold">S3-Compatible Object Storage</h2>
<p>Your media is stored in S3-compatible object storage.</p>
<ul className="grid grid-cols-1 md:grid-cols-2 gap-4">
{(
[
[
[
'Storage Used',
prettyBytes(
storageStatistics?.bucket_disk_size ?? 0
),
],
[
'Files',
storageStatistics?.bucket_file_count ?? 0,
],
[
'Endpoint',
instanceSettings.modules.storage
.endpoint_url,
undefined,
],
[
'Bucket',
instanceSettings.modules.storage.bucket,
<FaBucket />,
],
] as const
).map(([key, value, icon]) => (
<li key={key} className="gap-2 flex flex-col">
<span className="font-bold">{key}</span>
<span className="flex items-center gap-0.5">
{icon}
<span>{value}</span>
</span>
</li>
))}
</ul>
</div>
{/* <div className="md:max-w-md text-sm w-fit text-end text-neutral-500">
'Storage Used',
prettyBytes(
storageStatistics?.bucket_disk_size ?? 0
),
],
[
'Files',
storageStatistics?.bucket_file_count ?? 0,
],
[
'Endpoint',
instanceSettings.modules.storage.endpoint_url,
undefined,
],
[
'Bucket',
instanceSettings.modules.storage.bucket,
<FaBucket />,
],
] as const
).map(([key, value, icon]) => (
<li key={key} className="gap-2 flex flex-col">
<span className="font-bold">{key}</span>
<span className="flex items-center gap-0.5">
{icon}
<span>{value}</span>
</span>
</li>
))}
</ul>
</div>
{/* <div className="md:max-w-md text-sm w-fit text-end text-neutral-500">
To setup storage you need to specify{' '}
<code>S3_ENDPOINT_URL</code>, <code>S3_BUCKET_NAME</code>,{' '}
<code>S3_ACCESS_KEY</code>, and <code>S3_SECRET_KEY</code>
</div> */}
</div>
</div>
);
};
81 changes: 81 additions & 0 deletions web/src/components/settings/nav.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Link } from '@tanstack/react-router';
import clsx from 'clsx';
import {
LuBrain,
LuClock,
LuHardDrive,
LuKey,
LuScroll,
LuSearch,
LuSettings,
} from 'react-icons/lu';

export const SettingsNav = () => {
return (
<ul className="flex flex-col divide-y">
{(
[
['', [['/settings', 'General', <LuSettings />]]],
[
'Instance Settings',
[
['/settings/search', 'Search', <LuSearch />],
[
'/settings/intelligence',
'Intelligence',
<LuBrain />,
],
['/settings/storage', 'Storage', <LuHardDrive />],
],
],
[
'Authentication',
[
['/settings/sessions', 'Sessions', <LuClock />],
[
'/settings/pat',
'Personal Access Token',
<LuKey />,
],
],
],
[
'System',
[['/settings/build', 'Software Info', <LuScroll />]],
],
] as const
).map(([group, items]) => (
<div key={group}>
{group != '' && (
<h3 className="text-sm pt-4 px-2 pl-4 pb-1 text-neutral-500 font-bold">
{group}
</h3>
)}
<ul className="flex flex-col pb-4 pl-2">
{items.map(([path, label, icon]) => (
<li
key={path}
className={clsx('gap-1 flex items-center')}
>
<Link
to={path}
activeOptions={{ exact: true }}
className={clsx(
'py-1 px-2 hover:bg-neutral-100 rounded-md flex items-center relative gap-2 cursor-pointer w-full text-neutral-700',
'[&.active]:text-primary [&.active]:bg-neutral-500/10',
// eslint-disable-next-line quotes
"[&.active]:before:content-['']",
'[&.active]:before:absolute [&.active]:before:-left-3 [&.active]:before:top-[12%] [&.active]:before:w-1 [&.active]:before:bottom-[12%] [&.active]:before:bg-blue-500 [&.active]:before:rounded-md'
)}
>
{icon}
{label}
</Link>
</li>
))}
</ul>
</div>
))}
</ul>
);
};
44 changes: 44 additions & 0 deletions web/src/layouts/SidebarPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { ClassValue } from 'clsx';
import { FC, PropsWithChildren, ReactNode, useEffect } from 'react';

import { cn } from '@/util/style';
import { getTitle } from '@/util/title';

export type SidePageProperties = PropsWithChildren<{
title: string;
width?: 'xl' | '2xl' | '3xl' | '4xl';
suffix?: ReactNode;
className?: ClassValue;
sidebar?: ReactNode;
}>;

export const SidePage: FC<SidePageProperties> = ({
children,
title,
width = '2xl',
suffix,
className,
sidebar,
}) => {
useEffect(() => {
document.title = getTitle(title);
}, [title]);

return (
<div
className={cn(
'p-4 mt-8 mx-auto w-full space-y-4 pb-64 flex gap-8 justify-center md:flex-row flex-col',
className
)}
>
{sidebar && <div className="w-full md:max-w-64">{sidebar}</div>}
<div className="w-full max-w-xl lg:max-w-2xl space-y-4">
<div className="flex items-end justify-between">
<h1 className="h1 pl-4">{title}</h1>
{suffix}
</div>
{children}
</div>
</div>
);
};
Loading

0 comments on commit 318bccc

Please sign in to comment.