Sort the files after fetching
This commit is contained in:
@@ -58,6 +58,22 @@ export const fetchFiles = (gistId: string) => {
|
|||||||
language: res.data.files?.[filename]?.language?.toLowerCase() || "",
|
language: res.data.files?.[filename]?.language?.toLowerCase() || "",
|
||||||
content: res.data.files?.[filename]?.content || "",
|
content: res.data.files?.[filename]?.content || "",
|
||||||
}));
|
}));
|
||||||
|
// Sort files so that the source files are first
|
||||||
|
// In case of other files leave the order as it its
|
||||||
|
files.sort((a, b) => {
|
||||||
|
const aExtension = a.name.split('.')?.[1];
|
||||||
|
const bExtension = b.name.split('.')?.[1];
|
||||||
|
if (!aExtension || !bExtension) {
|
||||||
|
return 0
|
||||||
|
};
|
||||||
|
if (aExtension === 'c' && bExtension === 'c') {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if (aExtension === 'c' && bExtension !== 'c') {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
})
|
||||||
state.loading = false;
|
state.loading = false;
|
||||||
if (files.length > 0) {
|
if (files.length > 0) {
|
||||||
state.logs.push({
|
state.logs.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user