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

update #103

Open
wants to merge 2 commits into
base: master
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ eslint-config*
.nyc_output
.parcel-cache
coverage
test-project-dirs
1 change: 0 additions & 1 deletion .prettierrc

This file was deleted.

6 changes: 6 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var sharedPrettierConfig = require("eslint-config-turbocharge/prettier");

module.exports = {
...sharedPrettierConfig,
plugins: ["prettier-plugin-gherkin"],
};
5 changes: 0 additions & 5 deletions .proxyrc.json

This file was deleted.

3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"dbaeumer.vscode-eslint",
"orta.vscode-jest",
"esbenp.prettier-vscode",
"styled-components.vscode-styled-components"
"styled-components.vscode-styled-components",
"alexkrechik.cucumberautocomplete"
]
}
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"jest.autoRun": { "watch": false, "onSave": "test-file" }
"jest.autoRun": { "watch": false, "onSave": "test-file" },
"cucumberautocomplete.steps": ["./feature/**/*.steps.ts"],
"cucumberautocomplete.strictGherkinCompletion": true,
"cucumberautocomplete.smartSnippets": true,
"prettier.documentSelectors": ["*.{feature,features}"]
}
3 changes: 1 addition & 2 deletions client/app/ContextStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const ContextStore = createContext<Context>({
dispatch() {},
});

