🏗️(front) reorganise folder into features

After a quick discussion we decide to normalize the folder organization
into this one.
This commit is contained in:
Nathan Vasse
2025-02-25 16:25:57 +01:00
committed by NathanVss
parent 35e101a185
commit 4e3cd532fd
28 changed files with 43 additions and 54 deletions
@@ -1,6 +0,0 @@
export interface APIList<T> {
count: number;
next?: string | null;
previous?: string | null;
results: T[];
}
-14
View File
@@ -1,14 +0,0 @@
export const baseApiUrl = (apiVersion: string = '1.0') => {
const origin =
process.env.NEXT_PUBLIC_API_ORIGIN ||
(typeof window !== 'undefined' ? window.location.origin : '');
return `${origin}/api/v${apiVersion}/`;
};
export const signalingUrl = (padId: string) => {
const base =
process.env.NEXT_PUBLIC_SIGNALING_URL ||
(typeof window !== 'undefined' ? `wss://${window.location.host}/ws` : '');
return `${base}/${padId}`;
};
@@ -1,5 +1,5 @@
import { logout } from '@/core/auth/Auth';
import { baseApiUrl } from '@/core/conf';
import { logout } from "@/features/auth/Auth";
import { baseApiUrl } from "./utils";
/**
* Retrieves the CSRF token from the document's cookies.
@@ -8,9 +8,9 @@ import { baseApiUrl } from '@/core/conf';
*/
function getCSRFToken() {
return document.cookie
.split(';')
.filter((cookie) => cookie.trim().startsWith('csrftoken='))
.map((cookie) => cookie.split('=')[1])
.split(";")
.filter((cookie) => cookie.trim().startsWith("csrftoken="))
.map((cookie) => cookie.split("=")[1])
.pop();
}
@@ -21,18 +21,18 @@ export interface fetchAPIOptions {
export const fetchAPI = async (
input: string,
init?: RequestInit,
options?: fetchAPIOptions,
options?: fetchAPIOptions
) => {
const apiUrl = `${baseApiUrl('1.0')}${input}`;
const apiUrl = `${baseApiUrl("1.0")}${input}`;
const csrfToken = getCSRFToken();
const response = await fetch(apiUrl, {
...init,
credentials: 'include',
credentials: "include",
headers: {
...init?.headers,
'Content-Type': 'application/json',
...(csrfToken && { 'X-CSRFToken': csrfToken }),
"Content-Type": "application/json",
...(csrfToken && { "X-CSRFToken": csrfToken }),
},
});
@@ -16,3 +16,10 @@ export const errorCauses = async (response: Response, data?: unknown) => {
data,
};
};
export const baseApiUrl = (apiVersion: string = "1.0") => {
const origin =
process.env.NEXT_PUBLIC_API_ORIGIN ||
(typeof window !== "undefined" ? window.location.origin : "");
return `${origin}/api/v${apiVersion}/`;
};
@@ -1,8 +1,8 @@
import React, { PropsWithChildren, useEffect, useState } from "react";
import { fetchAPI } from "@/core/api/fetchApi";
import { User } from "@/core/auth/types";
import { baseApiUrl } from "@/core/conf";
import { fetchAPI } from "@/features/api/fetchApi";
import { User } from "@/features/auth/types";
import { baseApiUrl } from "../api/utils";
export const logout = () => {
window.location.replace(new URL("logout/", baseApiUrl()).href);
@@ -4,8 +4,8 @@ import { DummyDriver } from "../drivers/implementations/DummyDriver";
export const getConfig = () => {
// TODO: Later, be based on URL query params for instance.
return {
// driver: new DummyDriver(),
driver: new StandardDriver(),
driver: new DummyDriver(),
// driver: new StandardDriver(),
};
};
@@ -1,4 +1,4 @@
import { fetchAPI } from "@/core/api/fetchApi";
import { fetchAPI } from "@/features/api/fetchApi";
import { Driver } from "../Driver";
import { Item } from "../types";
@@ -1,5 +1,5 @@
import { ExplorerTree } from "@/components/explorer/ExplorerTree";
import { login, useAuth } from "@/core/auth/Auth";
import { login, useAuth } from "@/features/auth/Auth";
import { ExplorerTree } from "@/features/explorer/components/ExplorerTree";
export const ExplorerLayout = ({ children }: { children: React.ReactNode }) => {
const { user } = useAuth();
@@ -1,4 +1,4 @@
import { Auth, login, logout, useAuth } from "@/core/auth/Auth";
import { Auth, login, logout, useAuth } from "@/features/auth/Auth";
export const GlobalLayout = ({ children }: { children: React.ReactNode }) => {
return (
@@ -1,4 +1,4 @@
import { Auth } from "@/core/auth/Auth";
import { Auth } from "@/features/auth/Auth";
export const SdkLayout = ({ children }: { children: React.ReactNode }) => {
return <Auth>{children}</Auth>;
+1 -1
View File
@@ -5,7 +5,7 @@ import { CunninghamProvider } from "@openfun/cunningham-react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import "../styles/globals.scss";
import "./../i18n/initI18n";
import "../features/i18n/initI18n";
export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
getLayout?: (page: ReactElement) => ReactNode;
@@ -1,5 +1,5 @@
import { ExplorerLayout } from "@/components/layouts/explorer/ExplorerLayout";
import { GlobalLayout } from "@/components/layouts/global/GlobalLayout";
import { ExplorerLayout } from "@/features/layouts/components/explorer/ExplorerLayout";
import { GlobalLayout } from "@/features/layouts/components/global/GlobalLayout";
export default function ExplorerPage() {
return <div>explorer</div>;
@@ -1,6 +1,6 @@
import { Explorer } from "@/components/explorer/Explorer";
import { ExplorerLayout } from "@/components/layouts/explorer/ExplorerLayout";
import { GlobalLayout } from "@/components/layouts/global/GlobalLayout";
import { Explorer } from "@/features/explorer/components/Explorer";
import { ExplorerLayout } from "@/features/layouts/components/explorer/ExplorerLayout";
import { GlobalLayout } from "@/features/layouts/components/global/GlobalLayout";
import { useRouter } from "next/router";
export default function ItemPage() {
+1 -1
View File
@@ -1,4 +1,4 @@
import { GlobalLayout } from "@/components/layouts/global/GlobalLayout";
import { GlobalLayout } from "@/features/layouts/components/global/GlobalLayout";
import Head from "next/head";
import Link from "next/link";
import { useTranslation } from "next-i18next";
@@ -1,7 +1,5 @@
import { Explorer } from "@/components/explorer/Explorer";
import { ExplorerLayout } from "@/components/layouts/explorer/ExplorerLayout";
import { GlobalLayout } from "@/components/layouts/global/GlobalLayout";
import { SdkLayout } from "@/components/layouts/sdk/SdkLayout";
import { Explorer } from "@/features/explorer/components/Explorer";
import { SdkLayout } from "@/features/layouts/components/sdk/SdkLayout";
import { useRouter } from "next/router";
/**
@@ -1,8 +1,8 @@
@use "@lasuite/ui-kit/style";
@use "./cunningham-tokens.css";
@use "./../components/layouts/global/GlobalLayout.scss";
@use "./../components/layouts/explorer/ExplorerLayout.scss";
@use "./../components/explorer/Explorer.scss";
@use "./../features/layouts/components/global/GlobalLayout.scss";
@use "./../features/layouts/components/explorer/ExplorerLayout.scss";
@use "./../features/explorer/components/Explorer.scss";
body {
margin: 0;
+4
View File
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1