From 8e4163e3f08e29f38fe87c59d8cfb91e0fa98063 Mon Sep 17 00:00:00 2001 From: kartofen Date: Mon, 29 Aug 2022 19:01:20 +0300 Subject: everything works --- src/components/Form.astro | 7 ++- src/components/Image.astro | 21 +++++++++ src/components/Post.astro | 28 ++++++++++++ src/components/Thread.astro | 82 +++++++++++++++++++++++++++++++++ src/components/Thread.svelte | 105 ------------------------------------------- 5 files changed, 137 insertions(+), 106 deletions(-) create mode 100644 src/components/Image.astro create mode 100644 src/components/Post.astro create mode 100644 src/components/Thread.astro delete mode 100644 src/components/Thread.svelte (limited to 'src/components') diff --git a/src/components/Form.astro b/src/components/Form.astro index 417b569..540a4d4 100644 --- a/src/components/Form.astro +++ b/src/components/Form.astro @@ -1,7 +1,11 @@ --- -import '../styles/blackbox.css'; import { sha256 } from 'js-sha256'; +export interface Props { + board: string; + tid?: string +} + const { board, tid } = Astro.props; const iphash = sha256(Astro.clientAddress); --- @@ -31,6 +35,7 @@ const iphash = sha256(Astro.clientAddress); if(r.status == 200) { alert('Thread Successfuly Posted'); let id = await r.text(); + if(id == 'close') window.top.close(); window.location.assign(`/board/${board}/${id}`); } else alert('An Error has Accured'); diff --git a/src/components/Image.astro b/src/components/Image.astro new file mode 100644 index 0000000..07dbadf --- /dev/null +++ b/src/components/Image.astro @@ -0,0 +1,21 @@ +--- +export interface Props { + image: string; + fileType: string; +} + +const { image, fileType } = Astro.props; +--- + +{(image!= null) && ( + (fileType == 'image') ? ( + + {image}
+
+ ) : ( + (fileType == 'image') && ( + + )) +)} \ No newline at end of file diff --git a/src/components/Post.astro b/src/components/Post.astro new file mode 100644 index 0000000..6805846 --- /dev/null +++ b/src/components/Post.astro @@ -0,0 +1,28 @@ +--- +import { creatorColor, formatTime } from '../lib/util'; + +export interface Props { + id: string; + date: number; + creator: string; + box: string; + board: string +} + +const { id, date, creator, box, board = '' } = Astro.props; +--- +
+ + {(board != '') ? ( + {id} + ) : ( + {id} + )} + + at {formatTime(date)}
+ -> + {creator} +
+

+ +
diff --git a/src/components/Thread.astro b/src/components/Thread.astro new file mode 100644 index 0000000..6fae3de --- /dev/null +++ b/src/components/Thread.astro @@ -0,0 +1,82 @@ +--- +import type Thread from '../models/Thread'; +import Post from './Post.astro'; +import Image from './Image.astro'; + +export interface Props { + thread: Thread; + board: string; + comments: boolean; +} + +const { thread, board, comments = false } = Astro.props; + +let replies: string[] = []; +const listReplies = (id: string, getReplies: boolean = false): any => { + if(getReplies) return replies; + + replies = []; + thread.comments.forEach(comment => { + if(comment.commentText.includes(id)) + replies.push(comment.id); + }) + + if(replies.length <= 0) return false; + return true; +} +--- + +{(thread.id != "rules") && ( <> + + + {comments && (listReplies(thread.id) && ( + + {listReplies(thread.id, true).map((id) => ( <> + >>{id} + ))} +
+ ))} + + +

{thread.threadName}

+ +

+ + {comments && ( <> + {thread.comments.map((comment) => ( <> + + + {listReplies(comment.id) && ( + + {listReplies(comment.id, true).map((id) => ( <> + >>{id} + ))} +


+ )} + + +

+ + + ))} + )} + + + )} + +{comments && ( <> + + + + )} diff --git a/src/components/Thread.svelte b/src/components/Thread.svelte deleted file mode 100644 index 0321b8d..0000000 --- a/src/components/Thread.svelte +++ /dev/null @@ -1,105 +0,0 @@ - - -{#if thread.id != "rules"} -

- - {thread.id} - at {formatTime(thread.creationDate)}
- - -> - {thread.threadCreator} -
-
- - {#if comments} - {#if listReplies(thread.id) } - - {#each listReplies(thread.id, true) as id} - >>{id}  - {/each} -
- {/if} - {/if} - -
- -

{thread.threadName}

- - {#if thread.imageId!= null && thread.imageId != undefined} - {#if thread.fileType == 'image'} - - {thread.imageId}
-
- {:else if thread.fileType == 'video'} - - {/if} - {/if} - -

{@html thread.threadText}

- -{#if comments} - {#each thread.comments as comment} -
- - {comment.id} - at {formatTime(comment.creationDate)}
- - -> - {comment.commentCreator} -
-
- - {#if listReplies(comment.id)} - - {#each listReplies(comment.id, true) as id} - >>{id}  - {/each} -
- {/if} - -
- - {#if comment.imageId!= null && comment.imageId != undefined} - {#if comment.fileType == 'image'} - - {comment.imageId}
-
- {:else if comment.fileType == 'video'} - - {/if} - {/if} - -

{@html comment.commentText}

- -
- {/each} -{/if} - -
-{/if} -- cgit v1.2.3