fix up colocation

This commit is contained in:
Max Leiter 2022-11-12 01:28:06 -08:00
parent 96da95818f
commit 86b9172527
38 changed files with 72 additions and 67 deletions

View file

@ -71,7 +71,12 @@ const Auth = ({
auto auto
width="100%" width="100%"
icon={<GithubIcon />} icon={<GithubIcon />}
onClick={() => signIn("github").catch((err) => setErrorMsg(err.message))} onClick={(e) => {
e.preventDefault()
signIn("github", {
callbackUrl: "/",
})
}}
> >
Sign in with GitHub Sign in with GitHub
</Button> </Button>

View file

@ -1,4 +1,4 @@
import PageSeo from "app/components/page-seo" import PageSeo from "@components/page-seo"
export default function AuthHead() { export default function AuthHead() {
return <PageSeo title="Sign In" /> return <PageSeo title="Sign In" />

View file

@ -1,5 +1,5 @@
import Auth from "../components" import Auth from "../components"
import Header from "app/components/header" import Header from "@components/header"
export default function SignInPage() { export default function SignInPage() {
return ( return (

View file

@ -1,4 +1,4 @@
import PageSeo from "app/components/page-seo" import PageSeo from "@components/page-seo"
export default function AuthHead() { export default function AuthHead() {
return <PageSeo title="Sign Up" /> return <PageSeo title="Sign Up" />

View file

@ -1,5 +1,5 @@
import Auth from "../components" import Auth from "../components"
import Header from "app/components/header" import Header from "@components/header"
import { getRequiresPasscode } from "pages/api/auth/requires-passcode" import { getRequiresPasscode } from "pages/api/auth/requires-passcode"
const getPasscode = async () => { const getPasscode = async () => {

View file

@ -1,10 +1,10 @@
import ShiftBy from "app/components/shift-by" import ShiftBy from "@components/shift-by"
import { Button, Popover } from "@geist-ui/core/dist" import { Button, Popover } from "@geist-ui/core/dist"
import ChevronDown from "@geist-ui/icons/chevronDown" import ChevronDown from "@geist-ui/icons/chevronDown"
import CodeIcon from "@geist-ui/icons/fileFunction" import CodeIcon from "@geist-ui/icons/fileFunction"
import FileIcon from "@geist-ui/icons/fileText" import FileIcon from "@geist-ui/icons/fileText"
import { codeFileExtensions } from "@lib/constants" import { codeFileExtensions } from "@lib/constants"
import type { File } from "@lib/types" import type { File } from "lib/server/prisma"
import { useCallback, useEffect, useState } from "react" import { useCallback, useEffect, useState } from "react"
import styles from "./dropdown.module.css" import styles from "./dropdown.module.css"

View file

@ -2,10 +2,10 @@ import { File } from "@lib/types"
import FileIcon from "@geist-ui/icons/fileText" import FileIcon from "@geist-ui/icons/fileText"
import CodeIcon from "@geist-ui/icons/fileLambda" import CodeIcon from "@geist-ui/icons/fileLambda"
import styles from "./file-tree.module.css" import styles from "./file-tree.module.css"
import ShiftBy from "app/components/shift-by" import ShiftBy from "@components/shift-by"
import { useEffect, useState } from "react" import { useEffect, useState } from "react"
import { codeFileExtensions } from "@lib/constants" import { codeFileExtensions } from "@lib/constants"
import Link from "app/components/link" import Link from "@components/link"
type Item = File & { type Item = File & {
icon: JSX.Element icon: JSX.Element

View file

@ -114,4 +114,4 @@ function FileDropzone({ setDocs }: { setDocs: (docs: Document[]) => void }) {
) )
} }
export default memo(FileDropzone) export default FileDropzone

View file

@ -12,9 +12,9 @@ import DatePicker from "react-datepicker"
import getTitleForPostCopy from "@lib/get-title-for-post-copy" import getTitleForPostCopy from "@lib/get-title-for-post-copy"
import Description from "./description" import Description from "./description"
import { PostWithFiles } from "@lib/server/prisma" import { PostWithFiles } from "@lib/server/prisma"
import PasswordModal from "./password-modal" import PasswordModal from "../../../components/password-modal"
import Title from "./title" import Title from "./title"
import FileDropzone from "./drag-and-drop"
const emptyDoc = { const emptyDoc = {
title: "", title: "",
content: "", content: "",

View file

@ -1,7 +1,7 @@
import { ChangeEvent, memo, useEffect, useState } from "react" import { ChangeEvent, memo, useEffect, useState } from "react"
import { Text } from "@geist-ui/core/dist" import { Text } from "@geist-ui/core/dist"
import ShiftBy from "app/components/shift-by" import ShiftBy from "@components/shift-by"
import styles from "../post.module.css" import styles from "../post.module.css"
import { Input } from "@geist-ui/core/dist" import { Input } from "@geist-ui/core/dist"

View file

@ -1,7 +1,7 @@
import NewPost from "app/(posts)/new/components/new" import NewPost from "../../components/new"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { getPostWithFiles } from "@lib/server/prisma" import Header from "@components/header"
import Header from "app/components/header" import { getPostById } from "@lib/server/prisma"
const NewFromExisting = async ({ const NewFromExisting = async ({
params params
@ -18,7 +18,7 @@ const NewFromExisting = async ({
return; return;
} }
const post = await getPostWithFiles(id) const post = await getPostById(id, true)
return ( return (
<> <>

View file

@ -1,4 +1,4 @@
import PageSeo from "app/components/page-seo" import PageSeo from "@components/page-seo"
export default function NewPostHead() { export default function NewPostHead() {
return <PageSeo title="Create a new Drift" /> return <PageSeo title="Create a new Drift" />

View file

@ -1,4 +1,4 @@
import Header from "app/components/header" import Header from "@components/header"
import NewPost from "app/(posts)/new/components/new" import NewPost from "app/(posts)/new/components/new"
import "@styles/react-datepicker.css" import "@styles/react-datepicker.css"

View file

@ -1,24 +1,22 @@
"use client" "use client"
import VisibilityBadge from "app/components/badges/visibility-badge" import VisibilityBadge from "@components/badges/visibility-badge"
import DocumentComponent from "./view-document" import DocumentComponent from "./view-document"
import styles from "./post-page.module.css" import styles from "./post-page.module.css"
import type { PostVisibility } from "@lib/types"
import { Button, Text, ButtonGroup, useMediaQuery } from "@geist-ui/core/dist" import { Button, Text, ButtonGroup, useMediaQuery } from "@geist-ui/core/dist"
import { useEffect, useState } from "react" import { useEffect, useState } from "react"
import Archive from "@geist-ui/icons/archive" import Archive from "@geist-ui/icons/archive"
import Edit from "@geist-ui/icons/edit" import Edit from "@geist-ui/icons/edit"
import Parent from "@geist-ui/icons/arrowUpCircle" import Parent from "@geist-ui/icons/arrowUpCircle"
import FileDropdown from "app/(posts)/components/file-dropdown" import FileDropdown from "app/(posts)/components/file-dropdown"
import ScrollToTop from "app/components/scroll-to-top" import ScrollToTop from "@components/scroll-to-top"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import ExpirationBadge from "app/components/badges/expiration-badge" import ExpirationBadge from "@components/badges/expiration-badge"
import CreatedAgoBadge from "app/components/badges/created-ago-badge" import CreatedAgoBadge from "@components/badges/created-ago-badge"
import PasswordModalPage from "./password-modal-wrapper" import PasswordModalPage from "./password-modal-wrapper"
import VisibilityControl from "app/components/badges/visibility-control" import VisibilityControl from "@components/badges/visibility-control"
import { File, PostWithFiles } from "@lib/server/prisma" import { File, PostWithFiles } from "@lib/server/prisma"
import Header from "app/components/header"
type Props = { type Props = {
post: PostWithFiles post: PostWithFiles
@ -95,7 +93,7 @@ const PostPage = ({ post: initialPost, isProtected, isAuthor }: Props) => {
return ( return (
<> <>
{!isAvailable && <PasswordModalPage setPost={setPost} />} {!isAvailable && <PasswordModalPage setPost={setPost} postId={post.id} />}
<div className={styles.header}> <div className={styles.header}>
<span className={styles.buttons}> <span className={styles.buttons}>
<ButtonGroup <ButtonGroup
@ -113,7 +111,7 @@ const PostPage = ({ post: initialPost, isProtected, isAuthor }: Props) => {
> >
Edit a Copy Edit a Copy
</Button> </Button>
{post.parent && ( {post.parentId && (
<Button auto icon={<Parent />} onClick={viewParentClick}> <Button auto icon={<Parent />} onClick={viewParentClick}>
View Parent View Parent
</Button> </Button>

View file

@ -1,12 +1,12 @@
import PasswordModal from "@components/new-post/password-modal"
import { useToasts } from "@geist-ui/core/dist" import { useToasts } from "@geist-ui/core/dist"
import { Post } from "@lib/server/prisma" import { PostWithFiles } from "@lib/server/prisma"
import PasswordModal from "@components/password-modal"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { useState } from "react" import { useState } from "react"
type Props = { type Props = {
setPost: (post: Post) => void setPost: (post: PostWithFiles) => void
postId: Post["id"] postId: PostWithFiles["id"]
} }
const PasswordModalPage = ({ setPost, postId }: Props) => { const PasswordModalPage = ({ setPost, postId }: Props) => {

View file

@ -15,7 +15,7 @@ import {
Tag Tag
} from "@geist-ui/core/dist" } from "@geist-ui/core/dist"
import HtmlPreview from "app/(posts)/new/components/edit-document-list/edit-document/preview" import HtmlPreview from "app/(posts)/new/components/edit-document-list/edit-document/preview"
import FadeIn from "app/components/fade-in" import FadeIn from "@components/fade-in"
// import Link from "next/link" // import Link from "next/link"
type Props = { type Props = {

View file

@ -1,4 +1,4 @@
import PageSeo from "app/components/page-seo" import PageSeo from "@components/page-seo"
import { getPostById } from "@lib/server/prisma" import { getPostById } from "@lib/server/prisma"
export default async function Head({ export default async function Head({

View file

@ -6,7 +6,7 @@ import { USER_COOKIE_NAME } from "@lib/constants"
import { notFound } from "next/navigation" import { notFound } from "next/navigation"
import { getPostById } from "@lib/server/prisma" import { getPostById } from "@lib/server/prisma"
import { getCurrentUser, getSession } from "@lib/server/session" import { getCurrentUser, getSession } from "@lib/server/session"
import Header from "app/components/header" import Header from "@components/header"
export type PostProps = { export type PostProps = {
post: Post post: Post
@ -17,6 +17,7 @@ const getPost = async (id: string) => {
const post = await getPostById(id, true) const post = await getPostById(id, true)
const user = await getCurrentUser() const user = await getCurrentUser()
console.log("my post", post)
if (!post) { if (!post) {
return notFound() return notFound()
} }
@ -39,7 +40,9 @@ const getPost = async (id: string) => {
return notFound() return notFound()
} }
console.log("HERE", post.visibility, isAuthor)
if (post.visibility === "protected" && !isAuthor) { if (post.visibility === "protected" && !isAuthor) {
console.log("HERE2")
return { return {
post, post,
isProtected: true, isProtected: true,
@ -55,14 +58,13 @@ const PostView = async ({
params params
}: { }: {
params: { params: {
id: string, id: string
signedIn?: boolean
} }
}) => { }) => {
const { post, isProtected, isAuthor } = await getPost(params.id) const { post, isProtected, isAuthor, signedIn } = await getPost(params.id)
return ( return (
<> <>
<Header signedIn /> <Header signedIn={signedIn} />
<PostPage isAuthor={isAuthor} isProtected={isProtected} post={post} /> <PostPage isAuthor={isAuthor} isProtected={isProtected} post={post} />
</> </>
) )

View file

@ -1,7 +1,5 @@
"use client" "use client"
import { TOKEN_COOKIE_NAME } from "@lib/constants"
import { getCookie } from "cookies-next"
import styles from "./admin.module.css" import styles from "./admin.module.css"
import PostTable from "./post-table" import PostTable from "./post-table"
import UserTable from "./user-table" import UserTable from "./user-table"
@ -13,11 +11,10 @@ export const adminFetcher = async (
body?: any body?: any
} }
) => ) =>
fetch("/server-api/admin" + url, { fetch("/api/admin" + url, {
method: options?.method || "GET", method: options?.method || "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${getCookie(TOKEN_COOKIE_NAME)}`
}, },
body: options?.body && JSON.stringify(options.body) body: options?.body && JSON.stringify(options.body)
}) })

View file

@ -3,8 +3,8 @@ import { User } from "@lib/types"
import { useEffect, useMemo, useState } from "react" import { useEffect, useMemo, useState } from "react"
import { adminFetcher } from "./admin" import { adminFetcher } from "./admin"
import Table from "rc-table" import Table from "rc-table"
import SettingsGroup from "@components/settings-group"
import ActionDropdown from "./action-dropdown" import ActionDropdown from "./action-dropdown"
import SettingsGroup from "@components/settings-group"
const UserTable = () => { const UserTable = () => {
const [users, setUsers] = useState<User[]>() const [users, setUsers] = useState<User[]>()

View file

@ -1,10 +1,11 @@
import Admin from "./components/admin" import { isUserAdmin } from "@lib/server/prisma"
import { getCurrentUser } from "@lib/server/session" import { getCurrentUser } from "@lib/server/session"
import Admin from "./components/admin"
import { cookies } from "next/headers"
import { notFound } from "next/navigation" import { notFound } from "next/navigation"
const AdminPage = async () => { const AdminPage = async () => {
const user = await getCurrentUser() const user = await getCurrentUser();
if (!user) { if (!user) {
return notFound() return notFound()
} }

View file

@ -1,8 +1,10 @@
import { Badge } from "@geist-ui/core/dist" import { Badge } from "@geist-ui/core/dist"
import type { PostVisibility } from "@lib/types" import type { PostVisibility } from "@lib/types"
type CastPostVisibility = PostVisibility | string
type Props = { type Props = {
visibility: PostVisibility visibility: CastPostVisibility
} }
const VisibilityBadge = ({ visibility }: Props) => { const VisibilityBadge = ({ visibility }: Props) => {

View file

@ -1,7 +1,7 @@
import PasswordModal from "@components/new-post/password-modal"
import { Button, ButtonGroup, Loading, useToasts } from "@geist-ui/core/dist" import { Button, ButtonGroup, Loading, useToasts } from "@geist-ui/core/dist"
import { TOKEN_COOKIE_NAME } from "@lib/constants" import { TOKEN_COOKIE_NAME } from "@lib/constants"
import type { PostVisibility } from "@lib/types" import type { PostVisibility } from "@lib/types"
import PasswordModal from "@components/password-modal"
import { getCookie } from "cookies-next" import { getCookie } from "cookies-next"
import { useCallback, useState } from "react" import { useCallback, useState } from "react"

View file

@ -1,9 +1,10 @@
"use client" "use client"
import ShiftBy from "app/components/shift-by" import ShiftBy from "@components/shift-by"
import { Spacer, Tabs, Card, Textarea, Text } from "@geist-ui/core/dist" import { Spacer, Tabs, Card, Textarea, Text } from "@geist-ui/core/dist"
import Image from "next/image" import Image from "next/image"
import styles from "./home.module.css" import styles from "./home.module.css"
import markdownStyles from "@components/preview/preview.module.css" // TODO:components/new-post/ move these styles
import markdownStyles from "app/(posts)/new/components/edit-document-list/edit-document/preview/preview.module.css";
const Home = ({ const Home = ({
introTitle, introTitle,
introContent, introContent,

View file

@ -7,7 +7,7 @@ import ListItemSkeleton from "./list-item-skeleton"
import ListItem from "./list-item" import ListItem from "./list-item"
import { ChangeEvent, useCallback, useEffect, useState } from "react" import { ChangeEvent, useCallback, useEffect, useState } from "react"
import useDebounce from "@lib/hooks/use-debounce" import useDebounce from "@lib/hooks/use-debounce"
import Link from "app/components/link" import Link from "@components/link"
import { TOKEN_COOKIE_NAME } from "@lib/constants" import { TOKEN_COOKIE_NAME } from "@lib/constants"
import { getCookie } from "cookies-next" import { getCookie } from "cookies-next"
import type { PostWithFiles } from "@lib/server/prisma" import type { PostWithFiles } from "@lib/server/prisma"

View file

@ -7,15 +7,15 @@ import {
Badge, Badge,
Button Button
} from "@geist-ui/core/dist" } from "@geist-ui/core/dist"
import FadeIn from "app/components/fade-in" import FadeIn from "@components/fade-in"
import Trash from "@geist-ui/icons/trash" import Trash from "@geist-ui/icons/trash"
import ExpirationBadge from "app/components/badges/expiration-badge" import ExpirationBadge from "@components/badges/expiration-badge"
import CreatedAgoBadge from "app/components/badges/created-ago-badge" import CreatedAgoBadge from "@components/badges/created-ago-badge"
import Edit from "@geist-ui/icons/edit" import Edit from "@geist-ui/icons/edit"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import Parent from "@geist-ui/icons/arrowUpCircle" import Parent from "@geist-ui/icons/arrowUpCircle"
import styles from "./list-item.module.css" import styles from "./list-item.module.css"
import Link from "app/components/link" import Link from "@components/link"
import type { PostWithFiles } from "@lib/server/prisma" import type { PostWithFiles } from "@lib/server/prisma"
import type { PostVisibility } from "@lib/types" import type { PostVisibility } from "@lib/types"
import type { File } from "@lib/server/prisma" import type { File } from "@lib/server/prisma"

View file

@ -1,4 +1,4 @@
import PageSeo from "app/components/page-seo" import PageSeo from "@components/page-seo"
export default function Head() { export default function Head() {
return <PageSeo title="Drift - Your profile" isPrivate /> return <PageSeo title="Drift - Your profile" isPrivate />

View file

@ -1,8 +1,8 @@
import { redirect } from "next/navigation" import { redirect } from "next/navigation"
import { getPostsByUser } from "@lib/server/prisma" import { getPostsByUser } from "@lib/server/prisma"
import PostList from "app/components/post-list" import PostList from "@components/post-list"
import { getCurrentUser } from "@lib/server/session" import { getCurrentUser } from "@lib/server/session"
import Header from "app/components/header" import Header from "@components/header"
import { authOptions } from "@lib/server/auth" import { authOptions } from "@lib/server/auth"
export default async function Mine() { export default async function Mine() {

View file

@ -1,4 +1,4 @@
import Header from "app/components/header" import Header from "@components/header"
import { getCurrentUser } from "@lib/server/session" import { getCurrentUser } from "@lib/server/session"
import { getWelcomeContent } from "pages/api/welcome" import { getWelcomeContent } from "pages/api/welcome"
import Home from "./components/home" import Home from "./components/home"

View file

@ -4,7 +4,7 @@ import { Note, Input, Textarea, Button, useToasts } from "@geist-ui/core/dist"
import { TOKEN_COOKIE_NAME } from "@lib/constants" import { TOKEN_COOKIE_NAME } from "@lib/constants"
import { getCookie } from "cookies-next" import { getCookie } from "cookies-next"
import { User } from "next-auth" import { User } from "next-auth"
import { useEffect, useState } from "react" import { useState } from "react"
const Profile = ({ user }: { user: User }) => { const Profile = ({ user }: { user: User }) => {
const [name, setName] = useState<string>(user.name || "") const [name, setName] = useState<string>(user.name || "")

View file

@ -1,4 +1,4 @@
import PageSeo from "app/components/page-seo" import PageSeo from "@components/page-seo"
export default function Head() { export default function Head() {
return <PageSeo title="Drift - Settings" isPrivate /> return <PageSeo title="Drift - Settings" isPrivate />

View file

@ -1,5 +1,5 @@
import Header from "app/components/header" import Header from "@components/header"
import SettingsGroup from "./components/settings-group" import SettingsGroup from "../components/settings-group"
import Password from "app/settings/components/sections/password" import Password from "app/settings/components/sections/password"
import Profile from "app/settings/components/sections/profile" import Profile from "app/settings/components/sections/profile"
import { authOptions } from "@lib/server/auth" import { authOptions } from "@lib/server/auth"

View file

@ -54,7 +54,7 @@ export const authOptions: NextAuthOptions = {
name: dbUser.username, name: dbUser.username,
email: dbUser.email, email: dbUser.email,
picture: dbUser.image, picture: dbUser.image,
role: dbUser.role role: dbUser.role || "user",
} }
} }
} }

View file

@ -160,5 +160,5 @@ export const getPostById = async (postId: Post["id"], withFiles = false) => {
} }
}) })
return post return post as PostWithFiles
} }

View file

@ -41,6 +41,5 @@ export const config = {
"/signin", "/signin",
"/signup", "/signup",
"/new", "/new",
"/private/:path*"
] ]
} }