]> git.r.bdr.sh - rbdr/forum/commitdiff
Add internationalized error block
authorBen Beltran <redacted>
Sat, 20 Jun 2020 12:58:26 +0000 (14:58 +0200)
committerBen Beltran <redacted>
Sat, 20 Jun 2020 12:58:26 +0000 (14:58 +0200)
app/components/error_block/error_block.svelte [new file with mode: 0644]
app/components/forum_list/forum_list.svelte
app/components/topic_index/topic_index.svelte
app/config/i18n.js [new file with mode: 0644]
app/config/translations/en.json [new file with mode: 0644]
app/forum.svelte
app/stores/forums.js

diff --git a/app/components/error_block/error_block.svelte b/app/components/error_block/error_block.svelte
new file mode 100644 (file)
index 0000000..d649fb4
--- /dev/null
@@ -0,0 +1,31 @@
+<script>
+  import { _ } from 'svelte-i18n';
+  export let message = $_('error.generic.message');
+</script>
+
+<div>
+  <h2>{$_('error.generic.title')}</h2>
+  <p>{message}</p>
+</div>
+
+<style>
+  div {
+    background: repeating-linear-gradient( -45deg, red, red 5px, black 5px, black 10px );
+    border: 5px solid red;
+    color: yellow;
+    font-family: 'ヒラギノ角ゴ ProN' , 'Hiragino Kaku Gothic ProN' , '游ゴシック' , '游ゴシック体' , YuGothic , 'Yu Gothic' , 'メイリオ' , Meiryo , 'MS ゴシック' , 'MS Gothic' , HiraKakuProN-W3 , 'TakaoExゴシック' , TakaoExGothic , 'MotoyaLCedar' , 'Droid Sans Japanese' , sans-serif;
+    margin: 0 10px 0 0;
+    padding: 100px 5px;
+    text-align: center;
+  }
+
+  h2, p {
+    background-color: black;
+    font-size: 1em;
+  }
+
+  h2 {
+    text-transform: uppercase;
+  }
+</style>
+
index f77c79aac9ca9ebd3bea73f391d8420578de8aa0..c218bac81b214473ea92b706e311a77b565ab1d8 100644 (file)
@@ -1,8 +1,13 @@
 <script>
+  import { _ } from 'svelte-i18n';
   import { forums } from '../../stores/forums.js';
+  import ErrorBlock from '../error_block/error_block.svelte';
 </script>
 
 <nav title="List of Forums">
+  {#if !$forums.length}
+    <ErrorBlock message={$_('forum_list.error.unavailable')} />
+  {/if}
   <ul>
     {#each $forums as forum}
       <li>
index ea748a691fb51f7f573006d406213a5423ff1244..3de83bb5d1323647c41026bbc2c21a0e285c1ef8 100644 (file)
@@ -1,6 +1,8 @@
 <script>
   export let params;
+  import ErrorBlock from '../error_block/error_block.svelte';
 </script>
 
+<ErrorBlock />
 <h1>Topic Index.</h1>
 <p>This component lists topics for category or tag with id: {params.id}</p>
diff --git a/app/config/i18n.js b/app/config/i18n.js
new file mode 100644 (file)
index 0000000..e00adb5
--- /dev/null
@@ -0,0 +1,10 @@
+import { addMessages, getLocaleFromNavigator, init } from 'svelte-i18n';
+
+import en from './translations/en.json';
+
+addMessages('en', en);
+
+init({
+  fallbackLocale: 'en',
+  initialLocale: getLocaleFromNavigator()
+});
diff --git a/app/config/translations/en.json b/app/config/translations/en.json
new file mode 100644 (file)
index 0000000..935f4fe
--- /dev/null
@@ -0,0 +1,13 @@
+{
+  "error": {
+    "generic": {
+      "title": "Error!",
+      "message": "Unknown error has occurred. Panic!"
+    }
+  },
+  "forum_list": {
+    "error": {
+      "unavailable": "Forum list unavailable."
+    }
+  }
+}
index 85c6d1249773bb49da10fc4b98992801a9acf179..d83438d9766056c9e893100735dccc2331a0edd0 100644 (file)
@@ -1,6 +1,12 @@
 <script>
   import LightRouter from 'lightrouter';
 
+  // Initialize localization
+
+  import './config/i18n';
+
+  // Global components
+
   import ForumList from './components/forum_list/forum_list.svelte';
   import Header from './components/header/header.svelte';
 
index 5c7c6e69368eac18f93ebf6a080c9a95e4f6f18d..e82616369b5431aa797e897a80e8edbaa1d6d14e 100644 (file)
@@ -15,11 +15,8 @@ const internals = {
 
   handleChangeFeed(data) {
 
-    console.log(data);
-
     // No old value == add
     if (!data.old_val) {
-      console.log('Adding new data');
       return internals.forums.push(data.new_val);
     }
 
@@ -27,8 +24,6 @@ const internals = {
     const index = internals.forums.findIndex((element) => element.id === data.old_val.id);
 
     if (index > -1) {
-      console.log(`Found old data at index ${index}`);
-
       if (data.new_val) {
         return internals.forums.splice(index, 1, data.new_val || undefined);
       }