mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(flags): move reply flag below link and auto-geo on /bant/
Hide the flag selector on /bant/ while still publishing geographic location, and place the reply modal flag field after the link field.
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { getCommentFlagOptionsForDirectory, getCommentFlagPublishOptionsFromSelection, getCommentFlagRequestFromSelection } from '../comment-flag-selection';
|
||||
import {
|
||||
getCommentFlagOptionsForDirectory,
|
||||
getCommentFlagPublishOptionsForDirectory,
|
||||
getCommentFlagPublishOptionsFromSelection,
|
||||
getCommentFlagRequestFromSelection,
|
||||
} from '../comment-flag-selection';
|
||||
|
||||
describe('comment-flag-selection', () => {
|
||||
it('does not expose options for boards without flags', () => {
|
||||
@@ -16,6 +21,29 @@ describe('comment-flag-selection', () => {
|
||||
).toEqual([{ label: 'Geographic Location', value: 'country:auto' }]);
|
||||
});
|
||||
|
||||
it('does not expose a flag selector on /bant/ but still publishes geographic location', () => {
|
||||
expect(
|
||||
getCommentFlagOptionsForDirectory({
|
||||
directoryCode: 'bant',
|
||||
features: { hasFlags: true },
|
||||
title: '/bant/ - International/Random',
|
||||
}),
|
||||
).toEqual([]);
|
||||
|
||||
expect(
|
||||
getCommentFlagPublishOptionsForDirectory({
|
||||
directoryCode: 'bant',
|
||||
features: { hasFlags: true },
|
||||
title: '/bant/ - International/Random',
|
||||
}),
|
||||
).toEqual({
|
||||
challengeRequest: {
|
||||
challengeAnswers: ['bitsocial-flags:5chan:flag:country:auto'],
|
||||
},
|
||||
flairs: [{ type: 'country', code: 'auto', text: 'flag:country:auto' }],
|
||||
});
|
||||
});
|
||||
|
||||
it('matches the 4chan /pol/ flag order', () => {
|
||||
const options = getCommentFlagOptionsForDirectory({
|
||||
directoryCode: 'pol',
|
||||
|
||||
@@ -35,6 +35,9 @@ const NO_FLAG_OPTION: CommentFlagSelectOption = {
|
||||
label: 'None',
|
||||
};
|
||||
|
||||
/** Boards that always publish geographic location without showing a flag selector. */
|
||||
const AUTO_GEOGRAPHIC_FLAG_DIRECTORY_CODES = new Set(['bant']);
|
||||
|
||||
const getDirectoryCode = (directory: Pick<DirectoryCommunity, 'directoryCode' | 'title'> | undefined): string | undefined => {
|
||||
const directoryCode = directory?.directoryCode?.trim().toLowerCase();
|
||||
return directoryCode || directory?.title?.match(/^\/([^/]+)\//)?.[1]?.toLowerCase();
|
||||
@@ -52,6 +55,10 @@ export const getCommentFlagOptionsForDirectory = (directory: Pick<DirectoryCommu
|
||||
}
|
||||
|
||||
const directoryCode = getDirectoryCode(directory);
|
||||
if (directoryCode && AUTO_GEOGRAPHIC_FLAG_DIRECTORY_CODES.has(directoryCode)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (directoryCode === 'mlp') {
|
||||
return [NO_FLAG_OPTION, ...getBoardFlagOptions('pony')];
|
||||
}
|
||||
@@ -63,6 +70,33 @@ export const getCommentFlagOptionsForDirectory = (directory: Pick<DirectoryCommu
|
||||
return [GEOGRAPHIC_LOCATION_OPTION];
|
||||
};
|
||||
|
||||
export const getCommentFlagPublishOptionsForDirectory = (
|
||||
directory: Pick<DirectoryCommunity, 'directoryCode' | 'features' | 'title'> | undefined,
|
||||
selectedValue?: string,
|
||||
): CommentFlagPublishOptions => {
|
||||
if (directory?.features?.hasFlags !== true) {
|
||||
return {
|
||||
challengeRequest: undefined,
|
||||
flairs: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
const directoryCode = getDirectoryCode(directory);
|
||||
if (directoryCode && AUTO_GEOGRAPHIC_FLAG_DIRECTORY_CODES.has(directoryCode)) {
|
||||
return getCommentFlagPublishOptionsFromSelection(GEOGRAPHIC_LOCATION_FLAG_VALUE);
|
||||
}
|
||||
|
||||
const flagOptions = getCommentFlagOptionsForDirectory(directory);
|
||||
if (flagOptions.length === 0) {
|
||||
return {
|
||||
challengeRequest: undefined,
|
||||
flairs: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
return getCommentFlagPublishOptionsFromSelection(selectedValue ?? flagOptions[0]?.value);
|
||||
};
|
||||
|
||||
export const getCommentFlagRequestFromSelection = (value: string | undefined): CommentFlagRequest | undefined => {
|
||||
if (!value || value === NO_FLAG_VALUE) {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user