forked from bluedotimpact/bluedot
-
Notifications
You must be signed in to change notification settings - Fork 0
[to test AI review bots] Add editor app for editing blogs and job posts (#880) #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
brendanator
wants to merge
1
commit into
base-sha/15b5a8b86277dc9a917eaa6e3728dd79130e956b
Choose a base branch
from
head-sha/f7c59e67c9a589a39c480bf5eb2fab4d6e793245/2025-05-11T17-02-28/3c0fd2
base: base-sha/15b5a8b86277dc9a917eaa6e3728dd79130e956b
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,14 @@ | ||
APP_NAME=app-template | ||
|
||
# Airtable: https://support.airtable.com/docs/creating-and-using-api-keys-and-access-tokens | ||
AIRTABLE_PERSONAL_ACCESS_TOKEN= | ||
|
||
# BlueDot Impact Slack, #tech-dev-alerts | ||
ALERTS_SLACK_CHANNEL_ID=C04SFUECECU | ||
# For (local) BlueBot see https://airtable.com/appnNmNoNMB6crg6I/tbllthJ2YSPDsKWCt/viwfjWLvplq6Xw93D/recqurdJTPWzm5y4W | ||
# For (prod) BlueBot see https://api.slack.com/apps/A04PV2GAQRY/install-on-team | ||
# Starts 'xoxb-' | ||
ALERTS_SLACK_BOT_TOKEN=IGNORE_SLACK_ALERTS | ||
|
||
WEBSITE_ASSETS_BUCKET_ACCESS_KEY_ID= | ||
WEBSITE_ASSETS_BUCKET_SECRET_ACCESS_KEY= |
This file contains hidden or 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,11 @@ | ||
APP_NAME=app-template | ||
|
||
# Airtable | ||
AIRTABLE_PERSONAL_ACCESS_TOKEN=FAKE_TOKEN | ||
|
||
# Slack | ||
ALERTS_SLACK_CHANNEL_ID=C04SFUECECU | ||
ALERTS_SLACK_BOT_TOKEN=FAKE_TOKEN | ||
|
||
WEBSITE_ASSETS_BUCKET_ACCESS_KEY_ID=FAKE | ||
WEBSITE_ASSETS_BUCKET_SECRET_ACCESS_KEY=FAKE |
This file contains hidden or 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,31 @@ | ||
# You usually shouldn't need to edit this file. | ||
# If you came here to change environment variables: | ||
# - Add server-side env vars to infra's serviceDefinitions.ts | ||
# - Add client-side env vars to .env.production (you might need to create this) | ||
# If you came here to change the build process, edit the `npm run build` script in package.json instead | ||
|
||
FROM node:20-alpine@sha256:7a91aa397f2e2dfbfcdad2e2d72599f374e0b0172be1d86eeb73f1d33f36a4b2 AS base | ||
|
||
RUN apk update && apk add --no-cache dumb-init | ||
|
||
WORKDIR /app | ||
|
||
ENV NODE_ENV production | ||
ENV NEXT_TELEMETRY_DISABLED 1 | ||
|
||
# Set the correct permission for prerender cache | ||
RUN mkdir dist | ||
RUN chown node:node dist | ||
|
||
ARG APP_NAME | ||
ENV APP_NAME=${APP_NAME} | ||
|
||
COPY --chown=node:node dist/standalone ./ | ||
COPY --chown=node:node public ./apps/${APP_NAME}/public | ||
COPY --chown=node:node dist/static ./apps/${APP_NAME}/dist/static | ||
|
||
USER node | ||
|
||
EXPOSE 8080 | ||
|
||
CMD HOSTNAME="0.0.0.0" PORT="8080" dumb-init node ./apps/${APP_NAME}/server.js |
This file contains hidden or 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,13 @@ | ||
# editor | ||
|
||
An app for BlueDot staff to edit content: blogs and job postings. | ||
|
||
## Developer setup | ||
|
||
No special actions needed, just follow [the general developer setup instructions](../../README.md#developer-setup-instructions) | ||
|
||
## Deployment | ||
|
||
This app is deployed onto the K8s cluster as a standard Next.js app in docker. | ||
|
||
To deploy a new version, simply commit to the master branch. GitHub Actions automatically handles CD. |
This file contains hidden or 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,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information. |
This file contains hidden or 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,3 @@ | ||
const { withDefaultBlueDotNextConfig } = require('@bluedot/ui/src/default-config/next'); | ||
|
||
module.exports = withDefaultBlueDotNextConfig(); |
This file contains hidden or 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,57 @@ | ||
{ | ||
"name": "@bluedot/editor", | ||
"version": "1.0.0", | ||
"private": true, | ||
"scripts": { | ||
"postinstall": "shx cp -n .env.local.template .env.local", | ||
"start": "next dev -p 8000", | ||
"start:docker": "docker-scripts start", | ||
"build": "next build", | ||
"lint": "eslint . --report-unused-disable-directives --max-warnings=0", | ||
"lint:fix": "npm run lint -- --fix", | ||
"test": "vitest --run", | ||
"test:watch": "vitest", | ||
"deploy:cd": "docker-scripts deploy" | ||
}, | ||
"dependencies": { | ||
"@aws-sdk/client-s3": "^3.803.0", | ||
"@aws-sdk/s3-presigned-post": "^3.803.0", | ||
"@bluedot/ui": "*", | ||
"@mdx-js/mdx": "^3.1.0", | ||
"@syfxlin/tiptap-starter-kit": "^1.1.2", | ||
"@tailwindcss/typography": "^0.5.16", | ||
"@tiptap/pm": "^2.12.0", | ||
"@tiptap/react": "^2.12.0", | ||
"airtable-ts": "^1.5.0", | ||
"airtable-ts-formula": "^1.0.0", | ||
"axios": "^1.9.0", | ||
"axios-hooks": "^5.0.2", | ||
"http-errors": "^2.0.0", | ||
"next": "^15.3.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-icons": "^5.5.0", | ||
"tiptap-markdown": "^0.8.10", | ||
"zod": "^3.24.2" | ||
}, | ||
"devDependencies": { | ||
"@bluedot/docker-scripts": "*", | ||
"@bluedot/eslint-config": "*", | ||
"@bluedot/typescript-config": "*", | ||
"@tailwindcss/postcss": "^4.0.6", | ||
"@testing-library/react": "^15.0.2", | ||
"@types/node": "^22.13.2", | ||
"@types/react": "^18.0.22", | ||
"@types/react-dom": "^18.0.7", | ||
"@vitejs/plugin-react": "^4.2.1", | ||
"dotenv": "^16.4.5", | ||
"eslint": "^8.57.0", | ||
"happy-dom": "^14.7.1", | ||
"node-mocks-http": "^1.14.1", | ||
"postcss": "^8.4.38", | ||
"shx": "^0.4.0", | ||
"tailwindcss": "^4.0.6", | ||
"typescript": "^5.8.3", | ||
"vitest": "^1.5.0" | ||
} | ||
} |
This file contains hidden or 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,5 @@ | ||
module.exports = { | ||
plugins: { | ||
'@tailwindcss/postcss': {}, | ||
}, | ||
}; |
Empty file.
This file contains hidden or 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,21 @@ | ||
import { CTALinkOrButton, NewText } from '@bluedot/ui'; | ||
import { useRouter } from 'next/router'; | ||
|
||
export type BaseLayoutProps = { | ||
children?: React.ReactNode; | ||
}; | ||
|
||
export const BaseLayout: React.FC<BaseLayoutProps> = ({ children }) => { | ||
const router = useRouter(); | ||
|
||
return ( | ||
<div className="section-body gap-4 mt-6"> | ||
<NewText.H1>BlueDot Editor</NewText.H1> | ||
<nav className="flex gap-2 mb-4"> | ||
<CTALinkOrButton variant={router.pathname.startsWith('/blogs') ? 'primary' : 'secondary'} url="/blogs">Blogs</CTALinkOrButton> | ||
<CTALinkOrButton variant={router.pathname.startsWith('/jobs') ? 'primary' : 'secondary'} url="/jobs">Job postings</CTALinkOrButton> | ||
</nav> | ||
{children} | ||
</div> | ||
); | ||
}; |
This file contains hidden or 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,105 @@ | ||
import { | ||
Auth, CTALinkOrButton, | ||
ProgressDots, | ||
} from '@bluedot/ui'; | ||
import axios from 'axios'; | ||
import dynamic from 'next/dynamic'; | ||
import { useEffect, useState } from 'react'; | ||
import { PresignedPostResponse } from '../pages/api/presigned-upload'; | ||
|
||
const MarkdownEditor = dynamic(() => import('./MarkdownEditor'), { ssr: false, loading: () => <ProgressDots /> }); | ||
|
||
export type BodyEditorProps = { | ||
auth: Auth; | ||
children?: string; | ||
onSave: (body: string) => Promise<void>; | ||
}; | ||
|
||
export const BodyEditor: React.FC<BodyEditorProps> = ({ auth, children, onSave }) => { | ||
const [body, setBody] = useState<null | string>(null); | ||
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false); | ||
|
||
useEffect(() => { | ||
if (body === null && children) { | ||
setBody(children); | ||
} | ||
}, [children]); | ||
|
||
// Add beforeunload event listener to warn about unsaved changes | ||
useEffect(() => { | ||
const handleBeforeUnload = (e: BeforeUnloadEvent) => { | ||
if (hasUnsavedChanges) { | ||
e.preventDefault(); | ||
} | ||
}; | ||
|
||
window.addEventListener('beforeunload', handleBeforeUnload); | ||
|
||
return () => { | ||
window.removeEventListener('beforeunload', handleBeforeUnload); | ||
}; | ||
}, [hasUnsavedChanges]); | ||
|
||
const [isSaving, setIsSaving] = useState(false); | ||
const save = async () => { | ||
setIsSaving(true); | ||
try { | ||
if (body) { | ||
await onSave(body); | ||
setHasUnsavedChanges(false); | ||
} | ||
} finally { | ||
setIsSaving(false); | ||
} | ||
}; | ||
|
||
const uploadFile = async (fileData: ArrayBuffer, fileType: string) => { | ||
const blob = new Blob([fileData], { type: fileType }); | ||
|
||
const presignedResponse = await axios<PresignedPostResponse>({ | ||
method: 'POST', | ||
url: '/api/presigned-upload', | ||
data: { | ||
contentType: fileType, | ||
}, | ||
headers: { | ||
Authorization: `Bearer ${auth.token}`, | ||
}, | ||
}); | ||
|
||
const formData = new FormData(); | ||
Object.entries(presignedResponse.data.fields).forEach(([key, value]) => { | ||
formData.append(key, String(value)); | ||
}); | ||
formData.append('file', blob); | ||
await axios.post(presignedResponse.data.uploadUrl, formData); | ||
|
||
return { url: presignedResponse.data.fileUrl }; | ||
}; | ||
|
||
return ( | ||
<div className="max-w-3xl flex flex-col gap-4"> | ||
<MarkdownEditor | ||
uploadFile={uploadFile} | ||
onChange={(newBody) => { | ||
setHasUnsavedChanges(true); | ||
setBody(newBody); | ||
}} | ||
> | ||
{children} | ||
</MarkdownEditor> | ||
{body && ( | ||
<div className="flex flex-col gap-4"> | ||
{hasUnsavedChanges && ( | ||
<div className="text-amber-600 text-size-sm"> | ||
You have unsaved changes | ||
</div> | ||
)} | ||
<CTALinkOrButton onClick={save}> | ||
{isSaving ? 'Saving...' : 'Save'} | ||
</CTALinkOrButton> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider setting
e.returnValue
explicitly (e.g.,e.returnValue = ''
) in thebeforeunload
handler to ensure browsers display the unsaved changes warning consistently.