Open record modal on create

This commit is contained in:
Hakan Shehu
2024-09-13 18:02:25 +02:00
parent dfa614fdb5
commit bfac9c3930
7 changed files with 21 additions and 9 deletions

View File

@@ -19,8 +19,6 @@ export const BoardView = ({ node }: BoardViewProps) => {
(field) => field.id === node.groupBy,
);
console.log(node.groupBy, database.fields);
if (!groupByField || groupByField.dataType !== 'select') {
return null;
}

View File

@@ -94,7 +94,7 @@ export const TableViewNameCell = ({ record }: TableViewNameCellProps) => {
{hasName ? (
record.name
) : (
<span className="text-muted-foreground">Untitled</span>
<span className="text-muted-foreground">Unnamed</span>
)}
</div>
<button

View File

@@ -2,8 +2,10 @@ import React from 'react';
import { Icon } from '@/components/ui/icon';
import { useDatabase } from '@/contexts/database';
import { useRecordCreateMutation } from '@/mutations/use-record-create-mutation';
import { useWorkspace } from '@/contexts/workspace';
export const TableViewRecordCreateRow = () => {
const workspace = useWorkspace();
const database = useDatabase();
const { mutate, isPending } = useRecordCreateMutation();
@@ -13,9 +15,16 @@ export const TableViewRecordCreateRow = () => {
disabled={isPending}
className="animate-fade-in flex h-8 w-full cursor-pointer flex-row items-center gap-1 border-b pl-2 text-muted-foreground hover:bg-gray-50"
onClick={() => {
mutate({
databaseId: database.id,
});
mutate(
{
databaseId: database.id,
},
{
onSuccess: (recordId) => {
workspace.openModal(recordId);
},
},
);
}}
>
<Icon name="add-line" />

View File

@@ -33,6 +33,7 @@ export const RecordName = ({ record }: RecordNameProps) => {
});
}}
className="font-heading border-b border-none pl-1 text-4xl font-bold shadow-none focus-visible:ring-0"
placeholder="Unnamed"
/>
);
};

View File

@@ -7,10 +7,11 @@ interface SmartTextInputProps {
onChange: (newValue: string) => void;
className?: string;
readOnly?: boolean;
placeholder?: string;
}
const SmartTextInput = React.forwardRef<HTMLInputElement, SmartTextInputProps>(
({ value, onChange, className, readOnly, ...props }, ref) => {
({ value, onChange, className, readOnly, placeholder, ...props }, ref) => {
const [localValue, setLocalValue] = React.useState(value ?? '');
const initialValue = React.useRef(value ?? '');
@@ -71,6 +72,7 @@ const SmartTextInput = React.forwardRef<HTMLInputElement, SmartTextInputProps>(
onBlur={handleBlur}
onKeyDown={handleKeyDown}
readOnly={readOnly}
placeholder={placeholder}
{...props}
/>
);

View File

@@ -7,7 +7,7 @@ import { useWorkspace } from '@/contexts/workspace';
export const PageNodeView = ({ node }: NodeViewProps) => {
const workspace = useWorkspace();
const id = node.attrs.id;
const name = node.attrs.name ?? 'Untitled';
const name = node.attrs.name ?? 'Unnamed';
const avatar = node.attrs.avatar;
if (!id) {

View File

@@ -26,11 +26,12 @@ export const useRecordCreateMutation = () => {
result.rows && result.rows.length > 0 ? result.rows[0] : null;
const maxIndex = lastChild?.index ? lastChild.index : null;
const recordId = NeuronId.generate(NeuronId.Type.Record);
const index = generateNodeIndex(maxIndex, null);
const query = workspace.schema
.insertInto('nodes')
.values({
id: NeuronId.generate(NeuronId.Type.Record),
id: recordId,
type: NodeTypes.Record,
parent_id: input.databaseId,
index,
@@ -42,6 +43,7 @@ export const useRecordCreateMutation = () => {
.compile();
await workspace.mutate(query);
return recordId;
},
});
};