]> git.r.bdr.sh - rbdr/forum/commitdiff
Add components to view topics and posts
authorRuben Beltran del Rio <redacted>
Sun, 14 Mar 2021 22:10:01 +0000 (23:10 +0100)
committerRuben Beltran del Rio <redacted>
Sun, 14 Mar 2021 22:10:01 +0000 (23:10 +0100)
20 files changed:
src/components/footer/footer.svelte
src/components/forum/forum.svelte
src/components/forum_list/forum_list.svelte
src/components/glyph/glyph.svelte
src/components/header/header.svelte
src/components/topic/topic.svelte
src/pages/_fallback.svelte
src/pages/_layout.svelte
src/pages/a/[id].svelte
src/pages/f/[id].svelte
src/pages/g/[id].svelte
src/pages/index.svelte
src/pages/p/[id].svelte
src/pages/t/[id].svelte
src/stores/apollo.js
src/stores/forum.js
src/stores/forums.js
src/stores/post.js
src/stores/tag.js
src/stores/topic.js

index 3587aabf8a4692821b10e4a37e6ed178fcbb75ce..317319e052f3821835ea66c20ad207354d4e2c16 100644 (file)
@@ -1,7 +1,7 @@
 <script>
   import { _ } from 'svelte-i18n';
 
-  import LanguageSelector from '../language_selector/language_selector.svelte';
+  import LanguageSelector from '$/components/language_selector/language_selector.svelte';
 
   const licenseUrl = 'https://gitlab.com/rbdr/forum/';
 </script>
index 7008e6655366b5324fa0b5d9231e86aed2408006..8fc0538327f91a241b6481aa1233602c38a07b58 100644 (file)
@@ -2,20 +2,21 @@
   export let id;
 
   import { _ } from 'svelte-i18n';
-  import { getForum } from '$stores/forum';
-  import ErrorBlock from '../error_block/error_block.svelte';
+  import { getForum } from '$/stores/forum';
+  import ErrorBlock from '$/components/error_block/error_block.svelte';
+  import Loader from '$/components/loader/loader.svelte';
 
