Skip to content

Commit

Permalink
Fixes radar issues (tgstation#80453)
Browse files Browse the repository at this point in the history
## About The Pull Request
Went through tgui:sonar to search for bugs. Some of these are valid -
they've been addressed. Others, not so. Telling me I need to make icon
names and css classes into constants is a nit at best. Radar seems to be
bugged in certain areas: Classnames ok to dupe, but not ones with
conditionals. Most of the function duplication errors rely on hooks.

I think this should close tgstation#79815 and we should remove radar shortly
after. See my comment
[here](tgstation#79815 (comment))
## Why It's Good For The Game
Fixes tgstation#79815
## Changelog
N/A none of this was player facing
  • Loading branch information
jlsnow301 authored Dec 22, 2023
1 parent bd424b3 commit 1f25479
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 174 deletions.
2 changes: 1 addition & 1 deletion tgui/packages/common/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const applyMiddleware = (
return (reducer, ...args): Store => {
const store = createStoreFunction(reducer, ...args);

let dispatch: Dispatch = () => {
let dispatch: Dispatch = (action, ...args) => {
throw new Error(
'Dispatching while constructing your middleware is not allowed.',
);
Expand Down
64 changes: 31 additions & 33 deletions tgui/packages/tgui-dev-server/link/client.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ const ensureConnection = () => {
};
}
}
};

if (process.env.NODE_ENV !== 'production') {
window.onunload = () => socket && socket.close();
}
};

const subscribe = (fn) => subscribers.push(fn);

Expand Down Expand Up @@ -136,38 +134,38 @@ const sendLogEntry = (level, ns, ...args) => {

const setupHotReloading = () => {
if (
// prettier-ignore
process.env.NODE_ENV !== 'production'
&& process.env.WEBPACK_HMR_ENABLED
&& window.WebSocket
process.env.NODE_ENV === 'production' ||
!process.env.WEBPACK_HMR_ENABLED ||
!window.WebSocket
) {
if (module.hot) {
ensureConnection();
sendLogEntry(0, null, 'setting up hot reloading');
subscribe((msg) => {
const { type } = msg;
sendLogEntry(0, null, 'received', type);
if (type === 'hotUpdate') {
const status = module.hot.status();
if (status !== 'idle') {
sendLogEntry(0, null, 'hot reload status:', status);
return;
}
module.hot
.check({
ignoreUnaccepted: true,
ignoreDeclined: true,
ignoreErrored: true,
})
.then((modules) => {
sendLogEntry(0, null, 'outdated modules', modules);
})
.catch((err) => {
sendLogEntry(0, null, 'reload error', err);
});
return;
}
if (module.hot) {
ensureConnection();
sendLogEntry(0, null, 'setting up hot reloading');
subscribe((msg) => {
const { type } = msg;
sendLogEntry(0, null, 'received', type);
if (type === 'hotUpdate') {
const status = module.hot.status();
if (status !== 'idle') {
sendLogEntry(0, null, 'hot reload status:', status);
return;
}
});
}
module.hot
.check({
ignoreUnaccepted: true,
ignoreDeclined: true,
ignoreErrored: true,
})
.then((modules) => {
sendLogEntry(0, null, 'outdated modules', modules);
})
.catch((err) => {
sendLogEntry(0, null, 'reload error', err);
});
}
});
}
};

Expand Down
4 changes: 2 additions & 2 deletions tgui/packages/tgui-dev-server/winreg.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const regQuery = async (path, key) => {
logger.error('could not find the start of the key value');
return null;
}
const value = stdout.substring(indexOfValue + 4, indexOfEol);
return value;

return stdout.substring(indexOfValue + 4, indexOfEol);
} catch (err) {
logger.error(err);
return null;
Expand Down
1 change: 0 additions & 1 deletion tgui/packages/tgui/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export const Button = (props: Props) => {
// Refocus layout on pressing escape.
if (event.key === KEY.Escape) {
event.preventDefault();
return;
}
}}
{...computeBoxProps(rest)}
Expand Down
2 changes: 0 additions & 2 deletions tgui/packages/tgui/components/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ export const Input = (props: Props) => {

event.currentTarget.value = toInputValue(value);
event.currentTarget.blur();

return;
}
};

Expand Down
1 change: 0 additions & 1 deletion tgui/packages/tgui/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ window.addEventListener('focusin', (e) => {
setWindowFocus(true);
if (canStealFocus(e.target as HTMLElement)) {
stealFocus(e.target as HTMLElement);
return;
}
});

Expand Down
2 changes: 1 addition & 1 deletion tgui/packages/tgui/interfaces/BasketballPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const BasketballPanel = (props) => {
/>
<Button
icon="basketball"
disabled={!(data.total_votes >= data.players_min)}
disabled={data.total_votes < data.players_min}
onClick={() => act('basketball_start')}
>
Start
Expand Down
3 changes: 1 addition & 2 deletions tgui/packages/tgui/interfaces/CellularEmporium.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export const CellularEmporium = (props) => {
buttons={
<Stack>
<Stack.Item fontSize="16px">
{genetic_points_count && genetic_points_count}{' '}
<Icon name="dna" color="#DD66DD" />
{genetic_points_count} <Icon name="dna" color="#DD66DD" />
</Stack.Item>
<Stack.Item>
<Button
Expand Down
18 changes: 8 additions & 10 deletions tgui/packages/tgui/interfaces/CommandReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,27 @@ const CentComName = (props) => {
const { act, data } = useBackend<Data>();
const { command_name, command_name_presets = [], custom_name } = data;

const sendName = (value) => {
act('update_command_name', {
updated_name: value,
});
};

return (
<Section title="Set Central Command name" textAlign="center">
<Dropdown
width="100%"
selected={command_name}
options={command_name_presets}
onSelected={(value) =>
act('update_command_name', {
updated_name: value,
})
}
onSelected={(value) => sendName(value)}
/>
{!!custom_name && (
<Input
width="100%"
mt={1}
value={command_name}
placeholder={command_name}
onChange={(_, value) =>
act('update_command_name', {
updated_name: value,
})
}
onChange={(_, value) => sendName(value)}
/>
)}
</Section>
Expand Down
20 changes: 6 additions & 14 deletions tgui/packages/tgui/interfaces/Fabrication/DesignBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ export const DesignBrowser = <T extends Design = Design>(
}
}

const designWrapper = (design: T) => {
buildRecipeElement(design, availableMaterials || {}, onPrintDesign || NOOP);
};

return (
<Stack fill>
{/* Left Column */}
Expand Down Expand Up @@ -279,24 +283,12 @@ export const DesignBrowser = <T extends Design = Design>(
.toLowerCase()
.includes(searchText.toLowerCase()),
)
.map((design) =>
buildRecipeElement(
design,
availableMaterials || {},
onPrintDesign || NOOP,
),
)
.map((design) => designWrapper(design))
) : selectedCategory === ALL_CATEGORY ? (
<>
{sortBy((design: T) => design.name)(
Object.values(root.descendants),
).map((design) =>
buildRecipeElement(
design,
availableMaterials || {},
onPrintDesign || NOOP,
),
)}
).map((design) => designWrapper(design))}
</>
) : (
root.subcategories[selectedCategory] && (
Expand Down
12 changes: 4 additions & 8 deletions tgui/packages/tgui/interfaces/NumberInputModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@ export const NumberInputModal = (props) => {
const { act, data } = useBackend<NumberInputData>();
const { init_value, large_buttons, message = '', timeout, title } = data;
const [input, setInput] = useState(init_value);
const onChange = (value: number) => {
if (value === input) {
return;
}
setInput(value);
};
const onClick = (value: number) => {

const setValue = (value: number) => {
if (value === input) {
return;
}
setInput(value);
};

// Dynamically changes the window height based on the message.
const windowHeight =
140 +
Expand All @@ -59,7 +55,7 @@ export const NumberInputModal = (props) => {
<Box color="label">{message}</Box>
</Stack.Item>
<Stack.Item>
<InputArea input={input} onClick={onClick} onChange={onChange} />
<InputArea input={input} onClick={setValue} onChange={setValue} />
</Stack.Item>
<Stack.Item>
<InputButtons input={input} />
Expand Down
13 changes: 3 additions & 10 deletions tgui/packages/tgui/interfaces/Orbit/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ export const getAntagCategories = (antagonists: Antagonist[]) => {
categories[antag_group].push(player);
});

const sortedAntagonists = sortBy<AntagGroup>(([key]) => key)(
Object.entries(categories),
);

return sortedAntagonists;
return sortBy<AntagGroup>(([key]) => key)(Object.entries(categories));
};

/** Returns a disguised name in case the person is wearing someone else's ID */
Expand All @@ -46,9 +42,8 @@ export const getDisplayName = (full_name: string, name?: string) => {
export const getMostRelevant = (
searchQuery: string,
observables: Observable[][],
) => {
/** Returns the most orbited observable that matches the search. */
const mostRelevant: Observable = flow([
): Observable => {
return flow([
// Filters out anything that doesn't match search
filter<Observable>((observable) =>
isJobOrNameMatch(observable, searchQuery),
Expand All @@ -57,8 +52,6 @@ export const getMostRelevant = (
sortBy<Observable>((observable) => -(observable.orbiters || 0)),
// Makes a single Observables list for an easy search
])(observables.flat())[0];

return mostRelevant;
};

/** Returns the display color for certain health percentages */
Expand Down
Loading

0 comments on commit 1f25479

Please sign in to comment.