Skip to content

Commit

Permalink
Update [id].tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
moyomogi committed Dec 27, 2022
1 parent 3c58d6b commit 816038d
Show file tree
Hide file tree
Showing 19 changed files with 391 additions and 405 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules
target
venv

*.css
*.py
Cargo.lock
memo.md
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
},
"dependencies": {
"@tauri-apps/api": "^1.0.2",
"bulma": "^0.9.4",
"next": "^12.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.7.1",
"web-vitals": "^3.0.4"
},
"devDependencies": {
"@tauri-apps/cli": "^1.0.5",
"@types/node": "^18.7.11",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"autoprefixer": "^10.4.8",
"postcss": "^8.4.16",
"tailwindcss": "^3.1.8",
"typescript": "^4.7.4"
}
}
6 changes: 0 additions & 6 deletions postcss.config.js

This file was deleted.

3 changes: 3 additions & 0 deletions src-tauri/src/domain/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ pub struct ArticleOwner {

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ArticleTag {
id: String,
name: String,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ArticleComment {
id: String,
// created_at: DateTime<FixedOffset>,
// updated_at: DateTime<FixedOffset>,
created_at: String,
Expand All @@ -67,6 +69,7 @@ pub struct ArticleComment {

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ArticleImageUrl {
id: String,
image_url: String,
}

Expand Down
5 changes: 0 additions & 5 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ use article::*;
// let id = article.id;
// format!("Hello, {}! You've been greeted from Rust!", name)
// }
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}

// async fn manage_articles(app: &mut App) -> Result<()> {
// let articles = article::fetch_articles().await?;
Expand All @@ -65,7 +61,6 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
let articles = handle.await.expect("failed to handle articles");
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
greet,
get_articles,
insert_article,
update_article,
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"icons/128x128@2x.png",
"icons/icon.ico"
],
"identifier": "com.tauri.dev",
"identifier": "random-launcher",
"longDescription": "",
"macOS": {
"entitlements": null,
Expand Down
21 changes: 0 additions & 21 deletions src/App.css

This file was deleted.

21 changes: 0 additions & 21 deletions src/assets/next.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/assets/react.svg

This file was deleted.

6 changes: 0 additions & 6 deletions src/assets/tauri.svg

This file was deleted.

3 changes: 3 additions & 0 deletions src/domain/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ export interface ArticleOwner {
};

export interface ArticleTag {
id: string;
name: string;
};

export interface ArticleComment {
id: string;
created_at: string;
updated_at: string;
body: string;
rate: number;
};

export interface ArticleImageUrl {
id: string;
image_url: string;
};
3 changes: 1 addition & 2 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from "react";
import type { AppProps } from "next/app";

import "../style.css";
import "../App.css";
import "bulma/css/bulma.css";
import reportWebVitals from "../utils/reportWebVitals";

// https://bit.ly/CRA-vitals
Expand Down
225 changes: 225 additions & 0 deletions src/pages/articles/[id].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
import { useEffect, useState } from "react";
// import { invoke } from "@tauri-apps/api/tauri";
// https://react-icons.github.io/react-icons/icons?name=fa
import {
FaAngleDoubleLeft,
FaPlay,
FaUser,
FaShapes,
FaTv,
FaHandPaper,
FaGamepad,
FaKeyboard,
FaStarHalfAlt,
FaRegSmileBeam,
} from "react-icons/fa";

import { Article } from "../../domain/models";
import { isNullOrUndefined } from "../../utils/utils";
import { getArticles, getAllPaths } from "../../repository/fly/fly";

export default function App({ id }: { id: string }) {
const [article, setArticle] = useState<Article>(null);
useEffect(
() => {
try {
getArticles().then((articles: Map<string, Article>) => {
setArticle(articles[id]);
// console.log("(useEffect) articles[id]:", articles[id]);
});
} catch (e) {
console.log("failed to run getArticles", e);
}
},
// マウント時のみ useEffect する
[]
);
return (
<div className="container">
{isNullOrUndefined(article) ? (
"Loading..."
) : article.public ? (
<>
{/* 戻る */}
<div className="content mt-4">
<div className="columns">
<div className="column is-one-fifth mx-1">
<a href="/" className="button is-fullwidth is-link is-outlined">
<span className="icon m-0">
<FaAngleDoubleLeft />
</span>
戻る
</a>
</div>
</div>
</div>
{/* article */}
<div className="box m-2">
<div className="content p-2 columns">
<div className="column is-7">
<h1 className="title">{article.title}</h1>
<div className="is-size-5">
作成: {article.created_at}、更新: {article.updated_at}
</div>
</div>
<div className="column is-5">
<a className="button is-fullwidth mt-4 is-primary is-outlined is-large">
<span className="icon m-0">
<FaPlay />
</span>
プレイ
</a>
</div>
</div>
<div className="content tile is-ancestor">
<div className="tile is-parent is-7 p-2">
<div className="tile is-child">
<div
className="image is-5by3"
style={{ border: "1px solid" }}
>
<img
src={article.article_image_urls[0].image_url}
style={{
width: "auto",
height: "auto",
maxWidth: "100%",
maxHeight: "100%",
margin: "auto",
}}
/>
</div>
</div>
</div>
<div className="tile is-parent is-5 p-2 is-vertical">
<div className="tile is-child">
<div className="is-size-5 pt-2 px-2">
<div>
<span className="icon m-0 is-large">
<FaUser />
</span>
{article.article_owners
.map((o) => o.user.name)
.join("、")}
</div>
<div>
<span className="icon m-0 is-large">
<FaShapes />
</span>
{article.article_tags.map((t) => (
<span key={t.id}>
<span className="icon m-0">
<FaTv />
</span>
{t.name}
</span>
))}
</div>
<div>
<span className="icon m-0 is-large">
<FaHandPaper />
</span>
<span className="icon m-0">
<FaGamepad />
</span>
コントローラ/
<span className="icon m-0">
<FaKeyboard />
</span>
キーボード
</div>
</div>
</div>
<div
className="tile is-child py-1"
style={{ display: "grid", alignItems: "flex-end" }}
>
<h2 className="is-size-4">ギャラリー</h2>
<div className="columns mt-2 is-mobile">
{article.article_image_urls.map((aiu) => (
<div key={aiu.id} className="column is-4">
<div className="image is-5by3">
<img src={aiu.image_url} width="200" />
</div>
</div>
))}
</div>
</div>
</div>
</div>
<hr style={{ marginBottom: "8px", marginTop: "8px" }} />
<div className="content columns">
<div className="column is-7">
<h2 className="is-size-4">概要</h2>
<div className="p-2">{article.body}</div>
</div>
<div className="column is-5">
<div className="columns">
<div className="column is-5">
<h2 className="is-size-4">評価</h2>
</div>
<div className="column is-7">
<div className="button is-link is-outlined is-fullwidth">
<span className="icon m-0">
<FaStarHalfAlt />
</span>
評価する
</div>
</div>
</div>
<div className="is-size-1 has-text-centered m-2">
<span className="icon">
<FaRegSmileBeam />
</span>
Good
</div>
</div>
</div>
</div>

{/* <h1>{article.title}</h1>
<i>{article.created_at}</i>
<i>{article.updated_at}</i>
{article.article_tags.map((t) => (
<p>{t.name}</p>
))}
{article.article_owners.map((o) => (
<p>{o.user.name}</p>
))} */}
{/* {article.article_image_urls.map((aiu) => (
<img src={aiu.image_url} width="200" />
))} */}
<p>{article.article_game_content.exec_path}</p>
<p>{article.article_game_content.zip_url}</p>
{article.article_comments.map((ac) => {
<div key={ac.id}>
<p>{ac.rate}</p>
<i>{ac.created_at}</i>
<i>{ac.updated_at}</i>
<p>{ac.body}</p>
</div>;
})}
</>
) : (
"401 Unauthorized"
)}
</div>
);
}

// https://reffect.co.jp/react/next-js
export async function getServerSidePaths() {
const paths = await getAllPaths();
return {
paths,
fallback: "blocking",
};
}

export async function getServerSideProps({ params: { id } }) {
return {
props: {
id,
},
};
}
Loading

0 comments on commit 816038d

Please # to comment.