Skip to content

Commit

Permalink
body
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotBraem committed Jan 29, 2024
1 parent 973488e commit 67b932c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 28 deletions.
30 changes: 28 additions & 2 deletions apps/editor/widget/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,23 @@ const defaultViewMode = get("viewMode");
const defaultPreview = get("preview");
const defaultEditor = get("editor");
const defaultLanguage = get("language");
const defaultType = get("type");

if (
draft === null ||
viewMode === null ||
defaultPreview === null ||
defaultEditor === null
defaultEditor === null ||
defaultLanguage === null ||
defaultType === null
) {
return "";
}

const [content, setContent] = useState(draft);
const [viewMode, setViewMode] = useState(defaultViewMode || "single"); // 'single' or 'split'
const [showPreview, setShowPreview] = useState(defaultPreview || false);
const [type, setType] = useState(defaultType || "");
const [editor, setEditor] = useState(defaultEditor || "");
const [language, setLanguage] = useState(defaultLanguage || "md");

Expand Down Expand Up @@ -122,6 +126,13 @@ const languages = [
},
];

const types = [
{
value: "document",
label: "Document",
},
];

const DefaultEditor = ({ value, onChange, onBlur }) => (
<EditorTextarea
placeholder="Start typing..."
Expand Down Expand Up @@ -173,7 +184,7 @@ return (
props={{
creatorId: context.accountId,
path: path,
data: content,
data: JSON.stringify({ body: content }),
}}
/>
</ModalBox>
Expand Down Expand Up @@ -211,6 +222,7 @@ return (
props={{
creatorId: context.accountId,
path: path,
type: type,
}}
/>
</ModalBox>
Expand All @@ -221,6 +233,20 @@ return (
</div>
</Header>
<div>
<Label>type:</Label>
<Select
onChange={(e) => {
set("type", e.target.value);
setType(e.target.value);
}}
>
{types &&
types.map((it) => (
<Option value={it.value} selected={it.value === type}>
{it.label}
</Option>
))}
</Select>
<Label>editor:</Label>
<Select
onChange={(e) => {
Expand Down
58 changes: 32 additions & 26 deletions apps/editor/widget/modal/create.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,38 +80,44 @@ const [filename, setFilename] = useState(props.filename ?? "");
const [activeTab, setActiveTab] = useState("data");
const [name, setName] = useState(props.name ?? "");
const [description, setDescription] = useState(props.description ?? "");
const [type, setType] = useState(props.type ?? "");
const [path, setPath] = useState(props.path ?? `${context.accountId}/`);
const [type, setType] = useState(props.type ?? "document");
const [path, setPath] = useState(
props.path ?? `${context.accountId}/every/document/test`
);

const socialDbAdapter = {
get: (path, blockHeight) => {
if (!path) console.log("path not provided") && null;
if (!blockHeight) blockHeight = "final";
return Social.get(path, blockHeight);
},
create: (v) => {
create: (v, path, type) => {
const parts = path.split("/");
return Social.set(
{
[parts[1]]: {
[parts[2]]: {
"": v,
metadata: {
type: type,
},
},
},
let nestedObject = {};
let currentLevel = nestedObject;

for (let i = 1; i < parts.length - 1; i++) {
const part = parts[i];
currentLevel[part] = {};
currentLevel = currentLevel[part];
}

currentLevel[parts[parts.length - 1]] = {
"": v,
metadata: {
type: type,
},
{
force: "true",
onCommit: (v) => {
console.log(v);
},
onCancel: (v) => {
console.log(v);
},
}
);
};

return Social.set(nestedObject, {
force: "true",
onCommit: (v) => {
console.log(v);
},
onCancel: (v) => {
console.log(v);
},
});
},
};

Expand All @@ -124,15 +130,13 @@ function generateUID() {
}

const handleCreate = () => {
const isCreator = context.accountId === creatorId;

// load in the state.adapter (modules for IPFS, Arweave, Ceramic, Verida, On Machina... )
const { create } = adapter ? VM.require(adapter) : socialDbAdapter;
console.log("creating with", adapter);
// const { create } = VM.require(adapter) || (() => {});
if (create) {
// store the data somewhere, based on the adapter
create(json)
create(json, path, type);
// .then((reference) => {
// // now we have a reference to the data
// // we need to name it... are we the original creator or are we forking? We don't want to overwrite any of the users custom (or maybe we do!)
Expand Down Expand Up @@ -216,6 +220,7 @@ return (
<Input
type="text"
value={path}
disabled // temp
onChange={(e) => setPath(e.target.value)}
/>
</FormGroup>
Expand All @@ -224,6 +229,7 @@ return (
<Input
type="text"
value={type}
disabled // temp
onChange={(e) => setType(e.target.value)}
/>
</FormGroup>
Expand Down

0 comments on commit 67b932c

Please sign in to comment.