From 0b95bbac6716852cb7d0a66a868b5d09341d09eb Mon Sep 17 00:00:00 2001 From: GarandPLG Date: Wed, 11 Sep 2024 16:03:46 +0200 Subject: [PATCH] =?UTF-8?q?Przebudowanie=20headera=20z=20my=C5=9Bl=C4=85?= =?UTF-8?q?=20pod=20mobilne=20przegl=C4=85darki.=20Zmiana=20adresu=20urb?= =?UTF-8?q?=20pocketbase.=20Dodanie=20mo=C5=BCliwo=C5=9Bci=20zmieniania=20?= =?UTF-8?q?nazwy=20u=C5=BCytkownika.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Header.tsx | 47 +++++++++++++++++++++++++-------------- src/lib/pocketbase.ts | 2 +- src/pages/Home.tsx | 1 - src/pages/Profile.tsx | 17 ++++++++++++-- src/pages/Register.tsx | 3 --- 5 files changed, 46 insertions(+), 24 deletions(-) diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 27f017c..8529dad 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -15,23 +15,36 @@ const Header: React.FC = () => { return (
-
- Reddit-Like-App - Kod źródłowy - +
+ Reddit-Like-App + + | + + Kod źródłowy + + | + + {isAuth ? ( + <> + Stwórz post + + | + + Profil + + | + + + + ) : ( + <> + Zaloguj się + + | + + Zarejestruj się + + )}
); diff --git a/src/lib/pocketbase.ts b/src/lib/pocketbase.ts index 33a3731..50931f1 100644 --- a/src/lib/pocketbase.ts +++ b/src/lib/pocketbase.ts @@ -1,6 +1,6 @@ import PocketBase from 'pocketbase'; -export const pb = new PocketBase('https://pb.garandplg.com').autoCancellation(false); +export const pb = new PocketBase('https://rla-pb.garandplg.com').autoCancellation(false); // Inicjacja połączenia z moją instancją pocketbase // oraz wyeksportowanie tego połączenia diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index a68e2e9..1651ec7 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -19,7 +19,6 @@ const Home: React.FC = () => { try { const records = await pb.collection('posts').getFullList({ sort: '-votes', - expand: 'user', }); setPosts(records); } catch (error) { diff --git a/src/pages/Profile.tsx b/src/pages/Profile.tsx index 757566e..39ab98a 100644 --- a/src/pages/Profile.tsx +++ b/src/pages/Profile.tsx @@ -5,6 +5,7 @@ import { updateAuthAtom } from '../atoms/authAtom'; const Profile: React.FC = () => { const [email, setEmail] = useState(''); + const [username, setUsername] = useState(''); const [newPassword, setNewPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [, updateAuth] = useAtom(updateAuthAtom); @@ -23,7 +24,7 @@ const Profile: React.FC = () => { } try { - const data: Record = { email }; + const data: Record = { email, username }; if (newPassword) { data.password = newPassword; data.passwordConfirm = confirmPassword; @@ -47,7 +48,7 @@ const Profile: React.FC = () => { alert('Konto poprawnie usunięte'); } catch (error) { console.error('Błąd z usuwaniem konta:', error); - alert('Nie udało się usunąc konta.'); + alert('Nie udało się usunąć konta.'); } } }; @@ -67,12 +68,24 @@ const Profile: React.FC = () => { className="w-full px-3 py-2 border rounded" /> +
+ + setUsername(e.target.value)} + required + className="w-full px-3 py-2 border rounded" + /> +
setNewPassword(e.target.value)} className="w-full px-3 py-2 border rounded" /> diff --git a/src/pages/Register.tsx b/src/pages/Register.tsx index 3533f51..b13c1f0 100644 --- a/src/pages/Register.tsx +++ b/src/pages/Register.tsx @@ -1,15 +1,12 @@ import React, { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { pb } from '../lib/pocketbase'; -import { useAtom } from 'jotai'; -import { updateAuthAtom } from '../atoms/authAtom'; const Register: React.FC = () => { const [email, setEmail] = useState(''); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [passwordConfirm, setPasswordConfirm] = useState(''); - const [, updateAuth] = useAtom(updateAuthAtom); const navigate = useNavigate(); const handleSubmit = async (e: React.FormEvent) => {