-  import TopicSummary from '$components/topic_summary/topic_summary.svelte';
+  import TopicSummary from '$/components/topic_summary/topic_summary.svelte';
 
   $: store = getForum(id);
   $: forum = $store.data;
 </script>
 
 {#if $store.loading}
-  <p>Loading...</p>
+  <Loader />
 {/if}
 {#if $store.error}
-  <ErrorBlock message={$_('forum_list.error.unavailable')} />
+  <ErrorBlock message={$_('forum.error.unavailable')} />
 {/if}
 {#if forum}
   <h1>{forum.glyph} {$_(forum.label)}</h1>
index 46f60f08a4f05e3f955bb3420855cb17f8bbcb33..2998c09c22136c100c01e9010d0bb6fda34d3e6a 100644 (file)
@@ -1,12 +1,13 @@
 <script>
   import { _ } from 'svelte-i18n';
-  import { forums } from '$stores/forums';
-  import ErrorBlock from '../error_block/error_block.svelte';
+  import { forums } from '$/stores/forums';
+  import Loader from '$/components/loader/loader.svelte';
+  import ErrorBlock from '$/components/error_block/error_block.svelte';
 </script>
 
 <nav title="{$_('forum_list.title')}">
   {#if $forums.loading}
-    <p>Loading...</p>
+    <Loader />
   {/if}
   {#if $forums.error}
     <ErrorBlock message={$_('forum_list.error.unavailable')} />
index 98d1c6e5d96b456b1147c2d6a21af24426e3e478..32e8ee65cf3e5c8e01bfc1f24793485caeba6847 100644 (file)
@@ -1,6 +1,6 @@
 <script>
   import { _ } from 'svelte-i18n';
-  import { getGlyphHash } from '../../utils/glyph_hash';
+  import { getGlyphHash } from '$/utils/glyph_hash';
 
   export let uuid;
 </script>
index 36d4d500da52fe8e0236008e27343f470510116e..ed91526c4a7822a48164761e8f2dbbc394b3ec59 100644 (file)
@@ -1,7 +1,7 @@
 <script>
   import { _ } from 'svelte-i18n';
 
-  import { version } from '$config/config';
+  import { version } from '$/config/config';
 </script>
 
 <header title="{$_('header.title')}">
index 2aff79a6ce42ef33b64b463a19dd5aab3c2baf3f..9be7346b76f39088166107c5c18728670259e217 100644 (file)
@@ -1,59 +1,46 @@
 <script>
+  export let id;
+
   import { _ } from 'svelte-i18n';
+  import { getTopic } from '$/stores/topic';
 
-  import Glyph from '../glyph/glyph.svelte';
-</script>
+  import ErrorBlock from '$/components/error_block/error_block.svelte';
+  import Loader from '$/components/loader/loader.svelte';
+  import PostContent from '$/components/post_content/post_content.svelte';
+  import { readableTime } from '$/utils/readable_time.js';
 
-<div class="h-entry" title="{$_('topic.title')}">
-  <h1 class="p-name">This is a post in the forum.</h1>
-  <aside class="topic-meta" title="{$_('topic.metadata_title')}">
-    <span class="topic-location">{$_('topic.category_location')} <a href="/f/interaction"
-        class="p-category">{$_('forum.name.interaction')}</a>.</span>
-    <span class="topic-ttl"><a class="u-url u-uid" title="{$_('topic.permalink_title')}" href="/t/2a3fc567af8c897ca6f55fb5fj">{$_('topic.remaining_time', { values: { remaining: $_('time.days', { values: { count: 3 } }) } })}</a>.</span>
-  </aside>
-  <aside class="topic-tags" title="{$_('topic.tags_title')}">
-    {$_('topic.tags_location')}
-    <a href="/g/question" class="p-category">question<span class="tag-weight">(5)</span></a>
-    <a href="/g/meta" class="p-category">meta<span class="tag-weight">(34)</span></a>
-    <a href="/g/carrots" class="p-category">carrots<span class="tag-weight">(1)</span></a>
-    <a href="/g/tpbo" class="p-category">tpbo<span class="tag-weight">(2)</span></a>
-  </aside>
-  <aside class="post-meta" title="{$_('post.metadata_title', { values: { count: 1, total: 2 } })}">
-    <Glyph uuid="3cd8c84e18144a2da71f6bace9392abc" />
-    <span class="h-card">
-      {$_('post.author_credit')} <a href="/a/rbdr" class="p-nickname u-url">rbdr</a>.
-    </span>
-    <time role="presentation" class="dt-published" datetime="2018-08-14T03:32:10.929Z">
-      <a title="{$_('post.permalink_title')}" href="/p/a80c70ea0120387123097ce1907ff">
-        2018-08-14 03:32:10
-      </a>
-    </time>
-  </aside>
-  <article class="e-content" title="{$_('post.title', { values: { count: 1, total: 2, author: 'rbdr' } })}">
-    <p>This is a main topic in the forum. Does that abstraction still even make sense?</p>
-    <p>Is this really it??</p>
-    <p>This might all be fake but at least the links look purple when visited</p>
-  </article>
-  <hr/>
-  <aside class="post-meta" title="{$_('post.metadata_title', { values: { count: 2, total: 2 } })}">
-    <Glyph uuid="b33f0339f7d64d1ca27f1c0aefb7d753" />
-    <span class="h-card">
-      {$_('post.author_credit')} <a href="/a/time4carrots" class="p-nickname u-url">time4carrots</a>.
-    </span>
-    <time role="presentation" class="dt-published" datetime="2018-08-15T04:10:00.929Z">
-      <a href="/p/da9910f3febde91948000ce1535ea">
-        2018-08-15 04:10:00
-      </a>
-    </time>
-  </aside>
-  <article class="e-content" title="{$_('post.title', { values: { count: 1, total: 2, author: 'time4carrots' } })}">
-    <p>It's just how it is...</p>
-  </article>
-  <hr/>
-</div>
+  $: store = getTopic(id);
+  $: topic = $store.data;
+  $: remainingTime = topic ? (topic.updated_at + topic.ttl) - Date.now() : 0;
+  $: remaining = readableTime(remainingTime);
+</script>
 
-<style>
-  .post-meta * {
-    vertical-align: top;
-  }
-</style>
+{#if $store.loading}
+  <Loader />
+{/if}
+{#if $store.error}
+  <ErrorBlock message={$_('topic.error.unavailable')} />
+{/if}
+{#if topic}
+  <div class="h-entry" title="{$_('topic.title')}">
+    <h1 class="p-name">{topic.title}</h1>
+    <aside class="topic-meta" title="{$_('topic.metadata_title')}">
+      {#if topic.forum}
+      <span class="topic-location">{$_('topic.category_location')} <a href="/f/{topic.forum.id}"
+          class="p-category">{topic.forum.glyph} {$_(topic.forum.label)}</a>.</span>
+      {/if}
+      <span class="topic-ttl"><a class="u-url u-uid" title="{$_('topic.permalink_title')}" href="/t/{topic.id}">({$_('topic.remaining_time', { values: { remaining: $_(remaining.label, { values: { count: remaining.count } }) } })})</a>.</span>
+    </aside>
+    {#if topic.tags.length > 0}
+      <aside class="topic-tags" title="{$_('topic.tags_title')}">
+        {$_('topic.tags_location')}
+        {#each topic.tags as tag}
+          <a href="/g/{tag.id}" class="p-category">{tag.id}<span class="tag-weight">({tag.weight})</span></a>{' '}
+        {/each}
+      </aside>
+    {/if}
+    {#each topic.posts as post, index}
+      <PostContent post={post} index={index} count={topic.posts.length} />
+    {/each}
+  </div>
+{/if}
index df7da3ce52d07761b4da9978a23d959e9f2097a3..7c881294e215a87ee7169c099c700cf77bab286b 100644 (file)
@@ -1,5 +1,5 @@
 <script>
-  import InvalidRoute from '$components/invalid_route/invalid_route.svelte';
+  import InvalidRoute from '$/components/invalid_route/invalid_route.svelte';
 </script>
 
 <InvalidRoute />
index 80cc29e61159466f06e402593a91a91740bfb246..b296b73051e5429767aada8c434153850f02c95a 100644 (file)
@@ -1,14 +1,14 @@
 <script>
-  import '$config/i18n';
+  import '$/config/i18n';
   import { isLoading } from 'svelte-i18n';
-  import ForumList from '$components/forum_list/forum_list.svelte';
-  import Header from '$components/header/header.svelte';
-  import Footer from '$components/footer/footer.svelte';
+  import ForumList from '$/components/forum_list/forum_list.svelte';
+  import Header from '$/components/header/header.svelte';
+  import Loader from '$/components/loader/loader.svelte';
+  import Footer from '$/components/footer/footer.svelte';
 </script>
 
 {#if $isLoading}
-  <h1>Loading.</h1>
-  <p>Please wait.</p>
+  <Loader />
 {:else}
   <Header />
   <main>
index 9e6f1843b10ff46d1b6eb0d246103d124b133fdc..f9bd858226b5455387883a4ea653a9d1f34824ce 100644 (file)
@@ -1,5 +1,5 @@
 <script>
-  import Author from '$components/author/author.svelte';
+  import Author from '$/components/author/author.svelte';
 </script>
 
 <Author/>
index 025169422afb88629a27ef44b002b289059834fa..473a58dea2ee80aa9b8213236b36082697cd8eb7 100644 (file)
@@ -1,5 +1,5 @@
 <script>
-  import Forum from '$components/forum/forum.svelte';
+  import Forum from '$/components/forum/forum.svelte';
   export let id;
 </script>
 
index 04fda925609f19f108faa66c8ad1973a7ab09d36..754f129a757f050b33285183bdc186b69166420a 100644 (file)
@@ -1,6 +1,6 @@
 <script>
+  import Tag from '$/components/tag/tag.svelte';
   export let id;
 </script>
 
-<h1>Tag Index.</h1>
-<p>This component lists topics for tag with id: {id}</p>
+<Tag id={id}/>
index 7000137e92680cc33cf695cc41cba28912d95acc..b7167727bbea425fd6783b5c0ee0a33fc1f3401f 100644 (file)
@@ -1,6 +1,8 @@
 <script>
   import { _ } from 'svelte-i18n';
+  import Loader from '$/components/loader/loader.svelte';
 </script>
 
+<Loader />
 <h1>{$_('home.title')}</h1>
 <p>{$_('home.content')}</p>
index 9caab6ffc26cb691c092f19ac4d15f109c985b8b..3504ceaa59c4998706248825872e90b8f6291414 100644 (file)
@@ -1,5 +1,6 @@
 <script>
-  import Post from '$components/post/post.svelte';
+  import Post from '$/components/post/post.svelte';
+  export let id;
 </script>
 
-<Post/>
+<Post id={id}/>
index 3fd9560153b6a5822e4908c40165a2320969d184..e13fd047f7af41b7dcd302c12eebb281df51bae0 100644 (file)
@@ -1,5 +1,6 @@
 <script>
-  import Topic from '$components/topic/topic.svelte';
+  import Topic from '$/components/topic/topic.svelte';
+  export let id;
 </script>
 
-<Topic/>
+<Topic id={id}/>
index e2deecd5f9c6a436f853634292dbc89fc5b6faa6..0ac244353c12a4ac6b6d25207a03bb38d13ad48a 100644 (file)
@@ -1,6 +1,6 @@
 import { ApolloError } from '@apollo/client/core';
 import { readable } from 'svelte/store';
-import { client } from '$config/apollo';
+import { client } from '$/config/apollo';
 
 /*
  * This is a generic store for use with apollo
index 110da5792d749de66192166268bd047f64d6855a..a4a66a55b723a8aaac73f20980dbd08985f21e4e 100644 (file)
@@ -1,4 +1,4 @@
 import { store } from './apollo';
-import { GET_FORUM } from '$data/queries';
+import { GET_FORUM } from '$/data/queries';
 
 export const getForum = (id) => store({ key: 'forum', query: GET_FORUM, variables: { id } });
index 5cce7ba60f836584a8ecc1316c08626767a14229..583b0d35b1cac445825ce1c6c7fe8a31d8b52ab8 100644 (file)
@@ -1,4 +1,4 @@
 import { store } from './apollo';
-import { GET_FORUMS } from '$data/queries';
+import { GET_FORUMS } from '$/data/queries';
 
 export const forums = store({ key: 'forums', query: GET_FORUMS, initialValue: [] });
index ed19cd6dc20d11904f0e93682e043ae831d84f78..0cbf1d5e44cfdae14589870eb844190a8baeca72 100644 (file)
@@ -1,4 +1,4 @@
 import { store } from './apollo';
-import { GET_POST } from '$data/queries';
+import { GET_POST } from '$/data/queries';
 
 export const getPost = (id) => store({ key: 'post', query: GET_POST, variables: { id } });
index 742db51125b410d9e4f8264c90f919f8f89336b8..d74b7194277ad06d5b73f5b2ccc73c05408ea185 100644 (file)
@@ -1,4 +1,4 @@
 import { store } from './apollo';
-import { GET_TAG } from '$data/queries';
+import { GET_TAG } from '$/data/queries';
 
 export const getTag = (id) => store({ key: 'tag', query: GET_TAG, variables: { id } });
index 3225a8314e54752a3cea011de34e56b3af9bcefc..c90f1a3b9a437823105fd347a8ac1bea7f5fcf86 100644 (file)
@@ -1,4 +1,4 @@
 import { store } from './apollo';
-import { GET_TOPIC } from '$data/queries';
+import { GET_TOPIC } from '$/data/queries';
 
 export const getTopic = (id) => store({ key: 'topic', query: GET_TOPIC, variables: { id } });