Skip to content

Commit

Permalink
fix(front): Lint and format
Browse files Browse the repository at this point in the history
  • Loading branch information
RezaRahemtola committed Jul 3, 2024
1 parent 31d0f4b commit a611b49
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 85 deletions.
1 change: 1 addition & 0 deletions contract/r/gnovox/errors.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import "errors"
var (
ErrUserExist = errors.New("user already exist")
ErrUserNotFound = errors.New("user not found")
ErrPostNotFound = errors.New("post not found")
)
21 changes: 21 additions & 0 deletions contract/r/gnovox/gnovox.gno
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ func NewPost(slug, title, body string) {
checkErr(err)
}

func GetPost(userAddress std.Address, slug string) string {
uValue, uFound := users.Get(userAddress.String());

if uFound == false {
panic(ErrUserNotFound)
}
u := uValue.(*gnovox.User)

pValue, pFound := u.Posts.Get(slug)
if pFound == false {
panic(ErrPostNotFound)
}
p := pValue.(*gnovox.Post)

jsonResponse := p.Json()
b, err := json.Marshal(jsonResponse)
checkErr(err)

return string(b)
}

func GetUsers() string {
jsonResponse := json.ArrayNode("", []*json.Node{})

Expand Down
162 changes: 78 additions & 84 deletions front/src/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,118 +8,112 @@

// This file is auto-generated by TanStack Router

import { createFileRoute } from '@tanstack/react-router'
import { createFileRoute } from "@tanstack/react-router";

// Import Routes

import { Route as rootRoute } from './routes/__root'
import { Route as rootRoute } from "./routes/__root";

// Create Virtual Routes

const WriteLazyImport = createFileRoute('/write')()
const SignupLazyImport = createFileRoute('/signup')()
const SettingsLazyImport = createFileRoute('/settings')()
const IndexLazyImport = createFileRoute('/')()
const UserUsernameLazyImport = createFileRoute('/user/$username')()
const UserUsernamePostSlugLazyImport = createFileRoute(
'/user/$username/$postSlug',
)()
const WriteLazyImport = createFileRoute("/write")();
const SignupLazyImport = createFileRoute("/signup")();
const SettingsLazyImport = createFileRoute("/settings")();
const IndexLazyImport = createFileRoute("/")();
const UserUsernameLazyImport = createFileRoute("/user/$username")();
const UserUsernamePostSlugLazyImport = createFileRoute("/user/$username/$postSlug")();

// Create/Update Routes

const WriteLazyRoute = WriteLazyImport.update({
path: '/write',
getParentRoute: () => rootRoute,
} as any).lazy(() => import('./routes/write.lazy').then((d) => d.Route))
path: "/write",
getParentRoute: () => rootRoute,
} as any).lazy(() => import("./routes/write.lazy").then((d) => d.Route));

const SignupLazyRoute = SignupLazyImport.update({
path: '/signup',
getParentRoute: () => rootRoute,
} as any).lazy(() => import('./routes/signup.lazy').then((d) => d.Route))
path: "/signup",
getParentRoute: () => rootRoute,
} as any).lazy(() => import("./routes/signup.lazy").then((d) => d.Route));

const SettingsLazyRoute = SettingsLazyImport.update({
path: '/settings',
getParentRoute: () => rootRoute,
} as any).lazy(() => import('./routes/settings.lazy').then((d) => d.Route))
path: "/settings",
getParentRoute: () => rootRoute,
} as any).lazy(() => import("./routes/settings.lazy").then((d) => d.Route));

const IndexLazyRoute = IndexLazyImport.update({
path: '/',
getParentRoute: () => rootRoute,
} as any).lazy(() => import('./routes/index.lazy').then((d) => d.Route))
path: "/",
getParentRoute: () => rootRoute,
} as any).lazy(() => import("./routes/index.lazy").then((d) => d.Route));

const UserUsernameLazyRoute = UserUsernameLazyImport.update({
path: '/user/$username',
getParentRoute: () => rootRoute,
} as any).lazy(() =>
import('./routes/user/$username.lazy').then((d) => d.Route),
)
path: "/user/$username",
getParentRoute: () => rootRoute,
} as any).lazy(() => import("./routes/user/$username.lazy").then((d) => d.Route));

const UserUsernamePostSlugLazyRoute = UserUsernamePostSlugLazyImport.update({
path: '/user/$username/$postSlug',
getParentRoute: () => rootRoute,
} as any).lazy(() =>
import('./routes/user_.$username.$postSlug.lazy').then((d) => d.Route),
)
path: "/user/$username/$postSlug",
getParentRoute: () => rootRoute,
} as any).lazy(() => import("./routes/user_.$username.$postSlug.lazy").then((d) => d.Route));

// Populate the FileRoutesByPath interface

