generated from clerk/nextjs-auth-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from TereseBo/add_public
Add public draft display
- Loading branch information
Showing
19 changed files
with
192 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.library-content { | ||
margin: 2rem; | ||
|
||
display: flex; | ||
flex-wrap: wrap; | ||
align-items: flex-start; | ||
justify-content: center; | ||
gap: 2rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use client' | ||
import './page.scss' | ||
|
||
import { useEffect, useState } from 'react' | ||
|
||
import { PublicDraftCard } from '@/app/components/library/publicDraftCard' | ||
import { Header } from '@/app/components/zSharedComponents/Header' | ||
|
||
export default function LibraryPage() { | ||
|
||
const [publicDrafts, setPublicDrafts]=useState<PublicDraftList|null>(null) | ||
|
||
//TODO: Add second state and components for filtering/sorting | ||
|
||
useEffect(()=>{ | ||
const getPublicDrafts = async () => { | ||
|
||
try { | ||
let response = await fetch('/api/public/drafts') | ||
|
||
if (response.status == 200) { | ||
|
||
const body = await response.json(); | ||
const { publicDraftList } = body | ||
setPublicDrafts(publicDraftList) | ||
} | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
} | ||
|
||
getPublicDrafts() | ||
|
||
},[]) | ||
|
||
|
||
|
||
return ( | ||
<div id='library-page'> | ||
<Header title="You are in the library" text="Browse awailable drafts to be inspired" /> | ||
|
||
{publicDrafts ? | ||
<div className='library-content'> | ||
{publicDrafts.map((draft, index) => { | ||
if (!draft) return (null) | ||
else { | ||
return (<PublicDraftCard key={index} draft={draft} />) | ||
} | ||
})} | ||
</div> : <div>Loading drafts</div>} | ||
|
||
|
||
{publicDrafts && publicDrafts.length == 0 ? | ||
<div > | ||
No public drafts to show | ||
</div> : null} | ||
|
||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//Route for retrieving public drafts | ||
import { Db } from 'mongodb' | ||
import { NextResponse } from 'next/server' | ||
|
||
import { dbConnection } from '@/app/resources/db/mongodb' | ||
|
||
export async function GET( | ||
req: Request | ||
) { | ||
|
||
try { | ||
const db = await dbConnection() as Db | ||
let dbResponse = await db.collection('drafts').find({ public: true }).toArray() | ||
|
||
let publicDraftList: PublicDraftList = [] | ||
|
||
if (dbResponse.length > 0) { | ||
publicDraftList = dbResponse.map(draftDocument => { | ||
|
||
const draft: PublicDraft = { | ||
|
||
weave:JSON.parse(JSON.stringify(draftDocument.weave)), | ||
} | ||
return draft | ||
}) | ||
} | ||
|
||
return NextResponse.json({ publicDraftList }, { status: 200 }); | ||
|
||
} catch (error) { | ||
console.log('api/drafts/GET', error); | ||
return new NextResponse( | ||
'Ooops, something went very wrong on the server', | ||
{ status: 500 } | ||
); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use client' | ||
|
||
import { useRouter } from 'next/navigation' | ||
|
||
import { DisplayCard } from '@/app/components/(userpages)/DisplayCard' | ||
import { useWeaveContext } from '@/app/resources/contexts/weavecontext' | ||
import { readWeaveObject } from '@/app/resources/functions/weaveObjHandling/readWeaveObj/readWeaveObject' | ||
import { createWeave } from '@/app/resources/functions/weaveObjHandling/readWeaveObj/writeDraftGrid' | ||
|
||
import { PreviewGrid } from '../zSharedComponents/PreviewGrid' | ||
|
||
|
||
export function PublicDraftCard(params: { draft: { weave: WeaveObject } }) { | ||
|
||
const { weave } = params.draft | ||
const gridSet= readWeaveObject(weave) | ||
const weaveGrid=createWeave(gridSet, 50,30) | ||
const { upSetGrids } = useWeaveContext() | ||
|
||
const router = useRouter() | ||
|
||
function useDraft() { | ||
if (weave) { | ||
upSetGrids(weave) | ||
router.push('/weaver/draft') | ||
} else { | ||
alert('Ops, something went wrong, please try another one') | ||
} | ||
} | ||
|
||
return ( | ||
<div id='draft-card-container'> | ||
<DisplayCard > | ||
<div > | ||
<div className='vertical draft-card' > | ||
|
||
<div className='draft-info-container'> | ||
<button type='button' onClick={useDraft}>Use</button> | ||
</div> | ||
<PreviewGrid content={weaveGrid} type='publicDraft' /> | ||
|
||
<div className='draft-info-container'> | ||
<p> Treadles:<span>{weave.treadling?.count || '-'}</span></p> | ||
<p> Shafts:<span>{weave.shafts?.count || '-'}</span></p> | ||
</div> | ||
</div> | ||
</div> | ||
</DisplayCard> | ||
|
||
</div> | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.