Support diaries (kinda)
This commit is contained in:
@ -2,17 +2,19 @@ import type { NextPage } from "next";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import asciidoctor from "asciidoctor";
|
||||
import styles from "../styles/ProjectModal.module.css";
|
||||
import Link from "next/link";
|
||||
import type { Project, Diary } from "../lib/projects/types";
|
||||
//import Link from "next/link";
|
||||
|
||||
interface ModalInput {
|
||||
project: string;
|
||||
project: Project|Diary|undefined;
|
||||
projectType: "project"|"diary";
|
||||
visible: boolean;
|
||||
setVisible: CallableFunction;
|
||||
}
|
||||
|
||||
const ad = asciidoctor();
|
||||
|
||||
const ProjectModal: NextPage<ModalInput> = ({ project, visible, setVisible }) => {
|
||||
const ProjectModal: NextPage<ModalInput> = ({ project, projectType, visible, setVisible }) => {
|
||||
const projectEmpty = "<div>Kein Projekt ausgewählt.</div>";
|
||||
const [projectData, setProjectData] = useState<string>(projectEmpty);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
@ -29,24 +31,24 @@ Last updated: ${lastUpdate} | <a href="https://git.c0ntroller.de/c0ntroller/fron
|
||||
`;
|
||||
|
||||
useEffect(() => {
|
||||
if (project && project !== "") {
|
||||
if (project && project.name) {
|
||||
// TODO
|
||||
// set Spinner
|
||||
setProjectData("Loading...");
|
||||
fetch(`/api/projects/${project}`).then((res) => {
|
||||
fetch(`/api/${projectType === "diary" ? "diaries" : "projects"}/${project.name}`).then((res) => {
|
||||
if (res.status === 404) setProjectData(projectNotFoundHtml);
|
||||
if (res.status !== 200) setProjectData(projectServerErrorHtml);
|
||||
res.text().then(data => {
|
||||
try {
|
||||
const adDoc = ad.load(data, { attributes: { showtitle: true } });
|
||||
setProjectData(adDoc.convert(adDoc).toString() + generateFooter(project, adDoc.getAttribute("docdatetime")));
|
||||
setProjectData(adDoc.convert(adDoc).toString() + generateFooter(project.name, adDoc.getAttribute("docdatetime")));
|
||||
} catch {
|
||||
setProjectData(projectServerErrorHtml);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else if (project === "") setProjectData(projectEmpty);
|
||||
}, [project, projectEmpty, projectNotFoundHtml, projectServerErrorHtml]);
|
||||
} else if (typeof project === "undefined") setProjectData(projectEmpty);
|
||||
}, [project, projectType, projectEmpty, projectNotFoundHtml, projectServerErrorHtml]);
|
||||
|
||||
useEffect(() => {
|
||||
if (projectData && containerRef.current && projectData !== "") {
|
||||
|
@ -3,7 +3,7 @@ import useSWR from "swr";
|
||||
import { MutableRefObject, useState, createRef, useEffect } from "react";
|
||||
import { CommandInterface } from "../../lib/commands";
|
||||
import styles from "../../styles/REPL/REPLInput.module.css";
|
||||
import { Project } from "../../lib/projects/types";
|
||||
import type { ProjectList } from "../../lib/projects/types";
|
||||
|
||||
interface REPLInputParams {
|
||||
historyCallback: CallableFunction;
|
||||
@ -12,10 +12,11 @@ interface REPLInputParams {
|
||||
modalManipulation: {
|
||||
setModalVisible: CallableFunction;
|
||||
setModalProject: CallableFunction;
|
||||
setModalProjectType: CallableFunction;
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchProjects(endpoint: string): Promise<Project[]> {
|
||||
async function fetchProjects(endpoint: string): Promise<ProjectList> {
|
||||
const res = await fetch(endpoint);
|
||||
return res.json();
|
||||
}
|
||||
@ -28,7 +29,7 @@ const REPLInput: NextPage<REPLInputParams> = ({historyCallback, historyClear, in
|
||||
const [inCmdHistory, setInCmdHistory] = useState<number>(-1);
|
||||
const [cmdHistory, setCmdHistory] = useState<string[]>([]);
|
||||
const [usrInputTmp, setUsrInputTmp] = useState<string>("");
|
||||
const [cmdIf, setCmdIf] = useState<CommandInterface>(new CommandInterface(modalManipulation, []));
|
||||
const [cmdIf, setCmdIf] = useState<CommandInterface>(new CommandInterface(modalManipulation, {projects: [], diaries: []}));
|
||||
const { data: projects, error: projectsError } = useSWR("/api/projects?swr=1", fetchProjects);
|
||||
|
||||
const setInput = (inputRef: HTMLInputElement, input: string) => {
|
||||
|
@ -9,6 +9,7 @@ interface IREPLProps {
|
||||
modalManipulation: {
|
||||
setModalVisible: CallableFunction;
|
||||
setModalProject: CallableFunction;
|
||||
setModalProjectType: CallableFunction;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user