export const ContextStoreProvider: FC<{ children: ReactNode }> = ({
export const ContextStoreProvider: FC<{ readonly children: ReactNode }> = ({
children,
}) => {
const [state, dispatch] = useReducer(storeReducer, {
Expand Down Expand Up @@ -64,7 +64,6 @@ export const useProjectStore = (projectPath: string) => {

let id = 0;

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
export const useProjectsJobs = (projectPath: string) => {
const { dispatch } = useProjectStore(projectPath);

Expand Down
3 changes: 2 additions & 1 deletion client/app/store.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ export const storeReducer: Reducer<State, Action> = (state, action): State => {
};
}

default:
default: {
return state;
}
}
};
8 changes: 6 additions & 2 deletions client/base.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

body {
font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 16px;
Expand Down Expand Up @@ -54,10 +58,10 @@ th:last-child {
border-right: 0;
}

.npm-gui {
/* .npm-gui {
display: flex;
flex-direction: column;
max-height: 100vh;
min-height: 100vh;
overflow: hidden;
}
} */
4 changes: 2 additions & 2 deletions client/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { VFC } from 'react';
import type { FC } from 'react';
import { BrowserRouter as Router, Route } from 'react-router-dom';

import { ContextStoreProvider } from '../app/ContextStore';
import { Header } from './Header/Header';
import { Info } from './Info';
import { Project } from './Project/Project';

export const App: VFC = () => {
export const App: FC = () => {
return (
<ContextStoreProvider>
<Router>
Expand Down
53 changes: 10 additions & 43 deletions client/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { VFC } from 'react';
import type { FC } from 'react';
import React from 'react';
import styled from 'styled-components';

import { Button } from '../../ui/Button/Button';
import { Explorer } from './components/Explorer';
Expand All @@ -12,45 +11,13 @@ export interface HeaderButton {
icon: string;
}

const Nav = styled.nav`
background: #3e3f3a;
min-height: 35px;
max-height: 35px;
padding-left: 15px;
padding-right: 15px;
display: flex;
justify-content: space-between;
`;

const RightSection = styled.div`
display: flex;
align-items: center;
`;

const LeftSection = styled.div`
display: flex;
align-items: center;
`;

const Title = styled.h1`
color: #fff;
font-size: 1em;
font-weight: 400;
margin: 0 15px 0 0;
`;

const CloseButton = styled(Button)`
margin-right: 15px;
margin-left: -3px;
`;

export const Header: VFC = () => {
export const Header: FC = () => {
const { projectPathEncoded, projects, handleRemoveProject } = useHeader();

return (
<Nav>
<LeftSection>
<Title>npm-gui</Title>
<nav className="flex p-2 justify-between bg-neutral-700">
<div className="flex gap-2">
<h1 className="text-base text-white font-normal">npm-gui</h1>

<Button
icon="globe"
Expand All @@ -60,9 +27,9 @@ export const Header: VFC = () => {
>
Global
</Button>
</LeftSection>
</div>

<RightSection>
<div className="flex gap-2">
{projects
.filter(({ path }) => path !== 'global')
.map(({ path }) => (
Expand All @@ -75,7 +42,7 @@ export const Header: VFC = () => {
>
{window.atob(path).split('/').reverse()[0]}
</Button>
<CloseButton
<Button
icon="x"
onClick={(): void => handleRemoveProject(path)}
title="Remove"
Expand All @@ -85,7 +52,7 @@ export const Header: VFC = () => {
))}

<Explorer />
</RightSection>
</Nav>
</div>
</nav>
);
};
12 changes: 6 additions & 6 deletions client/components/Header/components/Explorer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { VFC } from 'react';
import type { FC } from 'react';

import { Button } from '../../../ui/Button/Button';
import {
Expand All @@ -11,7 +11,7 @@ import {
} from './ExplorerUi';
import { useExplorer } from './use-explorer';

export const Explorer: VFC = () => {
export const Explorer: FC = () => {
const {
ref,
onToggleIsOpen,
Expand Down Expand Up @@ -63,7 +63,7 @@ export const Explorer: VFC = () => {
?.filter((folderOrFile) => folderOrFile.name.includes(filter))
.map((folderOrFile) => (
<li key={folderOrFile.name}>
{folderOrFile.isDirectory && !folderOrFile.isProject && (
{folderOrFile.isDirectory && !folderOrFile.isProject ? (
<ExplorerButton
disabled={folderOrFile.name === 'node_modules' || isFetching}
isDirectory
Expand All @@ -76,9 +76,9 @@ export const Explorer: VFC = () => {
&nbsp;
{folderOrFile.name}/
</ExplorerButton>
)}
) : null}

{folderOrFile.isProject && (
{folderOrFile.isProject ? (
<ExplorerButton
disabled={isFetching}
isDirectory={false}
Expand All @@ -90,7 +90,7 @@ export const Explorer: VFC = () => {
&nbsp;
{folderOrFile.name}
</ExplorerButton>
)}
) : null}

{!folderOrFile.isDirectory && !folderOrFile.isProject && (
<ExplorerFile>
Expand Down
29 changes: 15 additions & 14 deletions client/components/Header/components/use-explorer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useQuery } from '@tanstack/react-query';
// import { useQuery } from '@tanstack/react-query';
import { useCallback, useEffect, useState } from 'react';
import { useHistory } from 'react-router-dom';

import type { ExplorerResponse } from '../../../../server/types/global.types';
import { fetchJSON } from '../../../service/utils';
import { trpc } from '../../../trpc';
// import type { ExplorerResponse } from '../../../../server/types/global.types';
// import { fetchJSON } from '../../../service/utils';
import { useClickOutsideRef } from '../../../ui/hooks/use-click-outside';
import { useToggle } from '../../../ui/hooks/use-toggle';

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/explicit-module-boundary-types
export const useExplorer = () => {
const { isOpen, onToggleIsOpen, onClose } = useToggle();
const [filter, setFilter] = useState('');
Expand All @@ -16,16 +16,17 @@ export const useExplorer = () => {

const ref = useClickOutsideRef(onClose);

const { data, isFetching } = useQuery(
[currentPath],
() => fetchJSON<ExplorerResponse>(`/api/explorer/${currentPath}`),
{
refetchOnWindowFocus: false,
refetchOnMount: false,
retry: false,
keepPreviousData: true,
},
);
const { data, isFetching } = trpc.explorer.useQuery(currentPath);
// const { data, isFetching } = useQuery(
// [currentPath],
// () => fetchJSON<ExplorerResponse>(`/api/explorer/${currentPath}`),
// {
// refetchOnWindowFocus: false,
// refetchOnMount: false,
// retry: false,
// keepPreviousData: true,
// },
// );

const onClickProject = useCallback((): void => {
onClose();
Expand Down
1 change: 0 additions & 1 deletion client/components/Header/use-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useHistory } from 'react-router-dom';
import { useProjectsStore } from '../../app/ContextStore';
import { useProjectPath } from '../../hooks/use-project-path';

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/explicit-module-boundary-types
export const useHeader = () => {
const projectPathEncoded = useProjectPath();

Expand Down
63 changes: 29 additions & 34 deletions client/components/Info.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,44 @@
import type { VFC } from 'react';
import { useEffect, useState } from 'react';
import styled from 'styled-components';
import type { FC } from 'react';
import { useEffect } from 'react';

const InfoWrapper = styled.div`
min-height: 45px;
max-height: 45px;
background: #3e3f3a;
padding: 5px 15px;
`;
import { trpc } from '../trpc';
// import styled from 'styled-components';

export const Info: VFC = () => {
const [content, setContent] = useState('');
// const InfoWrapper = styled.div`
// min-height: 45px;
// max-height: 45px;
// background: #3e3f3a;
// padding: 5px 15px;
// `;

const load = async (): Promise<void> => {
const response = await fetch(
`/api/info/${window.localStorage.getItem('npm-gui-id')}`,
);
setContent(await response.text());
// Tricky one
setTimeout(() => {
export const Info: FC = () => {
const { data: content } = trpc.info.useQuery(
window.localStorage.getItem('npm-gui-id') || 'unknown',
{
enabled: window.localStorage.getItem('npm-gui-id') !== 'developer',
},
);

useEffect(() => {
if (content) {
const script = document.createElement('script');
script.src = 'https://buttons.github.io/buttons.js';
document.head.append(script);
});
};

useEffect(() => {
if (window.localStorage.getItem('npm-gui-id') !== 'developer') {
load();
}
}, []);
}, [content]);

if (!content) {
return null;
}

return (
<InfoWrapper>
<div
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
// eslint-disable-next-line @typescript-eslint/naming-convention
__html: content,
}}
/>
</InfoWrapper>
<div
className="min-h-[45px] max-h-[45px] bg-neutral-700"
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
// eslint-disable-next-line @typescript-eslint/naming-convention
__html: content,
}}
/>
);
};
Loading
Loading