Skip to content

Commit

Permalink
removes a lot of unneeded code from aicg v1 (#4429)
Browse files Browse the repository at this point in the history
* removes a lot of unneeded code in aicg v1
  • Loading branch information
rusticpenguin authored Aug 8, 2023
1 parent 3e315fd commit 90b4326
Showing 1 changed file with 1 addition and 50 deletions.
51 changes: 1 addition & 50 deletions apps/ai-content-generator/src/locations/SidebarV1.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useState } from 'react';
import { useEffect, useState } from 'react';
import {
Box,
Button,
Expand All @@ -11,7 +11,6 @@ import {
} from '@contentful/f36-components';
import { ExternalLinkTrimmedIcon } from '@contentful/f36-icons';
import { documentToPlainTextString } from '@contentful/rich-text-plain-text-renderer';
import { createClient } from 'contentful-management';
import { useSDK } from '@contentful/react-apps-toolkit';
import RichTextModel from '../richTextModel';
import prompts from '../prompts';
Expand All @@ -34,17 +33,6 @@ const Sidebar = () => {

const fields = sdk.entry.fields;

const cma = createClient(
{ apiAdapter: sdk.cmaAdapter },
{
type: 'plain',
defaults: {
environmentId: sdk.ids.environmentAlias ?? sdk.ids.environment,
spaceId: sdk.ids.space,
},
}
);

const [error, setError] = useState(null);
const [prompt, setPrompt] = useState(fields[sdk.contentType.displayField].getValue() || '');
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -115,43 +103,6 @@ const Sidebar = () => {
});

useEffect(() => {
// Find ALL the fields in document, including the ones that are going up the tree
async function getTree() {
const entries = await cma.entry.getMany({
query: {
links_to_entry: sdk.entry.getSys().id,
},
});
if (entries.total > 0) {
const entry = entries.items[0];
const contentType = await cma.contentType.get({
contentTypeId: entry.sys.contentType.sys.id,
});
// Merge the content types with the locale info
const fields = contentType.fields.map((field: any) => {
field.locales = entry.fields[field.id] ? Object.keys(entry.fields[field.id]) : [];
return field;
});
const parentRichTextFields = fields
.filter((field) => field.type === 'RichText')
.filter((field) => field.locales.includes(targetLocale));
// Merge the new fields with the existing ones from the parent, but indicate they are not visibile inside the current editor
setRichTextFields([
...richTextFields,
...parentRichTextFields.map((field) => {
return {
name: field.name,
data: entry.fields[field.id][targetLocale],
currentEditor: false,
};
}),
]);
}
}
getTree();
}, [cma.contentType, cma.entry, sdk.entry, targetLocale]);

useMemo(() => {
const fields = sdk.entry.fields;
const textFields = Object.keys(fields)
.filter((key) => fields[key].type === 'Symbol' || fields[key].type === 'Text')
Expand Down

0 comments on commit 90b4326

Please sign in to comment.