rspace-online/website/create-space.html

318 lines
8.2 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🌌</text></svg>">
<title>Create a Space — rSpace</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
color: white;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding-top: 56px;
}
.hero {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: calc(100vh - 56px);
width: 100%;
}
.container {
text-align: center;
max-width: 520px;
padding: 40px 20px;
width: 100%;
}
h1 {
font-size: 2.5rem;
margin-bottom: 0.75rem;
background: linear-gradient(135deg, #14b8a6, #22d3ee);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.tagline {
font-size: 1.1rem;
color: #94a3b8;
margin-bottom: 2.5rem;
}
.create-form {
display: flex;
flex-direction: column;
gap: 1.25rem;
background: rgba(255, 255, 255, 0.05);
padding: 2rem;
border-radius: 16px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.form-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
text-align: left;
}
label {
font-size: 0.875rem;
color: #94a3b8;
}
input, select {
padding: 12px 16px;
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.2);
background: rgba(255, 255, 255, 0.05);
color: white;
font-size: 1rem;
}
select option {
background: #1e293b;
color: white;
}
input:focus, select:focus {
outline: none;
border-color: #14b8a6;
}
input::placeholder {
color: #64748b;
}
.slug-preview {
font-size: 0.875rem;
color: #64748b;
margin-top: 0.25rem;
}
.slug-preview span {
color: #14b8a6;
}
button {
padding: 14px 28px;
border-radius: 8px;
border: none;
background: linear-gradient(135deg, #14b8a6, #0d9488);
color: white;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(20, 184, 166, 0.3);
}
button:active {
transform: translateY(0);
}
button:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
.error {
color: #ef4444;
font-size: 0.875rem;
margin-top: 0.5rem;
}
.help-text {
font-size: 0.8rem;
color: #64748b;
margin-top: 0.25rem;
}
.back-link {
display: inline-block;
margin-top: 1.5rem;
color: #64748b;
text-decoration: none;
font-size: 0.9rem;
transition: color 0.2s;
}
.back-link:hover {
color: #94a3b8;
}
</style>
<link rel="stylesheet" href="/shell.css">
<script defer src="https://rdata.online/collect.js" data-website-id="6ee7917b-0ed7-44cb-a4c8-91037638526b"></script>
</head>
<body data-theme="dark">
<header class="rstack-header" data-theme="dark">
<div class="rstack-header__left">
<rstack-app-switcher current=""></rstack-app-switcher>
<rstack-space-switcher current="" name="Spaces"></rstack-space-switcher>
</div>
<div class="rstack-header__right">
<rstack-identity></rstack-identity>
</div>
</header>
<div class="hero">
<div class="container">
<h1>Create a Space</h1>
<p class="tagline">Start a collaborative community space with all the r* tools built in.</p>
<form class="create-form" id="create-form">
<div class="form-group">
<label for="community-name">Space Name</label>
<input
type="text"
id="community-name"
placeholder="e.g. MycoFi Commons"
required
/>
</div>
<div class="form-group">
<label for="community-slug">URL Slug</label>
<input
type="text"
id="community-slug"
placeholder="e.g. mycofi"
pattern="[a-z0-9-]+"
required
/>
<p class="slug-preview">Your space will be at: <span id="slug-preview">___.rspace.online</span></p>
</div>
<div class="form-group">
<label for="visibility">Visibility</label>
<select id="visibility">
<option value="public">Public — anyone can read and write</option>
<option value="public_read" selected>Public Read — anyone can view, sign in to edit</option>
<option value="authenticated">Authenticated — sign in to view and edit</option>
<option value="members_only">Members Only — invite-only access</option>
</select>
<p class="help-text">You can change this later in space settings.</p>
</div>
<button type="submit">Create Space</button>
<p class="error" id="error-message" style="display: none;"></p>
</form>
<a href="/" class="back-link">&larr; Back to rSpace</a>
</div>
</div>
<script type="module">
import { RStackIdentity } from "@shared/components/rstack-identity";
import { RStackAppSwitcher } from "@shared/components/rstack-app-switcher";
import { RStackSpaceSwitcher } from "@shared/components/rstack-space-switcher";
import { requireAuth, isAuthenticated, getAccessToken } from "@shared/components/rstack-identity";
RStackIdentity.define();
RStackAppSwitcher.define();
RStackSpaceSwitcher.define();
fetch("/api/modules").then(r => r.json()).then(data => {
document.querySelector("rstack-app-switcher")?.setModules(data.modules || []);
}).catch(() => {});
const nameInput = document.getElementById("community-name");
const slugInput = document.getElementById("community-slug");
const slugPreview = document.getElementById("slug-preview");
const form = document.getElementById("create-form");
const errorMessage = document.getElementById("error-message");
const visibility = document.getElementById("visibility");
nameInput.addEventListener("input", () => {
const slug = nameInput.value
.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-|-$/g, "");
slugInput.value = slug;
slugPreview.textContent = slug ? `${slug}.rspace.online` : "___.rspace.online";
});
slugInput.addEventListener("input", () => {
const slug = slugInput.value.toLowerCase().replace(/[^a-z0-9-]/g, "");
slugInput.value = slug;
slugPreview.textContent = slug ? `${slug}.rspace.online` : "___.rspace.online";
});
async function submitCreateCommunity() {
errorMessage.style.display = "none";
const name = nameInput.value.trim();
const slug = slugInput.value.trim();
if (!name || !slug) {
errorMessage.textContent = "Please fill in all fields";
errorMessage.style.display = "block";
return;
}
const token = getAccessToken();
if (!token) {
errorMessage.textContent = "Authentication token missing. Please sign in again.";
errorMessage.style.display = "block";
return;
}
const submitBtn = form.querySelector("button");
submitBtn.disabled = true;
submitBtn.textContent = "Creating...";
try {
const response = await fetch("/api/communities", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`,
},
body: JSON.stringify({ name, slug, visibility: visibility.value }),
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || "Failed to create community");
}
window.location.href = `/${slug}/canvas`;
} catch (err) {
errorMessage.textContent = err.message;
errorMessage.style.display = "block";
submitBtn.disabled = false;
submitBtn.textContent = "Create Space";
}
}
form.addEventListener("submit", (e) => {
e.preventDefault();
if (!isAuthenticated()) {
requireAuth(() => submitCreateCommunity());
return;
}
submitCreateCommunity();
});
</script>
</body>
</html>