Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Links for embedding models elsewhere #401

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
317 changes: 315 additions & 2 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/backend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DATABASE_URL=postgres://hamidahoderinwale@localhost:5432/catcolab
FIREBASE_PROJECT_ID=catcolab-next

3 changes: 2 additions & 1 deletion packages/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ qubit = "0.10.2"
regex = "1.11.1"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
shuttle-persist = "0.51.0"
socketioxide = { version = "0.14.1", features = ["tracing"] }
sqlx = { version = "0.8.2", features = ["runtime-tokio", "tls-native-tls", "postgres", "uuid", "json"] }
sqlx = { version = "0.8.2", features = ["runtime-tokio", "tls-native-tls", "postgres", "uuid", "json", "macros"] }
thiserror = "1.0.64"
tokio = { version = "1.40.0", features = ["full"] }
tower = { version = "0.5.1", features = ["util"] }
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// generated by `sqlx migrate build-script`
fn main() {
// trigger recompilation when a new migration is added
println!("cargo:rerun-if-changed=migrations");
}
4 changes: 4 additions & 0 deletions packages/backend/migration_status.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
20241004010448/installed document refs
20241025030906/installed users
20250114010822/installed test first five view
20250121193606/installed testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Add down migration script here
SELECT *
FROM users
LIMIT 2;

SELECT *
FROM permission_level
LIMIT 2;

SELECT *
FROM permissions
LIMIT 2;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM _sqlx_migrations WHERE version = '20250121193606';
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- Add down migration script here
1 change: 1 addition & 0 deletions packages/backend/migrations/20250121200530_testing.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- Add up migration script here
14 changes: 14 additions & 0 deletions packages/backend/src/search.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use sqlx::PgPool;

// adding indices to the table of models

pub fn

// take an enum for each instance of a model, subtyped based on the theory

pub enum modelInstance {
title,
theory,

}
// taking each title of model as keyword / tokenizing
21 changes: 21 additions & 0 deletions packages/backend/src/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use sqlx::PgPool; // Import PgPool for PostgreSQL connection
use std::env;

#[tokio::main]
async fn main() -> Result<(), sqlx::Error> {
// Set up the database connection pool
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let pool = PgPool::connect(&database_url).await?;

// Execute the query and fetch results
let rows = sqlx::query("SELECT * FROM Catcolab LIMIT 5")
.fetch_all(&pool)
.await?;

// Print each row
for row in rows {
println!("{:?}", row);
}

Ok(())
}
62 changes: 62 additions & 0 deletions packages/frontend/src/model/model_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { useParams } from "@solidjs/router";
import { Match, Show, Switch, createResource, useContext } from "solid-js";
import invariant from "tiny-invariant";

import Dialog from "@corvu/dialog";
import CodeXml from "lucide-solid/icons/code-xml";
import { createMemo, createSignal } from "solid-js";
import { useApi } from "../api";
import { InlineInput } from "../components";
import { IconButton } from "../components";
import {
type CellConstructor,
type FormalCellEditorProps,
Expand Down Expand Up @@ -189,3 +193,61 @@ function judgmentLabel(judgment: ModelJudgment): string | undefined {
return theory.modelMorTypeMeta(judgment.morType)?.name;
}
}

export function EmbedButton() {
const [isOpen, setIsOpen] = createSignal(false);

return (
<>
<IconButton
onClick={() => setIsOpen(true)}
tooltip="Embed Notebook"
class="embed-button"
>
<CodeXml />
<p>Embed</p>
</IconButton>
<EmbedDialog isOpen={isOpen()} onClose={() => setIsOpen(false)} />
</>
);
}

