mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-04 15:04:00 +01:00 
			
		
		
		
	fix
This commit is contained in:
		
							parent
							
								
									754535318c
								
							
						
					
					
						commit
						c3ecaed954
					
				@ -1,5 +1,6 @@
 | 
			
		||||
{{$isTreePathRoot := not .TreeNames}}
 | 
			
		||||
 | 
			
		||||
<div class="repo-view-content-data tw-hidden" data-document-title="{{ctx.RootData.Title}}"></div>
 | 
			
		||||
{{template "repo/sub_menu" .}}
 | 
			
		||||
<div class="repo-button-row">
 | 
			
		||||
	<div class="repo-button-row-left">
 | 
			
		||||
 | 
			
		||||
@ -10,7 +10,6 @@
 | 
			
		||||
{{/* TODO: Dynamically move components such as refSelector and createPR here */}}
 | 
			
		||||
<div id="view-file-tree" class="tw-overflow-auto tw-h-full is-loading"
 | 
			
		||||
	data-repo-link="{{.RepoLink}}"
 | 
			
		||||
	data-repo-name="{{.Repository.Name}}"
 | 
			
		||||
	data-tree-path="{{$.TreePath}}"
 | 
			
		||||
	data-current-ref-name-sub-url="{{.RefTypeNameSubURL}}"
 | 
			
		||||
></div>
 | 
			
		||||
 | 
			
		||||
@ -7,7 +7,6 @@ const elRoot = useTemplateRef('elRoot');
 | 
			
		||||
 | 
			
		||||
const props = defineProps({
 | 
			
		||||
  repoLink: {type: String, required: true},
 | 
			
		||||
  repoName: {type: String, required: true},
 | 
			
		||||
  treePath: {type: String, required: true},
 | 
			
		||||
  currentRefNameSubURL: {type: String, required: true},
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,7 @@ import {pathEscapeSegments} from '../utils/url.ts';
 | 
			
		||||
import {createElementFromHTML} from '../utils/dom.ts';
 | 
			
		||||
import {html} from '../utils/html.ts';
 | 
			
		||||
 | 
			
		||||
export function createViewFileTreeStore(props: {repoLink: string, repoName: string, treePath: string, currentRefNameSubURL: string}) {
 | 
			
		||||
export function createViewFileTreeStore(props: {repoLink: string, treePath: string, currentRefNameSubURL: string}) {
 | 
			
		||||
  const store = reactive({
 | 
			
		||||
    rootFiles: [],
 | 
			
		||||
    selectedItem: props.treePath,
 | 
			
		||||
@ -25,30 +25,24 @@ export function createViewFileTreeStore(props: {repoLink: string, repoName: stri
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    async loadViewContent(url: string) {
 | 
			
		||||
      url = url.includes('?') ? url.replace('?', '?only_content=true') : `${url}?only_content=true`;
 | 
			
		||||
      const response = await GET(url);
 | 
			
		||||
      document.querySelector('.repo-view-content').innerHTML = await response.text();
 | 
			
		||||
      const u = new URL(url, window.origin);
 | 
			
		||||
      u.searchParams.set('only_content', '1');
 | 
			
		||||
      const response = await GET(u.href);
 | 
			
		||||
      const elViewContent = document.querySelector('.repo-view-content');
 | 
			
		||||
      elViewContent.innerHTML = await response.text();
 | 
			
		||||
      document.title = elViewContent.querySelector('.repo-view-content-data').getAttribute('data-document-title');
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    async navigateTreeView(treePath: string) {
 | 
			
		||||
      const url = store.buildTreePathWebUrl(treePath);
 | 
			
		||||
      const title = store.buildTitle(store.selectedItem, treePath);
 | 
			
		||||
      window.history.pushState({treePath, url}, null, url);
 | 
			
		||||
      store.selectedItem = treePath;
 | 
			
		||||
      await store.loadViewContent(url);
 | 
			
		||||
      document.title = title;
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    buildTreePathWebUrl(treePath: string) {
 | 
			
		||||
      return `${props.repoLink}/src/${props.currentRefNameSubURL}/${pathEscapeSegments(treePath)}`;
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    buildTitle(oldTreePath: string, treePath: string) {
 | 
			
		||||
      // the title always starts with "<repoName>/<treePath>"
 | 
			
		||||
      const oldPrefixLength = props.repoName.length + 1 + oldTreePath.length;
 | 
			
		||||
      const titleSuffix = document.title.substring(oldPrefixLength);
 | 
			
		||||
      return `${props.repoName}/${treePath}${titleSuffix}`;
 | 
			
		||||
    },
 | 
			
		||||
  });
 | 
			
		||||
  return store;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -31,7 +31,6 @@ export async function initRepoViewFileTree() {
 | 
			
		||||
  const fileTree = sidebar.querySelector('#view-file-tree');
 | 
			
		||||
  createApp(ViewFileTree, {
 | 
			
		||||
    repoLink: fileTree.getAttribute('data-repo-link'),
 | 
			
		||||
    repoName: fileTree.getAttribute('data-repo-name'),
 | 
			
		||||
    treePath: fileTree.getAttribute('data-tree-path'),
 | 
			
		||||
    currentRefNameSubURL: fileTree.getAttribute('data-current-ref-name-sub-url'),
 | 
			
		||||
  }).mount(fileTree);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user