Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions app/notebook/NotebookClientLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { ReactNode, useEffect, useState } from 'react';
import { ReactNode, useState } from 'react';
import './globals.css';
import 'cal-sans/index.css';
import 'katex/dist/katex.min.css';
Expand All @@ -16,11 +16,8 @@ import '@fontsource/inter/700.css';
import { PageLayout } from '@/app/layouts/PageLayout';
import { NotebookProvider } from '@/contexts/NotebookContext';
import { NoteEditorLayout } from '@/components/Notebook/NoteEditorLayout';
import { clearPendingGrant } from '@/components/Editor/lib/utils/publishingFormStorage';

function NotebookContent({ children }: Readonly<{ children: ReactNode }>) {
useEffect(() => () => clearPendingGrant(), []);

// The docked assistant already reserves its own gutter inside the page
// container, so keeping the container capped would centre the document in
// what's left and leave a wide dead band on either side. Release the cap for
Expand Down
10 changes: 7 additions & 3 deletions app/notebook/[orgSlug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
getTemplatePlainText,
} from '@/components/Editor/lib/utils/documentTitle';
import { useCreateNote, useNoteContent } from '@/hooks/useNote';
import { NoteService } from '@/services/note.service';
import { NoteCreationPopover } from '@/components/Notebook/NoteCreationPopover';
import { useUser } from '@/contexts/UserContext';
import { getPendingGrant } from '@/components/Editor/lib/utils/publishingFormStorage';
import type { ID } from '@/types/root';

// An empty document for the "Start blank" funding-opportunity path. The
Expand Down Expand Up @@ -42,6 +42,7 @@ export default function OrganizationPage() {
const isNewGrant = searchParams.get('newGrant') === 'true';
const grantSource = searchParams.get('grantSource');
const proposalSource = searchParams.get('proposalSource');
const selectedGrantId = searchParams.get('selectedGrantId') ?? undefined;

const createNoteWithContent = async (
orgSlug: string,
Expand All @@ -66,10 +67,13 @@ export default function OrganizationPage() {
title,
grouping: 'WORKSPACE',
documentType,
selectedGrantId,
});

if (newNote) {
if (selectedGrantId) {
await NoteService.updateNote({ noteId: newNote.id, selectedGrantId });
}

await updateNoteContent({
note: newNote.id,
fullJson: JSON.stringify(template),
Expand Down Expand Up @@ -103,7 +107,6 @@ export default function OrganizationPage() {
} else if (isNewFunding) {
// "Upload a document" is handled inline in OpenProposalModal; here we
// only create from template/blank.
const selectedGrantId = getPendingGrant()?.id;
if (proposalSource === 'blank') {
createNoteWithContent(selectedOrg.slug, {
template: BLANK_DOCUMENT,
Expand Down Expand Up @@ -132,6 +135,7 @@ export default function OrganizationPage() {
isNewGrant,
grantSource,
proposalSource,
selectedGrantId,
]); // eslint-disable-line react-hooks/exhaustive-deps

const handleStartFromTemplate = async (selectedGrantId?: Exclude<ID, null | undefined>) => {
Expand Down
128 changes: 0 additions & 128 deletions components/Editor/lib/utils/publishingFormStorage.ts

This file was deleted.

1 change: 0 additions & 1 deletion components/Funding/DocumentUploadStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export const DocumentUploadStep = ({
title: result.title,
grouping: 'WORKSPACE',
documentType,
selectedGrantId: undefined,
});
await updateNoteContent({
note: newNote.id,
Expand Down
2 changes: 2 additions & 0 deletions components/Notebook/NoteEditorLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function NoteEditorLayout({ onAgentChatDockedChange }: NoteEditorLayoutPr
noteError,
setEditor,
updateNoteTitle,
saveDetailsSoon,
activeNoteId,
editor,
} = useNotebookContext();
Expand Down Expand Up @@ -212,6 +213,7 @@ export function NoteEditorLayout({ onAgentChatDockedChange }: NoteEditorLayoutPr
}, [note, noteError, isLoadingNote]);

const [, updateNote, saveNoteNow] = useUpdateNote(note?.id, {
saveTitle: (title) => saveDetailsSoon({ title }),
onTitleUpdate: updateNoteTitle,
registeredReportProposalId: note?.proposalId,
// While an assistant review is open the editor holds a merged document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import { NonprofitSearchSection } from '@/components/Nonprofit';
import { useNonprofitByFundraiseId } from '@/hooks/useNonprofitByFundraiseId';
import { useNonprofitSearch } from '@/hooks/useNonprofitSearch';
import { SelectFundingOpportunityModal } from '@/components/modals/SelectFundingOpportunityModal';
import type { SelectedGrantData } from '@/components/Editor/lib/utils/publishingFormStorage';
import { formatCompactAmount } from '@/utils/currency';
import { GRANT_IMAGE_FALLBACK_GRADIENT } from '@/types/grant';
import { GRANT_IMAGE_FALLBACK_GRADIENT, type SelectedGrantDetails } from '@/types/grant';
import { NoteService } from '@/services/note.service';

interface FundingSectionProps {
Expand All @@ -25,12 +24,12 @@ const FEATURE_FLAG_NFT_REWARDS = false;

function FundingOpportunitySection({ note }: Readonly<FundingSectionProps>) {
const { watch, setValue } = useFormContext();
const selectedGrant: SelectedGrantData | null = watch('selectedGrant');
const selectedGrant: SelectedGrantDetails | null = watch('selectedGrant');
const workId = watch('workId');
const [isModalOpen, setIsModalOpen] = useState(false);
const [isSavingGrant, setIsSavingGrant] = useState(false);

const saveSelectedGrant = async (grant: SelectedGrantData | null) => {
const saveSelectedGrant = async (grant: SelectedGrantDetails | null) => {
setIsSavingGrant(true);
try {
await NoteService.updateNote({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { useEffect, useRef, useState } from 'react';
import { useFormContext, Controller } from 'react-hook-form';
import { toast } from 'react-hot-toast';
import { Image as ImageIcon, Plus, X } from 'lucide-react';
import { SectionHeader } from './SectionHeader';
import { PublishingFormData } from '../schema';
import { useAssetUpload } from '@/hooks/useAssetUpload';

const ACCEPT = ['image/jpeg', 'image/png'];
const MAX_SIZE_MB = 10;
Expand All @@ -13,10 +15,12 @@ const isValidFile = (file: unknown): file is File =>
export function WorkImageSection() {
const {
control,
getValues,
formState: { errors },
} = useFormContext<PublishingFormData>();

const [error, setError] = useState<string | null>(null);
const [, uploadAsset] = useAssetUpload();

return (
<div className="py-3 px-6">
Expand All @@ -33,9 +37,26 @@ export function WorkImageSection() {
file={file}
existingUrl={existingUrl}
error={error || (errors.coverImage?.message as string) || null}
onSelect={(selected) => {
onSelect={async (selected) => {
setError(null);
field.onChange({ file: selected, url: null });
const previousCover = field.value ?? null;
// Show the pick right away, then swap in what the server stored.
field.onChange({ file: selected, key: null, url: null });

const uploaded = await uploadAsset(selected, 'post').catch((uploadError) => {
console.error('Error uploading cover image:', uploadError);
return null;
});

// Ignore this upload if its selection was removed or replaced while it ran.
if (getValues('coverImage')?.file !== selected) return;
Comment thread
michaelcanova marked this conversation as resolved.

if (!uploaded) {
field.onChange(previousCover);
toast.error('Failed to upload image. Please try again.');
return;
}
field.onChange({ file: null, key: uploaded.objectKey, url: uploaded.absoluteUrl });
}}
onRemove={() => {
setError(null);
Expand Down
Loading
Loading