declare module '@tanstack/react-router' {
interface FileRoutesByPath {
'/': {
id: '/'
path: '/'
fullPath: '/'
preLoaderRoute: typeof IndexLazyImport
parentRoute: typeof rootRoute
}
'/settings': {
id: '/settings'
path: '/settings'
fullPath: '/settings'
preLoaderRoute: typeof SettingsLazyImport
parentRoute: typeof rootRoute
}
'/signup': {
id: '/signup'
path: '/signup'
fullPath: '/signup'
preLoaderRoute: typeof SignupLazyImport
parentRoute: typeof rootRoute
}
'/write': {
id: '/write'
path: '/write'
fullPath: '/write'
preLoaderRoute: typeof WriteLazyImport
parentRoute: typeof rootRoute
}
'/user/$username': {
id: '/user/$username'
path: '/user/$username'
fullPath: '/user/$username'
preLoaderRoute: typeof UserUsernameLazyImport
parentRoute: typeof rootRoute
}
'/user/$username/$postSlug': {
id: '/user/$username/$postSlug'
path: '/user/$username/$postSlug'
fullPath: '/user/$username/$postSlug'
preLoaderRoute: typeof UserUsernamePostSlugLazyImport
parentRoute: typeof rootRoute
}
}
declare module "@tanstack/react-router" {
interface FileRoutesByPath {
"/": {
id: "/";
path: "/";
fullPath: "/";
preLoaderRoute: typeof IndexLazyImport;
parentRoute: typeof rootRoute;
};
"/settings": {
id: "/settings";
path: "/settings";
fullPath: "/settings";
preLoaderRoute: typeof SettingsLazyImport;
parentRoute: typeof rootRoute;
};
"/signup": {
id: "/signup";
path: "/signup";
fullPath: "/signup";
preLoaderRoute: typeof SignupLazyImport;
parentRoute: typeof rootRoute;
};
"/write": {
id: "/write";
path: "/write";
fullPath: "/write";
preLoaderRoute: typeof WriteLazyImport;
parentRoute: typeof rootRoute;
};
"/user/$username": {
id: "/user/$username";
path: "/user/$username";
fullPath: "/user/$username";
preLoaderRoute: typeof UserUsernameLazyImport;
parentRoute: typeof rootRoute;
};
"/user/$username/$postSlug": {
id: "/user/$username/$postSlug";
path: "/user/$username/$postSlug";
fullPath: "/user/$username/$postSlug";
preLoaderRoute: typeof UserUsernamePostSlugLazyImport;
parentRoute: typeof rootRoute;
};
}
}

// Create and export the route tree

export const routeTree = rootRoute.addChildren({
IndexLazyRoute,
SettingsLazyRoute,
SignupLazyRoute,
WriteLazyRoute,
UserUsernameLazyRoute,
UserUsernamePostSlugLazyRoute,
})
IndexLazyRoute,
SettingsLazyRoute,
SignupLazyRoute,
WriteLazyRoute,
UserUsernameLazyRoute,
UserUsernamePostSlugLazyRoute,
});

/* prettier-ignore-end */

Expand Down
71 changes: 70 additions & 1 deletion front/src/routes/user_.$username.$postSlug.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,74 @@
import { createLazyFileRoute } from "@tanstack/react-router";
import { useEffect, useState } from "react";
import { constants } from "@/constants.ts";
import { parseGnoEvaluateJsonResponse } from "@/utils";
import { useProviderStore } from "@/stores/provider.ts";
import { useToast } from "@/components/ui/use-toast.ts";
import { Post, postSchema } from "@/types/post.ts";
import {
diffSourcePlugin,
headingsPlugin,
linkPlugin,
listsPlugin,
markdownShortcutPlugin,
MDXEditor,
quotePlugin,
tablePlugin,
thematicBreakPlugin,
} from "@mdxeditor/editor";
import "@mdxeditor/editor/style.css";

const PostPage = () => {
const { provider } = useProviderStore();
const { toast } = useToast();
const { username, postSlug } = Route.useParams();
const [pagePost, setPagePost] = useState<Post | null>(null);

useEffect(() => {
(async () => {
try {
// TODO: Get by username instead
const response = await provider.evaluateExpression(
constants.realmPath,
`GetPost("${username}", "${postSlug}")`,
);
const jsonResponse = parseGnoEvaluateJsonResponse(response);
const parsedResponse = postSchema.parse(jsonResponse);
setPagePost(parsedResponse);
} catch (error) {
// TODO: redirect to 404
toast({
title: "Post not found",
variant: "destructive",
});
}
})();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

if (pagePost === null) {
return "Post not found";
}
return (
<MDXEditor
readOnly
className="mx-5"
contentEditableClassName="prose"
markdown={pagePost.body.replace(/\\n|\\r\\n|\\n\\r|\\r/g, "\n")}
plugins={[
headingsPlugin(),
quotePlugin(),
listsPlugin(),
thematicBreakPlugin(),
linkPlugin(),
tablePlugin(),
markdownShortcutPlugin(),
diffSourcePlugin(),
]}
/>
);
};

export const Route = createLazyFileRoute("/user/$username/$postSlug")({
component: () => <div>Hello /user/$username/$postSlug!</div>,
component: PostPage,
});

0 comments on commit a611b49

Please sign in to comment.