newOS for Developers

Back to Mood Management

Create Mood

beginner

Create a new folder or space for organizing content

POST /mood

Overview

Moods (also called folders or spaces) are the primary organizational unit in Newgraph. The createFolder action creates a new mood with configurable title, description, privacy settings, and optional future grantees.

The action supports a "future" mode where a provisional folder is created locally in the cache before being committed to the server. This enables optimistic UI updates.

Request

import { createFolder } from "newgraph-signals/actions/folder";

// Create a new mood via progressive handler
const progress = createFolder();

// Execute the creation
progress.exec({
  title: "My Collection",
  description: "A space for my content",
  isPrivate: true,                    // Default: true
  licenseType: "private",             // "private" | "cc0" | "cc-by"
  future: false,                      // Create provisionally first
  futureGrantees: [{ id: "userId" }], // Users to grant access
});

// Track progress
progress.done;     // boolean - is operation complete
progress.error;    // Error | undefined
progress.loading;  // boolean - is loading

Parameters

ParameterTypeRequiredDescription
titlestringYesDisplay name for the mood
descriptionstringNoOptional description text
isPrivatebooleanNoAccess visibility (default: true)
licenseTypestringNo"private" | "cc0" | "cc-by"
futurebooleanNoCreate provisional folder locally first
futureGrantees{id: string}[]NoUsers to auto-grant access on creation

Response

// MoodCreateResponse
{
  "id": "aec78e08-fbf2-4511-a3d8-e360686297da",
  "title": "My Collection",
  "description": "A space for my content",
  "isPrivate": true,
  "author": {
    "id": "user-uuid",
    "username": "creator"
  },
  "created": "2024-01-15T10:30:00Z",
  "updated": "2024-01-15T10:30:00Z"
}

Edge Cases

Future Mode: When future: true, the folder is created locally with a UUID before server commit. Use for optimistic UI patterns.
Caching: Created folders are automatically cached in IndexedDB via cacheFolders().
Auto-Grant: If futureGrantees is provided, access is automatically granted after creation via grantWriteAccessMulti.