82 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			HTML
		
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			HTML
		
	
	
	
<!DOCTYPE html>
 | 
						|
<head>
 | 
						|
  <title>Forum test</title>
 | 
						|
  <link type="text/css" rel="stylesheet" href="/index.css" />
 | 
						|
</head>
 | 
						|
<body>
 | 
						|
  <div id="forum-test"></div>
 | 
						|
</body>
 | 
						|
<script type="module">
 | 
						|
  import { Box } from "/classes/box.js";
 | 
						|
  import { Scene } from "/classes/scene.js";
 | 
						|
  import { Expert } from "/classes/expert.js";
 | 
						|
  import { Bench } from "/classes/bench.js";
 | 
						|
  import { Business } from "/classes/business.js";
 | 
						|
  import { Availability } from "/classes/availability.js";
 | 
						|
  import { delay } from "/util.js";
 | 
						|
  import { Forum } from "/classes/forum.js";
 | 
						|
  import { Public } from "/classes/public.js";
 | 
						|
  import { PostContent } from "/classes/post.js";
 | 
						|
 | 
						|
  const DELAY_INTERVAL = 500;
 | 
						|
 | 
						|
  const rootElement = document.getElementById("forum-test");
 | 
						|
  const rootBox = new Box("rootBox", rootElement).flex();
 | 
						|
 | 
						|
  const scene = (window.scene = new Scene("Forum test", rootBox).log(
 | 
						|
    "sequenceDiagram"
 | 
						|
  ));
 | 
						|
 | 
						|
  const members = (window.members = []);
 | 
						|
  const newExpert = async () => {
 | 
						|
    const index = members.length;
 | 
						|
    const name = `Expert${index + 1}`;
 | 
						|
    const member = await new Expert(name, scene).initialize();
 | 
						|
    members.push(member);
 | 
						|
    return member;
 | 
						|
  };
 | 
						|
 | 
						|
  const posts = (window.posts = []);
 | 
						|
  const newPost = async (author, content, citations) => {
 | 
						|
    const postContent = new PostContent({ hello: "there" });
 | 
						|
    const postId = await member1.submitPost(forum, postContent1);
 | 
						|
    return postId;
 | 
						|
  };
 | 
						|
 | 
						|
  const member1 = await newExpert();
 | 
						|
  const member2 = await newExpert();
 | 
						|
  await newExpert();
 | 
						|
  const bench = (window.bench = new Bench("Bench", scene));
 | 
						|
  const forum = (window.forum = new Forum(bench, "Forum", scene));
 | 
						|
 | 
						|
  const updateDisplayValues = async () => {
 | 
						|
    for (const member of members) {
 | 
						|
      member.setValue(
 | 
						|
        "rep",
 | 
						|
        bench.reputations.getTokens(member.reputationPublicKey)
 | 
						|
      );
 | 
						|
    }
 | 
						|
    bench.setValue("total rep", bench.getTotalReputation());
 | 
						|
    await scene.renderSequenceDiagram();
 | 
						|
  };
 | 
						|
 | 
						|
  const updateDisplayValuesAndDelay = async () => {
 | 
						|
    await updateDisplayValues();
 | 
						|
    await delay(DELAY_INTERVAL);
 | 
						|
  };
 | 
						|
 | 
						|
  await updateDisplayValuesAndDelay();
 | 
						|
 | 
						|
  const postId1 = await member1.submitPost(
 | 
						|
    forum,
 | 
						|
    new PostContent({ hello: "there" })
 | 
						|
  );
 | 
						|
  await updateDisplayValuesAndDelay();
 | 
						|
 | 
						|
  const postId2 = await member1.submitPost(
 | 
						|
    forum,
 | 
						|
    new PostContent({ hello: "to you as well" }).addCitation(postId1, 0.5)
 | 
						|
  );
 | 
						|
  await updateDisplayValuesAndDelay();
 | 
						|
</script>
 |