import {LitElement, html} from "lit" import {TemplateResult} from "@benev/slate" import {property} from "lit/decorators.js" import {styles} from "./styles.js" import loadingSvg from "../../icons/loading.svg.js" import addSvg from "../../icons/gravity-ui/add.svg.js" import {HistoricalState} from "../../context/types.js" import binSvg from "../../icons/gravity-ui/bin.svg.js" import {collaboration} from "../../context/context.js" import {removeLoadingPageIndicator} from "../../main.js" import exportSvg from "../../icons/gravity-ui/export.svg.js" import warningSvg from "../../icons/gravity-ui/warning.svg.js" import {generate_id} from "@benev/slate/x/tools/generate_id.js" import circlePlaySvg from "../../icons/gravity-ui/circle-play.svg.js" import collaborateSvg from "../../icons/gravity-ui/collaborate.svg.js" import {Project} from "../../context/controllers/project/controller.js" import documentImportSvg from "../../icons/carbon-icons/document-import.svg.js" import {calculateProjectDuration} from "../../utils/calculate-project-duration.js" import {convert_ms_to_hms} from "../omni-timeline/views/time-ruler/utils/convert_ms_to_hms.js" export class OmniManager extends LitElement { project = new Project() static styles = styles @property({type: Boolean}) joiningInProgress = false @property() sessionError: unknown = "" @property({type: String, attribute: false}) private inviteID = "" @property() projects: HistoricalState[] = [] loadProjects() { for(const project of this.project.loadProjectsFromStorage()) { if(project) this.projects = [...this.projects, project] } } removeProject(projectId: string, prefix: string) { localStorage.removeItem(prefix + projectId) this.projects = [] this.loadProjects() this.project.onNotify.publish({message: "Project removed successfully!", type: "info"}) this.requestUpdate() } connectedCallback() { super.connectedCallback() this.loadProjects() removeLoadingPageIndicator() this.project.onNotify(e => this.showToast(e.message, e.type)) } showToast(message: string, type: "error" | "warning" | "info") { const toast = document.createElement("div") toast.textContent = message toast.className = `toast ${type}` document.body.appendChild(toast) setTimeout(() => document.body.removeChild(toast), 5000) } async joinRoom() { this.joiningInProgress = true this.requestUpdate() try { await collaboration.joinRoom(this.inviteID) this.joiningInProgress = false } catch(e) { collaboration.initiatingProject = false this.sessionError = e this.joiningInProgress = false } this.requestUpdate() } handleCollaborationUI(content: TemplateResult) { return html`

${collaborateSvg} Collaboration

${this.joiningInProgress ? html`Session loading ${loadingSvg}` : this.sessionError === "" ? content : html` ${warningSvg} error joining session reason: ${this.sessionError} ` }
` } setInviteId(str: string) { this.inviteID = str this.requestUpdate() } render() { return html`
${this.handleCollaborationUI(html`

Join Session

{this.setInviteId((e.target as HTMLInputElement).value); this.requestUpdate()}} >
`)}

Your projects

${this.projects.map(project => html`
${project.effects?.length === 0 ? 0 : convert_ms_to_hms(calculateProjectDuration(project.effects))}s
${circlePlaySvg} ${project.projectName}
`)}
`} }