function EmbedDialog(props: { isOpen: boolean; onClose: () => void }) {
const [copyStatus, setCopyStatus] = createSignal<"Copied!" | "Please try again later." | "">(
"",
);
const embedLink = createMemo(() => {
const pageURL = window.location.href;
return `<iframe src="${pageURL}" width="100%" height="500" frameborder="0"></iframe>`;
});

const copyToClipboard = async () => {
try {
await navigator.clipboard.writeText(embedLink());
setCopyStatus("Copied!");
} catch (err) {
setCopyStatus("Please try again later.");
}
};

return (
<Dialog open={props.isOpen} onOpenChange={props.onClose}>
<Dialog.Portal>
<Dialog.Overlay class="overlay" />
<Dialog.Content class="popup">
<Dialog.Label>Embed Notebook</Dialog.Label>
<Dialog.Description>Copy iframe Code Below:</Dialog.Description>
<div class="embed-code-container">
<code class="embed-code">{embedLink()}</code>
<div class="copy-status">
<button onClick={copyToClipboard} class="link-button">
Copy
</button>
<span>{copyStatus()}</span>
</div>
</div>
</Dialog.Content>
</Dialog.Portal>
</Dialog>
);
}
28 changes: 28 additions & 0 deletions packages/frontend/src/page/menubar.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,31 @@
color: dimgray;
}
}

.embed-code-container {
display: flex;
gap: 1rem;
align-items: flex-start;
margin: 1rem 0;
}

.embed-code {
display: block;
overflow-x: auto;
flex: 1;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
background-color: #f5f5f5;
border: 1px solid #e0e0e0;
border-radius: 4px;
padding: 0.75rem;
font-size: 0.875rem;
line-height: 1.4;
color: #333;
}

.copy-status {
display: flex;
flex-direction: column;
line-height: 2em;
color: gray;
}
13 changes: 13 additions & 0 deletions packages/frontend/src/user/permissions.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,16 @@
align-items: center;
gap: 5em;
}

.embed-button {
display: flex;
align-items: center;
gap: 8px;
margin: none;
border: none;
padding: none;
border-radius: 10%;
p {
font-family: var(--main-font);
}
}
55 changes: 29 additions & 26 deletions packages/frontend/src/user/permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import invariant from "tiny-invariant";
import type { NewPermissions, PermissionLevel, Permissions, UserSummary } from "catcolab-api";
import { useApi } from "../api";
import { Dialog, FormGroup, IconButton, SelectItem, Warning } from "../components";
import { EmbedButton } from "../model/model_editor";
import { deepCopyJSON } from "../util/deepcopy";
import { Login } from "./login";
import { NameUser, UserInput } from "./username";
Expand Down Expand Up @@ -235,32 +236,34 @@ function AnonPermissionsButton() {
};

return (
<Dialog
open={open()}
onOpenChange={setOpen}
title="Permissions"
trigger={AnonPermissionsTrigger}
>
<p>
This document can be <strong>edited by anyone</strong> with the link.
</p>
<Switch>
<Match when={user.data}>
<p>
Create a new document to restrict permissions, <br /> or{" "}
<a href="#" onClick={logOut}>
log out
</a>{" "}
to create other anonymous documents.
</p>
</Match>
<Match when={!user.loading}>
<div class="separator" />
<p>To create documents with restricted permissions, log in.</p>
<Login onComplete={() => setOpen(false)} />
</Match>
</Switch>
</Dialog>
<>
<Dialog open={open()} onOpenChange={setOpen} title="" trigger={AnonPermissionsTrigger}>
<div class="embed-button">
<h4>Permissions</h4>
<EmbedButton />
</div>

<p>
This document can be <strong>edited by anyone</strong> with the link.
</p>
<Switch>
<Match when={user.data}>
<p>
Create a new document to restrict permissions, <br /> or{" "}
<a href="#" onClick={logOut}>
log out
</a>{" "}
to create other anonymous documents.
</p>
</Match>
<Match when={!user.loading}>
<div class="separator" />
<p>To create documents with restricted permissions, log in.</p>
<Login onComplete={() => setOpen(false)} />
</Match>
</Switch>
</Dialog>
</>
);
}

Expand Down