diff --git a/package.json b/package.json index ac02431..b93c4ba 100644 --- a/package.json +++ b/package.json @@ -20,13 +20,15 @@ "next": "14.2.6", "react": "^18.3.1", "react-dom": "^18.3.1", - "showdown": "^2.1.0" + "showdown": "^2.1.0", + "ua-parser-js": "^1.0.38" }, "devDependencies": { "@types/cookie": "^0.6.0", "@types/node": "^20.16.2", "@types/react": "^18.3.4", "@types/react-dom": "^18.3.0", + "@types/ua-parser-js": "^0.7.39", "eslint": "^8.57.0", "eslint-config-next": "14.2.6", "sass": "^1.77.8", diff --git a/pages/settings.tsx b/pages/settings.tsx index e6fff9f..eb2db7e 100644 --- a/pages/settings.tsx +++ b/pages/settings.tsx @@ -9,17 +9,20 @@ import { useEffect, useState } from 'react'; import cookie from 'cookie'; import Meta from '@/components/Meta'; +import { UAParser } from 'ua-parser-js'; + +import styles from '@/styles/Settings.module.scss'; +import { X } from 'lucide-react'; + interface SettingsType { animations: boolean; ads: boolean; - language: string; } export default function Settings({ sessions }: { sessions: any[] }) { const [ settings, setSettings ] = useState({ animations: true, - ads: true, - language: 'en' + ads: true }); useEffect(() => { @@ -34,6 +37,9 @@ export default function Settings({ sessions }: { sessions: any[] }) { localStorage.setItem('crss_settings', JSON.stringify(settings)); }, [ settings ]); + const currentSession = sessions.find(s => s.current); + const otherSessions = sessions.filter(s => !s.current); + return ( <> @@ -42,54 +48,52 @@ export default function Settings({ sessions }: { sessions: any[] }) {

Settings

-
-
+ { /* TODO: Move it to the css 😒 */ } +
+
setSettings({ ...settings, animations: e.target.checked })} />
-
+
setSettings({ ...settings, ads: e.target.checked })} />
- -
- - -

Sessions

- - - - - - - - - - - {sessions.map(session => ( - - - - - - - ))} - -
User AgentCreatedExpiresActions
{session.user_agent}{new Date(session.created).toLocaleDateString('hu-HU')}{new Date(session.expires).toLocaleDateString('hu-HU')} - {session.current ? ( - - ) : ( - - )} -
+

+ View and manage your active sessions. +

+ +

Current Session

+ +
+
+
+

{currentSession.user_agent.os.name} {currentSession.user_agent.os.version} • {currentSession.user_agent.browser.name} {currentSession.user_agent.browser.version}

+

{new Date(currentSession.created).toLocaleString('en-GB')}

+
+
+
+ +

Other Sessions

+ +
+ {otherSessions.map(session => ( +
+
+

{session.user_agent.os.name} {session.user_agent.os.version} • {session.user_agent.browser.name} {session.user_agent.browser.version}

+

{new Date(session.created).toLocaleString('en-GB')}

+
+ + +
+ ))} +