From 8d615d0d6e4008a73f015d3bf94c5d21daa42400 Mon Sep 17 00:00:00 2001
From: Ren Amamiya <123083837+reyamir@users.noreply.github.com>
Date: Thu, 23 Feb 2023 09:50:31 +0700
Subject: [PATCH] small changes
---
next.config.js | 4 +++
src/components/note/single.tsx | 11 +++++++-
src/pages/feed/[id].tsx | 40 +++++++++++++++++++++++++++++
src/pages/index.tsx | 46 +++++++++++++++++++---------------
4 files changed, 80 insertions(+), 21 deletions(-)
create mode 100644 src/pages/feed/[id].tsx
diff --git a/next.config.js b/next.config.js
index be85000a..07e914ab 100644
--- a/next.config.js
+++ b/next.config.js
@@ -9,4 +9,8 @@ module.exports = removeImports({
typescript: {
ignoreBuildErrors: true,
},
+ webpack: (config) => {
+ config.experiments = { ...config.experiments, topLevelAwait: true };
+ return config;
+ },
});
diff --git a/src/components/note/single.tsx b/src/components/note/single.tsx
index 363914b6..d6fe2cfa 100644
--- a/src/components/note/single.tsx
+++ b/src/components/note/single.tsx
@@ -4,6 +4,7 @@ import Reply from '@components/note/atoms/reply';
import { User } from '@components/note/atoms/user';
import dynamic from 'next/dynamic';
+import { useRouter } from 'next/router';
import { memo } from 'react';
const DynamicContent = dynamic(() => import('@components/note/content'), {
@@ -17,8 +18,16 @@ const DynamicContent = dynamic(() => import('@components/note/content'), {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const Single = memo(function Single({ event }: { event: any }) {
+ const router = useRouter();
+
+ const openThread = (id: string) => {
+ router.push(`/feed/${id}`);
+ };
+
return (
-
+
openThread(event.id)}
+ className="flex h-min min-h-min w-full cursor-pointer select-text flex-col border-b border-zinc-800 py-4 px-6 hover:bg-zinc-800">
diff --git a/src/pages/feed/[id].tsx b/src/pages/feed/[id].tsx
new file mode 100644
index 00000000..0639784b
--- /dev/null
+++ b/src/pages/feed/[id].tsx
@@ -0,0 +1,40 @@
+/* eslint-disable @typescript-eslint/no-explicit-any */
+import BaseLayout from '@layouts/baseLayout';
+import UserLayout from '@layouts/userLayout';
+
+import { GetStaticPaths } from 'next';
+import { JSXElementConstructor, ReactElement, ReactFragment, ReactPortal } from 'react';
+
+export default function Page({ id }: { id: string }) {
+ return
{id}
;
+}
+
+export const getStaticPaths: GetStaticPaths = async () => {
+ return {
+ paths: [],
+ fallback: 'blocking',
+ };
+};
+
+export async function getStaticProps(context) {
+ const id = context.params.id;
+ return {
+ props: { id },
+ };
+}
+
+Page.getLayout = function getLayout(
+ page:
+ | string
+ | number
+ | boolean
+ | ReactElement
>
+ | ReactFragment
+ | ReactPortal
+) {
+ return (
+
+ {page}
+
+ );
+};
diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 818c9f05..8c8aef36 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -17,30 +17,36 @@ import {
} from 'react';
import Database from 'tauri-plugin-sql-api';
+const db = typeof window !== 'undefined' ? await Database.load('sqlite:lume.db') : null;
+
export default function Page() {
const [done, setDone] = useState(false);
const initDB = useCallback(async () => {
- const db = await Database.load('sqlite:lume.db');
- await db.execute(
- 'CREATE TABLE IF NOT EXISTS accounts (id INTEGER PRIMARY KEY, privkey TEXT NOT NULL, pubkey TEXT NOT NULL, npub TEXT, nsec TEXT, metadata JSON, UNIQUE(privkey));'
- );
- await db.execute(
- 'CREATE TABLE IF NOT EXISTS followings (id INTEGER PRIMARY KEY, pubkey TEXT NOT NULL, account TEXT, UNIQUE(pubkey));'
- );
- await db.execute(
- 'CREATE TABLE IF NOT EXISTS note_reactions (id INTEGER PRIMARY KEY, reaction_id TEXT NOT NULL, e TEXT, p TEXT, UNIQUE(reaction_id));'
- );
- await db.execute(
- 'CREATE TABLE IF NOT EXISTS note_replies (id INTEGER PRIMARY KEY, reply_id TEXT NOT NULL, e TEXT, p TEXT, UNIQUE(reply_id));'
- );
- await db.execute(
- 'CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, event_id TEXT, event JSON, UNIQUE(event_id));'
- );
- await db.execute(
- 'CREATE TABLE IF NOT EXISTS block_pubkeys (id INTEGER PRIMARY KEY, pubkey TEXT, UNIQUE(pubkey));'
- );
- await db.close();
+ if (db) {
+ await db.execute(
+ 'CREATE TABLE IF NOT EXISTS accounts (id INTEGER PRIMARY KEY, privkey TEXT NOT NULL, pubkey TEXT NOT NULL, npub TEXT, nsec TEXT, metadata JSON, UNIQUE(privkey));'
+ );
+ await db.execute(
+ 'CREATE TABLE IF NOT EXISTS followings (id INTEGER PRIMARY KEY, pubkey TEXT NOT NULL, account TEXT, UNIQUE(pubkey));'
+ );
+ await db.execute(
+ 'CREATE TABLE IF NOT EXISTS note_reactions (id INTEGER PRIMARY KEY, reaction_id TEXT NOT NULL, e TEXT, p TEXT, UNIQUE(reaction_id));'
+ );
+ await db.execute(
+ 'CREATE TABLE IF NOT EXISTS note_replies (id INTEGER PRIMARY KEY, reply_id TEXT NOT NULL, e TEXT, p TEXT, UNIQUE(reply_id));'
+ );
+ await db.execute(
+ 'CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, event_id TEXT, event JSON, UNIQUE(event_id));'
+ );
+ await db.execute(
+ 'CREATE TABLE IF NOT EXISTS cache_profiles (id INTEGER PRIMARY KEY, pubkey TEXT, metadata JSON, UNIQUE(pubkey));'
+ );
+ await db.execute(
+ 'CREATE TABLE IF NOT EXISTS block_pubkeys (id INTEGER PRIMARY KEY, pubkey TEXT, UNIQUE(pubkey));'
+ );
+ await db.close();
+ }
setDone(true);
}, []);