Skip to content

Commit

Permalink
Revert "Story editor implementation" (#26)
Browse files Browse the repository at this point in the history
Reverts #25 because login does not work
  • Loading branch information
IceCandle authored Feb 1, 2025
1 parent 086e0ea commit a548544
Show file tree
Hide file tree
Showing 44 changed files with 2,352 additions and 1,038 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"postcss": "8.4.49",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-draggable": "4.4.6",
"react-intersection-observer": "9.15.1",
"react-router-dom": "7.1.1",
"tailwindcss": "3.4.17"
Expand Down
22 changes: 0 additions & 22 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import './index.css';
import { createContext, useState } from 'react';
import { Navigate, Route, Routes } from 'react-router-dom';

import StoryEditor from './components/story/Editor/StoryEditor';
import { useAuth } from './hooks/useAuth';
import ExplorePage from './pages/ExplorePage';
import FriendMapPage from './pages/FriendMapPage';
Expand All @@ -14,7 +13,6 @@ import PostDetailPage from './pages/PostDetailPage';
import ProfileEditPage from './pages/ProfileEditPage';
import ProfilePage from './pages/ProfilePage';
import RegisterPage from './pages/RegisterPage';
import StoryPage from './pages/StoryPage';
import type { LoginContextType } from './types/auth';
import type { SearchContextType } from './types/search';

Expand Down Expand Up @@ -61,26 +59,6 @@ export const App = () => {
path="/:username"
element={auth.isLoggedIn ? <ProfilePage /> : <Navigate to="/" />}
/>
<Route
path="/stories/:username/:storyId"
element={
auth.isLoggedIn ? (
<StoryPage />
) : (
<LoginPage handleIsLoggedIn={auth.handleIsLoggedIn} />
)
}
/>
<Route
path="/stories/new"
element={
auth.isLoggedIn ? (
<StoryEditor />
) : (
<LoginPage handleIsLoggedIn={auth.handleIsLoggedIn} />
)
}
/>
<Route
path="/accounts/edit"
element={
Expand Down
26 changes: 21 additions & 5 deletions src/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,28 @@ export const signin = async (username: string, password: string) => {
},
);

if (response.ok) {
const data = (await response.json()) as SignInResponse;
localStorage.setItem('access_token', data.access_token);
localStorage.setItem('refresh_token', data.refresh_token);
// First check if we got a JSON response
const contentType = response.headers.get('content-type');
if (contentType?.includes('application/json') === false) {
const text = await response.text();
console.error('Non-JSON response:', text);
throw new Error('Server returned non-JSON response');
}

return await myProfile(data.access_token);
if (response.ok) {
try {
const data = (await response.json()) as SignInResponse;
localStorage.setItem('access_token', data.access_token);
localStorage.setItem('refresh_token', data.refresh_token);
const profileResponse = await myProfile(data.access_token);
if (profileResponse === null) {
throw new Error('Failed to fetch user profile');
}
return profileResponse;
} catch (err) {
console.error('Error parsing JSON response:', err);
throw new Error('Invalid response format from server');
}
}

if (response.status === 401) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/feed/Stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StoryList } from '../story/StoryList';
import { StoryList } from '../story/list/StoryList';

export function Stories() {
return <StoryList />;
Expand Down
11 changes: 10 additions & 1 deletion src/components/layout/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useContext, useEffect, useState } from 'react';
import { Link, useLocation } from 'react-router-dom';

import { LoginContext } from '../../App';
import CreatePostModal from '../modals/CreatePostModal';
import { NavItem } from './NavItem';

interface SideBarProps {
Expand All @@ -21,7 +22,7 @@ interface SideBarProps {
const SideBar = ({ onSearchClick }: SideBarProps) => {
const [isMenuOpen, setIsMenuOpen] = useState(false);
const [activeItem, setActiveItem] = useState('home');
const [, setIsCreateModalOpen] = useState(false);
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
const location = useLocation();

const context = useContext(LoginContext);
Expand Down Expand Up @@ -100,6 +101,14 @@ const SideBar = ({ onSearchClick }: SideBarProps) => {
handleCreateClick('create');
}}
/>
{isCreateModalOpen && (
<CreatePostModal
isOpen={isCreateModalOpen}
onClose={() => {
setIsCreateModalOpen(false);
}}
/>
)}
<Link to={`/${String(context.myProfile?.username)}`}>
<NavItem
icon={<User />}
Expand Down
5 changes: 0 additions & 5 deletions src/components/shared/default-profile.svg

This file was deleted.

156 changes: 0 additions & 156 deletions src/components/story/Editor/ImageProcessor.tsx

This file was deleted.

92 changes: 0 additions & 92 deletions src/components/story/Editor/StoryEditor.tsx

This file was deleted.

Loading

0 comments on commit a548544

Please sign in to comment.