Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure project #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
jobs:
publish-docker-image:
name: Build & Publish Docker Image
runs-on: self-hosted
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
Expand Down
12 changes: 6 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Container } from "@mui/material";
import "./App.css";

import { AppwriteContextProvider } from "./contexts/appwrite";
import { AuthContextProvider } from "./contexts/auth";
import { Router } from "./routes";
import { AuthProvider } from "./providers/auth.provider";
import { AppwriteProvider } from "./providers/appwrite.provider";

export function App() {
return (
<>
<AppwriteContextProvider>
<AuthContextProvider>
<AppwriteProvider>
<AuthProvider>
<Container maxWidth="lg">
<Router />
</Container>
</AuthContextProvider>
</AppwriteContextProvider>
</AuthProvider>
</AppwriteProvider>
</>
);
}
10 changes: 10 additions & 0 deletions src/contexts/appwrite.context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Client } from "appwrite";
import { createContext } from "react";

export type AppwriteContextValue = {
client: Client;
};

export const AppwriteContext = createContext<AppwriteContextValue>(
{} as AppwriteContextValue,
);
13 changes: 13 additions & 0 deletions src/contexts/auth.context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createContext } from "react";
import { Models } from "appwrite";

export type AuthContextType = {
session?: Models.Session;
user?: Models.User<Models.Preferences>;
loggedIn: boolean;
login(email: string, password: string): Promise<void>;
logout(): Promise<void>;
register(email: string, password: string, name: string): Promise<void>;
};

export const AuthContext = createContext({} as AuthContextType);
2 changes: 1 addition & 1 deletion src/hooks/useAppwrite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext } from "react";
import { AppwriteContext } from "../contexts/appwrite";
import { AppwriteContext } from "../contexts/appwrite.context";

export function useAppwrite() {
return useContext(AppwriteContext);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useAuth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext } from "react";
import { AuthContext } from "../contexts/auth";
import { AuthContext } from "../contexts/auth.context";

export function useAuth() {
return useContext(AuthContext);
Expand Down
13 changes: 3 additions & 10 deletions src/contexts/appwrite.tsx → src/providers/appwrite.provider.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { Client } from "appwrite";
import { createContext, PropsWithChildren } from "react";

export type AppwriteContextValue = {
client: Client;
};

export const AppwriteContext = createContext<AppwriteContextValue>(
{} as AppwriteContextValue,
);
import { PropsWithChildren } from "react";
import { AppwriteContext } from "../contexts/appwrite.context";

type Props = PropsWithChildren;

export function AppwriteContextProvider({ children }: Props) {
export function AppwriteProvider({ children }: Props) {
const client = new Client();
client
.setEndpoint("https://cloud.appwrite.io/v1")
Expand Down
15 changes: 2 additions & 13 deletions src/contexts/auth.tsx → src/providers/auth.provider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
createContext,
PropsWithChildren,
useCallback,
useEffect,
Expand All @@ -8,19 +7,9 @@ import {
} from "react";
import { useAppwrite } from "../hooks/useAppwrite";
import { Account, AppwriteException, ID, Models } from "appwrite";
import { AuthContext } from "../contexts/auth.context";

export type AuthContextValue = {
session?: Models.Session;
user?: Models.User<Models.Preferences>;
loggedIn: boolean;
login(email: string, password: string): Promise<void>;
logout(): Promise<void>;
register(email: string, password: string, name: string): Promise<void>;
};

export const AuthContext = createContext({} as AuthContextValue);

export function AuthContextProvider({ children }: PropsWithChildren) {
export function AuthProvider({ children }: PropsWithChildren) {
const { client } = useAppwrite();
const account = useMemo(() => new Account(client), [client]);

Expand Down
2 changes: 1 addition & 1 deletion src/routes/error.tsx → src/routes/error.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type RouteError = {
statusText: string;
};

export default function ErrorPage() {
export function ErrorPage() {
const error = useRouteError() as RouteError;
console.error(error);

Expand Down
10 changes: 5 additions & 5 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {
RouteObject,
RouterProvider,
} from "react-router-dom";
import { Root } from "./root";
import { Root } from "./root.page";
import { useAuth } from "../hooks/useAuth";
import { Login } from "./login";
import ErrorPage from "./error";
import { Main } from "./main";
import { Register } from "./register";
import { Login } from "./login.page";
import { Main } from "./main.page";
import { Register } from "./register.page";
import { ErrorPage } from "./error.page";

export function Router() {
const { loggedIn } = useAuth();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading