Built Twitter Like App - 7

Install Zustand

1
npm install zustand

Add Hooks

Add file hooks/useLoginModal.ts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { create } from "zustand";

interface LoginModalStore{
isOpen: boolean;
onOpen: ()=> void;
onClose: ()=> void;
};

const useLoginModal = create<LoginModalStore>((set) =>({
isOpen: true,
onOpen: () => set({ isOpen: true}),
onClose: () => set({ isOpen: false})
}));

export default useLoginModal;
More...

Built Twitter Like App - 6

Add ModalBox

Modify file pages/_app.tsx:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import '../styles/globals.css'
import type { AppProps } from 'next/app'

import Layout from '../components/Layout'
import ModalBox from '../components/ModalBox'

export default function App({ Component, pageProps }: AppProps) {
return (
<>
<ModalBox actionLabel='Submit' isOpen title='Test Modal' />
<Layout>
<Component {...pageProps} />
</Layout>
</>
)
}

More...

Built Twitter Like App - 4

Add FollowBar

Modify file conmponent/Layout.tsx:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import FollowBar from "./layout/FollowBar";
import Sidebar from "./layout/Siderbar";

interface LayoutProps{
children: React.ReactNode;
}

const Layout:React.FC<LayoutProps> = ({ children }) => {
return (
<div className="h-screen bg-black">
<div className="container h-full mx-auto xl:px-30 max-w-6xl">
<div className="grid grid-cols-4 h-full">
<Sidebar />
<div className="
col-span-3
lg:col-span-2
border-x-[1px]
border-neutral-800
">
{ children }
</div>
<FollowBar />
</div>
</div>
</div>
);
}

export default Layout;
More...

Built Twitter Like App - 3

Install Icon

1
npm install react-icons

Add Sidebar Item

Modify file conmponent/layout/Sidebar.tsx:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { BsHouseFill, BsBellFill } from 'react-icons/bs'
import { FaUser } from 'react-icons/fa'
import { BiLogOut } from 'react-icons/bi'

import SidebarLog from './SidebarLogo'
import SidebarItem from './SidebarItem'
import SiderbarTweetButton from './SiderbarTweetButton'

const Sidebar = () => {
const items = [
{
label: 'Home',
href:'/',
icon: BsHouseFill
},
{
label: 'Notifications',
href:'/notifications',
icon: BsBellFill
},
{
label: 'Profile',
href:'/users/123',
icon: FaUser
},

]

return(
<div className='col-span-1 h-full pr-4 pr-6'>
<div className='flex flex-col items-end'>
<div className='space-y-2 lg:w-[230px]'>
<SidebarLog />
{items.map((item) =>(
<SidebarItem
key={item.href}
href={item.href}
label={item.label}
icon={item.icon}
/>
))}

<SidebarItem onclick={() => {}} icon={ BiLogOut } label='Logout' href='/' />
<SiderbarTweetButton />
</div>
</div>
</div>
);
}

export default Sidebar
More...

Built Twitter Like App - 2

Add basic layout

Add file components/Layout.tsx:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import Sidebar from "./layout/Siderbar";

interface LayoutProps{
children: React.ReactNode;
}

const Layout:React.FC<LayoutProps> = ({ children }) => {
return (
<div className="h-screen bg-black">
<div className="container h-full mx-auto xl:px-30 max-w-6xl">
<div className="grid grid-cols-4 h-full">
<Sidebar />
<div className="
col-span-3
lg:col-span-2
border-x-[1px]
border-neutral-800
">
{ children }
</div>
</div>
</div>
</div>
);
}

export default Layout;

Add file conmponent/layout/Sidebar.tsx:

1
2
3
4
5
6
7
8
9
const Sidebar = () => {
return(
<div>

</div>
);
}

export default Sidebar
More...

Built Twitter Like App - 1

Install Next.Js

1
npx create-next-app@13.0.0 --typescript

Install tailwindcss

1
2
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

Initial page

modify pages/index.js

1
2
3
4
5
6
7
export default function Home() {
return (
<div className="text-3xl text-sky-500">
Hello World!
</div>
)
}
More...

请我喝杯咖啡吧~

支付宝
微信