-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clipboard): allow user to change domain used when copying to cli…
…pboard
- Loading branch information
Showing
18 changed files
with
142 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,48 @@ | ||
import { Route } from "react-router-dom"; | ||
import classes from './app.module.scss'; | ||
import {MemoryRouter as Router} from "react-router-dom"; | ||
import classes from "./app.module.scss"; | ||
import { MemoryRouter as Router } from "react-router-dom"; | ||
import { ThemeProvider, createTheme } from "@mui/material"; | ||
import { Content, MainMenu } from './components'; | ||
import { Files, Links, Texts } from './pages'; | ||
import { Content, MainMenu } from "./components"; | ||
import { Files, Links, Texts } from "./pages"; | ||
import AppContext from "./app_context"; | ||
import { useEffect, useState } from "react"; | ||
import { App as ShortApp } from "./common/data.types"; | ||
import { appRepository } from "./repositories"; | ||
import { config } from "./core"; | ||
|
||
const theme = createTheme({ | ||
spacing: 16, | ||
spacing: 16, | ||
}); | ||
|
||
function App() { | ||
return <Router basename={process.env.PUBLIC_URL}> | ||
<ThemeProvider theme={theme}> | ||
<div className={classes.root}> | ||
<MainMenu /> | ||
<Content> | ||
<Route path="/" element={<Links />} /> | ||
<Route path="/texts" element={<Texts />} /> | ||
<Route path="/files" element={<Files />} /> | ||
</Content> | ||
</div> | ||
</ThemeProvider> | ||
</Router>; | ||
const [isLoading, setIsLoading] = useState(true); | ||
const [appContextValue, setAppContextValue] = useState<ShortApp>(); | ||
useEffect(() => { | ||
(async() => { | ||
const app = await appRepository.get() | ||
setAppContextValue(app); | ||
config.domain = app.domain; | ||
setIsLoading(false); | ||
})(); | ||
}, []); | ||
|
||
return ( | ||
<Router basename={process.env.PUBLIC_URL}> | ||
<ThemeProvider theme={theme}> | ||
<AppContext.Provider value={appContextValue}> | ||
<div className={classes.root}> | ||
{!isLoading ? <><MainMenu /> | ||
<Content> | ||
<Route path="/" element={<Links />} /> | ||
<Route path="/texts" element={<Texts />} /> | ||
<Route path="/files" element={<Files />} /> | ||
</Content> | ||
</> : null} | ||
</div> | ||
</AppContext.Provider> | ||
</ThemeProvider> | ||
</Router> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { createContext } from "react"; | ||
import { App as ShortApp } from "./common/data.types"; | ||
|
||
const LinksContext = createContext<ShortApp|undefined>(undefined); | ||
|
||
export default LinksContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { api, config } from "../core"; | ||
import { App as ShortApp } from "../common/data.types"; | ||
|
||
export default class AppRepository { | ||
static async get(): Promise<ShortApp> { | ||
const { data: apiStatus } = await api.getStatus(); | ||
const { data: apiConfig } = await api.getConfig(); | ||
|
||
return { ...apiStatus, ...apiConfig }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default as appRepository } from "./app_repository"; | ||
export { default as linksRepository } from "./links_repository"; | ||
export { default as textsRepository } from "./texts_repository"; | ||
export { default as filesRepository } from "./files_repository"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"shortpaste/core/config" | ||
) | ||
|
||
func ConfigList(w http.ResponseWriter, r *http.Request) { | ||
var list = map[string]interface{}{ | ||
"domain": config.GetDomain(), | ||
"version": config.AppVersion(), | ||
} | ||
body, _ := json.Marshal(list) | ||
w.Write(body) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package config | ||
|
||
import "os" | ||
|
||
func GetDomain() string { | ||
domain := os.Getenv("DOMAIN") | ||
return domain | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestGetDomain(t *testing.T) { | ||
os.Setenv("DOMAIN", "") | ||
|
||
domain := GetDomain() | ||
|
||
expectedDomain := "" | ||
|
||
if expectedDomain != domain { | ||
t.Fatalf("Expected base path %s, but got %s", expectedDomain, domain) | ||
} | ||
} |