Skip to content

Commit

Permalink
chore: refactored clear and command logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-i committed Jan 1, 2024
1 parent 3b94240 commit e84c3a9
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 203 deletions.
8 changes: 6 additions & 2 deletions src/components/Cli/Cli.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ import { ReactNode } from 'react';

export const runPrompt = (
args: string[],
): { result: ReactNode; isStandalone: boolean } => {
): {
result: ReactNode;
isStandalone: boolean;
} => {
let isScript = false;
// convert paths to file names since there only is the root directory
const strippedArgs = args.map((arg, i) => {
if (!arg.includes(`/`)) return arg;
// is a file or path
Expand Down Expand Up @@ -106,7 +110,7 @@ export const runPrompt = (
};

export function getSuggestions(args: string[]): string[] {
let lastArg = args.at(-1) ?? ``;
let lastArg = args[args.length - 1];
let lastArgPrefix = ``;

if (lastArg === ``) return [];
Expand Down
20 changes: 14 additions & 6 deletions src/components/Cli/cmd/clear/clear.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { CliCmd, UsageTuple } from '@/components/Cli/cmd/types/CliCmd';
import { ClearEvent } from '@/util/types';
import { ReactNode } from 'react';
import {
PromptHistoryAction,
PromptHistoryContext,
} from '@/context/PromptHistoryContext';
import { ReactNode, useContext, useEffect } from 'react';

const RunClear = (): ReactNode => {
const { dispatch } = useContext(PromptHistoryContext);
useEffect(() => {
dispatch({ type: PromptHistoryAction.CLEAR });
}, [dispatch]);
return null;
};

export class Clear extends CliCmd {
get fileName(): string {
Expand All @@ -14,8 +25,5 @@ export class Clear extends CliCmd {
};
}

public run(): ReactNode {
window.dispatchEvent(ClearEvent);
return null;
}
public run = (): ReactNode => <RunClear />;
}
11 changes: 7 additions & 4 deletions src/components/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ export const Link = ({ href, children }: Readonly<LinkProps>) => {
fill-log-500
group-hover:fill-log-400`;

const hrefUrl = new URL(href || ``);
const fileExtLength = hrefUrl.pathname.split(`.`).pop()?.length;
if (!href) {
return <span>{children}</span>;
}

const fileExtLength = href.split(`.`).pop()?.length;
const isFile = fileExtLength && fileExtLength >= 3 && fileExtLength <= 4;

return (
<a
href={href}
target={!isFile ? `_blank` : undefined}
rel={!isFile ? `noreferrer` : undefined}
target={`_blank`}
rel={`noreferrer`}
className={`
inline-flex
group
Expand Down
Loading

0 comments on commit e84c3a9

Please sign in to comment.